public static int SaveToolStdout(BinaryInfo info, string extra_args, MBFile stdout, IBuildContext ctxt, bool fatal, string message) { string stderr; int code = SaveToolStdout(info, extra_args, stdout, out stderr, ctxt); if (code != 0) { string detail = info.ToUnixStyle(ctxt) + " " + extra_args + ":\n" + stderr; if (fatal) { ctxt.Logger.Error(3003, message, detail); } else { ctxt.Logger.Warning(3004, message, detail); } } else if (stderr.Length > 0) { // FIXME: is this a good idea? string detail = info.ToUnixStyle(ctxt) + " " + extra_args + ":\n" + stderr; ctxt.Logger.Warning(3010, "Tool warning:", detail); } return(code); }
public void AddDictionary(MBDictionary substs, IBuildContext ctxt) { foreach (string key in substs.Keys) { Result r = substs[key]; if (r is MBString) { AddSubst(key, ((MBString)r).Value); } else if (r is MBFile) { MBFile f = (MBFile)r; if (f.Dir.Storage != ResultStorageKind.System) { ctxt.Logger.Warning(2044, "Substituting a relative filename into a text file -- " + "this will cause problems when building from a different directory. " + "Be very sure that you know what you're doing.", key); } else { AddSubst(key, f.GetPath(ctxt)); } } else { AddSubst(key, r.ToString()); } } }
public static int Start(BinaryInfo info, string extra_args, MBFile stdin, MBFile stdout, MBFile stderr, IBuildContext ctxt) { StreamReader stdin_stream = null; StreamWriter stdout_stream = null; StreamWriter stderr_stream = null; if (stdin != null) { stdin_stream = new StreamReader(stdin.OpenRead(ctxt)); ctxt.Logger.Log("launcher.stdin_from", stdin.GetPath(ctxt)); } if (stdout != null) { stdout_stream = new StreamWriter(stdout.OpenWrite(ctxt)); ctxt.Logger.Log("launcher.stdout_to", stdout.GetPath(ctxt)); } if (stderr != null) { stderr_stream = new StreamWriter(stderr.OpenWrite(ctxt)); ctxt.Logger.Log("launcher.stderr_to", stderr.GetPath(ctxt)); } return(Start(info, extra_args, stdin_stream, stdout_stream, stderr_stream, ctxt)); }
public static int Start(BinaryInfo info, string extra_args, MBFile stdin, MBFile stdout, out string stderr, IBuildContext ctxt) { MemoryStream ms = new MemoryStream(32); StreamReader stdin_stream = null; StreamWriter stdout_stream = null; StreamWriter stderr_stream = null; int exit_code; if (stdin != null) { stdin_stream = new StreamReader(stdin.OpenRead(ctxt)); ctxt.Logger.Log("launcher.stdin_from", stdin.GetPath(ctxt)); } if (stdout != null) { stdout_stream = new StreamWriter(stdout.OpenWrite(ctxt)); ctxt.Logger.Log("launcher.stdout_to", stdout.GetPath(ctxt)); } stderr_stream = new StreamWriter(ms); exit_code = Start(info, extra_args, stdin_stream, stdout_stream, stderr_stream, ctxt); byte[] buf = ms.ToArray(); stderr = System.Text.Encoding.Default.GetString(buf).Trim(); return(exit_code); }
public IOSink(MBFile file, IBuildContext ctxt) { if (file == null) { throw new ArgumentNullException(); } writer = new StreamWriter(file.OpenWrite(ctxt)); }
public override Result Build(IBuildContext ctxt) { string outname = GetOutputName(ctxt); if (outname == null) { return(null); } string resname = GetResourceName(ctxt); // Output MBFile file = (MBFile)CreateResultObject(); file.Dir = ctxt.WorkingDirectory; file.Name = outname; StreamWriter writer = new StreamWriter(file.OpenWrite(ctxt)); // Input stream Assembly caller = Assembly.GetAssembly(GetType()); Stream rstream = caller.GetManifestResourceStream(resname); if (rstream == null) { ctxt.Logger.Error(9999, "No such resource stream " + resname + " in assembly " + caller.FullName, null); return(null); } StreamReader reader = new StreamReader(rstream); // Do it try { char[] buf = new char[512]; int read; do { read = reader.Read(buf, 0, buf.Length); writer.Write(buf, 0, read); } while (read > 0); } catch (Exception e) { ctxt.Logger.Error(9999, "Exception while writing to file from resource stream" + resname, e.Message); return(null); } finally { reader.Close(); writer.Close(); } return(file); }
public FileBinaryInfo(MBFile program, string args) : base() { if (program != null) { Program = program; } if (args != null) { ForcedArgs = args; } }
protected bool MoveToFinal(MBFile output, MBFile tempdest, IBuildContext ctxt) { // We should probably move away the file before clobbering it ... if (output.Exists(ctxt)) { output.Delete(ctxt); } tempdest.MoveTo(output, ctxt); return(false); }
public virtual string DescribeAction(Result other, IBuildContext ctxt) { MBFile dest = MakeDestination((MBFile)other, ctxt); if (dest == null) { return("[error determining destination]"); } return(String.Format("Copy {0} to {1}", ((MBFile)other).GetPath(ctxt), dest.GetPath(ctxt))); }
public FileBinaryInfo(ArchKind arch, MBFile program, string args) : base() { Architecture = arch; if (program != null) { Program = program; } if (args != null) { ForcedArgs = args; } }
public override Result Build(IBuildContext ctxt) { string name = GetOutputName(ctxt); if (name == null) { return(null); } MBFile result = (MBFile)CreateResultObject(); result.Dir = ctxt.SourceDirectory; result.Name = name; return(result); }
protected MBFile MakeDestination(MBFile src, IBuildContext ctxt) { string ddir = MutateDestDir(DestDir, src, ctxt); if (ddir == null) { string t = String.Format("No destination directory for the installation of {0}", src); ctxt.Logger.Error(2013, t, String.Format("Base dest directory \"{0}\"", DestDir)); return(null); } MBDirectory dir = new MBDirectory(ResultStorageKind.System, ddir); return(new MBFile(dir, GetDestName(src, dir, ctxt))); }
public static int SaveToolStdout(BinaryInfo info, string extra_args, MBFile stdout, out string stderr, IBuildContext ctxt) { Stream sout = stdout.OpenWrite(ctxt); StreamWriter wout = new StreamWriter(sout); MemoryStream mserr = new MemoryStream(32); StreamWriter err = new StreamWriter(mserr); int result = Start(info, extra_args, null, wout, err, ctxt); byte[] buf = mserr.ToArray(); stderr = System.Text.Encoding.Default.GetString(buf).Trim(); ctxt.Logger.Log("launcher.stdout_to", stdout.GetPath(ctxt)); ctxt.Logger.Log("launcher.stderr", stderr); return(result); }
protected override bool PostCopy(MBFile src, MBFile dest, bool backwards, IBuildContext ctxt) { if (backwards) { return(false); } try { dest.MakeExecutable(ctxt); } catch (Exception e) { ctxt.Logger.Error(1004, "Unhandled exception while attempting to make file executable", e.ToString()); return(true); } return(false); }
protected bool GetOutputAndTemp(IBuildContext ctxt, MBFile output, out MBFile tempdest) { string name = GetOutputName(ctxt); if (name == null) { output = null; tempdest = null; return(true); } output.Dir = ctxt.WorkingDirectory; output.Name = name; tempdest = (MBFile)output.Clone(); // TODO: add in some random characters if you're really anal tempdest.Name += ".tmp"; return(false); }
public static void DrainStream(MBFile file, IBuildContext ctxt, IMiniStreamSink sink) { DrainStream(file.OpenRead(ctxt), sink); }
protected bool CopyFile(MBFile src, bool backwards, IBuildContext ctxt) { MBFile dest = MakeDestination(src, ctxt); if (dest == null) { return(true); } if (PreCopy(src, dest, backwards, ctxt)) { // Error will be reported return(true); } try { if (backwards) { // FIXME: delete containing dirs if empty? probably a bad idea. dest.Delete(ctxt); } else { dest.Dir.CreateTo(ctxt); src.CopyTo(dest, ctxt); } } catch (IOException ioex) { string t1; if (backwards) { t1 = String.Format("There was an error deleting {0}.", dest.GetPath(ctxt)); } else { t1 = String.Format("There was an error copying {0} to {1}.", src.GetPath(ctxt), dest.GetPath(ctxt)); } // Different error # for the delete exception? ctxt.Logger.Error(3023, t1, ioex.Message); return(true); } catch (UnauthorizedAccessException uaex) { string t1; if (backwards) { t1 = String.Format("You do not have permission to delete {0}.", dest.GetPath(ctxt)); } else { t1 = String.Format("You do not have permission to copy {0} to {1}.", src.GetPath(ctxt), dest.GetPath(ctxt)); } ctxt.Logger.Error(3023, t1, uaex.Message); return(true); } if (PostCopy(src, dest, backwards, ctxt)) { // Error will be reported but we need to clean up if (!backwards) { try { dest.Delete(ctxt); } catch (IOException ioex) { string t1 = String.Format("There was an error removing {0}.", dest.GetPath(ctxt)); ctxt.Logger.Error(3022, t1, ioex.ToString()); } } return(true); } return(false); }
protected virtual bool PostCopy(MBFile src, MBFile dest, bool backwards, IBuildContext ctxt) { // return true on error return(false); }
protected virtual string GetDestName(MBFile file, MBDirectory dest, IBuildContext ctxt) { // return the basename of the destination file, derived from the arguments // in whatever manner is fit. return(file.Name); }
public static int SaveToolStdout(BinaryInfo info, string extra_args, MBFile stdout, IBuildContext ctxt, string message) { return(SaveToolStdout(info, extra_args, stdout, ctxt, true, message)); }
// Implementation protected virtual string MutateDestDir(string destdir, MBFile other, IBuildContext ctxt) { return(destdir); }
public FileBinaryInfo(MBFile program) : this(program, null) { }