public void LinkFromOrCopyTo(MBFile f, IBuildContext ctxt) { // FIXME: like MakeExecutable, probably a hack. string path = GetPath(ctxt); if (!RuntimeEnvironment.MonoUnixSupported) { // emulate with copying CopyTo(f, ctxt); return; } // Try and emulate the copy semantics by obliterating // f if it already exists. string other = f.GetPath(ctxt); try { File.Delete(other); } catch (IOException) { } // FIXME: does this create absolute paths always? // that would be highly lame. UnixFileInfo ufi = new UnixFileInfo(path); ctxt.Logger.Log("io.file_link", other + " -> " + path); ufi.CreateSymbolicLink(other); }
public FileBinaryInfo (ArchKind arch, MBFile program, string args) : base () { Architecture = arch; if (program != null) Program = program; if (args != null) ForcedArgs = args; }
// Clone protected override void CloneTo(Result dest) { MBFile dfile = (MBFile)dest; dfile.dir = (MBDirectory)dir.Clone(); dfile.name = (string)name.Clone(); dfile.modtime = modtime; // cloning? }
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 void MoveTo(MBFile dest, IBuildContext ctxt) { // FIXME: exception handling string src = GetPath(ctxt); string dp = dest.GetPath(ctxt); ctxt.Logger.Log("io.file_move", src + " -> " + dp); File.Move(src, dp); this.Dir = dest.Dir; this.Name = dest.Name; }
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 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)); }
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; }
// Compare protected override bool ContentEquals(Result other) { MBFile f = (MBFile)other; return((dir == f.dir) && (name == f.name)); }
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; }
protected virtual bool PostCopy (MBFile src, MBFile dest, bool backwards, IBuildContext ctxt) { // return true on error return false; }
public IOSink (MBFile file, IBuildContext ctxt) { if (file == null) throw new ArgumentNullException (); writer = new StreamWriter (file.OpenWrite (ctxt)); }
// Implementation protected virtual string MutateDestDir (string destdir, MBFile other, IBuildContext ctxt) { return destdir; }
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 static int SaveToolStdout (BinaryInfo info, string extra_args, MBFile stdout, IBuildContext ctxt, string message) { return SaveToolStdout (info, extra_args, stdout, ctxt, true, message); }
public static void DrainStream (MBFile file, IBuildContext ctxt, IMiniStreamSink sink) { DrainStream (file.OpenRead (ctxt), sink); }
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; }
public void CopyTo (MBFile f, IBuildContext ctxt) { CopyToUnsafe (f.GetPath (ctxt), ctxt); }
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; }
public FileBinaryInfo (MBFile program) : this (program, null) {}
public FileBinaryInfo (MBFile program, string args) : base () { if (program != null) Program = program; if (args != null) ForcedArgs = args; }
public void CopyTo(MBFile f, IBuildContext ctxt) { CopyToUnsafe(f.GetPath(ctxt), ctxt); }
public void MoveTo (MBFile dest, IBuildContext ctxt) { // FIXME: exception handling string src = GetPath (ctxt); string dp = dest.GetPath (ctxt); ctxt.Logger.Log ("io.file_move", src + " -> " + dp); File.Move (src, dp); this.Dir = dest.Dir; this.Name = dest.Name; }
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 void LinkFromOrCopyTo (MBFile f, IBuildContext ctxt) { // FIXME: like MakeExecutable, probably a hack. string path = GetPath (ctxt); if (!RuntimeEnvironment.MonoUnixSupported) { // emulate with copying CopyTo (f, ctxt); return; } // Try and emulate the copy semantics by obliterating // f if it already exists. string other = f.GetPath (ctxt); try { File.Delete (other); } catch (IOException) { } // FIXME: does this create absolute paths always? // that would be highly lame. UnixFileInfo ufi = new UnixFileInfo (path); ctxt.Logger.Log ("io.file_link", other + " -> " + path); ufi.CreateSymbolicLink (other); }
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; }