internal void injectAnnotations(BuildObject dest, string commentToken) { string annotations = emit(commentToken); string destStr = File.ReadAllText(dest.getFilesystemPath()); File.Delete(dest.getFilesystemPath()); File.WriteAllText(dest.getFilesystemPath(), annotations + destStr); }
public string getKnownObjectHash(BuildObject obj) { string hash; bool present = knownObjectHash.TryGetValue(obj, out hash); if (!present) { NuObjValue value = nuObjectContents.getValue(obj); if (value != null) { if (value.disp is Failed) { return(null); } else if (obj is VirtualBuildObject) { hash = "virtual"; } else { hash = hasher.hash(obj.getFilesystemPath()); } knownObjectHash[obj] = hash; } } return(hash); }
//- Fetch an object from the cache and store it in the local //- nuobj tree. //- //- NB BuildObjectValuePointers get stored in untrusted places, so we never //- actually use their RelativePath values in filesystem calls. //- Instead, we require the caller to supply a local BuildObject where //- he expects the ptr to point, and we test for equality, and then //- use the obj value for filesystem operations. void fetchObject(BuildObjectValuePointer ptr, BuildObject obj) { //-Console.WriteLine("ResultCache.fetchObject " + obj); Util.Assert(obj.getRelativePath().Equals(ptr.relativePath)); File.Delete(obj.getFilesystemPath()); this.itemCache.FetchItemToFile(ItemCacheContainer.Objects, ptr.objectHash, obj.getFilesystemPath()); this.knownObjectHash[obj] = ptr.objectHash; }
public Disposition complete(ProcessInvokeAsyncWorker worker) { if (!(worker.pinv.disposition is Failed)) { File.WriteAllText(asmFileOut.getFilesystemPath(), worker.pinv.getStdout()); } return(worker.pinv.disposition); }
//- Read an output object from the nuobj tree and store it in the cache. public BuildObjectValuePointer storeObject(BuildObject obj) { string contentHash = hasher.hash(obj.getFilesystemPath()); this.itemCache.StoreItemFromFile(ItemCacheContainer.Objects, contentHash, obj.getFilesystemPath()); this.knownObjectHash[obj] = contentHash; return(new BuildObjectValuePointer(contentHash, obj.getRelativePath())); }
void writeBootFile() { List <string> lines = new List <string>(); lines.Add(mkBootFileEntry(loaderCopy)); lines.Add(mkBootFileEntry(appExecutableCopy)); File.WriteAllLines(bootIniFile.getFilesystemPath(), lines); }
void blessInternal(BuildObject obj, string hashIfKnown, Disposition disp, VirtualContents contents) { Util.Assert(!theCache.ContainsKey(obj)); //- I don't think we should ever write the same file twice in one run. string hash = hashIfKnown; if (hash == null && disp is Fresh && !(obj is VirtualBuildObject)) { hash = _hasher.hash(obj.getFilesystemPath()); } theCache[obj] = new NuObjValue(hash, disp, contents); }
public static void propagatePrivateImports( IContextGeneratingVerb contextVerb, BuildObject srcobj, BuildObject dstobj) { //- Rewrite basm output to propagate any import statements from the beat file. //- TODO this step really should be a beat function, not part of the build system. IEnumerable <BeatIncludes.LabeledInclude> beatImports = getBeatFlavoredShallowIncludesLabeled(contextVerb, srcobj); StringBuilder sb = new StringBuilder(); foreach (BeatIncludes.LabeledInclude li in beatImports) { sb.Append("//-"); sb.Append(li.importFilter == BeatIncludes.ImportFilter.ForBasmOnly ? "private-basmonly-import" : "private-import"); sb.Append(" "); sb.Append(li.buildObject.getFileNameWithoutExtension()); sb.AppendLine(";"); } string beatOutput = File.ReadAllText(dstobj.getFilesystemPath()); File.Delete(dstobj.getFilesystemPath()); File.WriteAllText(dstobj.getFilesystemPath(), sb.ToString() + beatOutput); }
public virtual Disposition complete(ProcessInvokeAsyncWorker worker) { if (!(worker.pinv.disposition is Failed)) { //- Check that the executable isn't too large long exeSize = new FileInfo(outputObject.getFilesystemPath()).Length; if (exeSize > maxExeSize) { return(new Failed("Executable too big")); } } return(worker.pinv.disposition); }
private static IEnumerable <string> extractImportStatements(BuildObject obj) { //- Well, it might be nice to use BeatExtensions.propagatePrivateImports, but that requires //- a context to interpret the input imports. We don't really want to cons up yet ANOTHER //- intermediate context, so here's a temporary workaround. Caution; may be brittle. IEnumerable <string> imports = File.ReadAllLines(obj.getFilesystemPath()) .Where(line => line.Contains("private-import")); //- Note that dafny_Main_i didn't really expect us to steal its //- imports, so it hasn't conditioned the Checked and Trusted imports to be beat-resistant. imports = imports.Select( line => line.Contains("Checked") || line.Contains("Trusted") ? line.Replace("private-import", "private-basmonly-import") : line); return(imports); }
public override IVerbWorker getWorker() { if (verificationRequest.isComplete()) { VerificationResult vr = VerificationResult.fromXmlFile(batchSummaryVerb.getOutputFile().getRelativePath()); if (!vr.pass) { Util.Assert(false); //- Should never get here, since Ironclad app should fail before producing a verified exe return(new VerbSyncWorker(new Failed())); } } //- Copy the AppLoader binary and the bootloader into the same directory as the app's binary, so the pxe-loader can find them File.Copy(loaderVerb.getExe().getFilesystemPath(), loaderCopy.getFilesystemPath(), true); File.Copy(appVerb.getExe().getFilesystemPath(), appExecutableCopy.getFilesystemPath(), true); File.Copy(bootloader.getFilesystemPath(), bootloaderCopy.getFilesystemPath(), true); writeBootFile(); return(new VerbSyncWorker(new Fresh())); }
public override IVerbWorker getWorker() { if (verificationRequest.isComplete()) { //- If the verification succeeded, then we convert the untrusted exe into a trusted exe (via a copy) VerificationResult vr = VerificationResult.fromXmlFile(verifyResultsVerb.getOutputFile().getFilesystemPath()); if (!vr.pass) { return(new VerbSyncWorker(new Failed())); } File.Copy(srcObject.getFilesystemPath(), outputObject.getFilesystemPath(), true); //- True => Overwrite } else { UnverifiedSentinelVirtualContents contents = new UnverifiedSentinelVirtualContents(); BuildEngine.theEngine.getNuObjContents().storeVirtual(outputObject, new Fresh(), contents); } return(new VerbSyncWorker(new Fresh())); }
public void store(BuildObject obj) { _fixed = true; string[] lines = _verificationObligations.Select(vo => vo.getRelativePath()).ToArray(); File.WriteAllLines(obj.getFilesystemPath(), lines); }
string mkBootFileEntry(BuildObject obj) { return(String.Format("Size={0} Path=/{1}", new FileInfo(obj.getFilesystemPath()).Length, obj.getFileName())); }
public ProcessInvoker( string executable, string[] args, RcHandling rcHandling, BuildObject failureBase, string finalStdoutPath = null, string dbgText = null, bool allowAbsoluteExe = false, bool allowAbsoluteArgs = false, string workingDir = null) { Util.Assert(allowAbsoluteExe || !executable.Contains(":")); //- Hey, this looks like an absolute path! Use .getRelativePath() to tolerate crossing machine boundaries. foreach (string arg in args) { //- Pardon my distasteful heuristic to avoid flagging /flag:value args. Util.Assert(allowAbsoluteArgs || arg.Length < 2 || arg[1] != ':'); //- Hey, this looks like an absolute path! Use .getRelativePath() to tolerate crossing machine boundaries. } this.rcHandling = rcHandling; stdout = new StringBuilder(); stderr = new StringBuilder(); using (Job job = new Job()) { using (Process proc = new Process()) { proc.StartInfo.FileName = Path.Combine(BuildEngine.theEngine.getIronRoot(), executable); //- TODO Is there a better way to escape the args to avoid problems with spaces? proc.StartInfo.Arguments = String.Join(" ", args); proc.StartInfo.WorkingDirectory = workingDir == null?BuildEngine.theEngine.getIronRoot() : workingDir; proc.StartInfo.RedirectStandardOutput = true; if (finalStdoutPath != null) { _tmpStdoutPath = finalStdoutPath + ".tmp"; stdoutFile = new StreamWriter(_tmpStdoutPath); proc.OutputDataReceived += new DataReceivedEventHandler(stdoutRedirectHandler); } else { //- collect stdout here for diagnostics. proc.OutputDataReceived += new DataReceivedEventHandler(stdoutHandler); } proc.StartInfo.RedirectStandardError = true; proc.ErrorDataReceived += new DataReceivedEventHandler(stderrHandler); proc.StartInfo.UseShellExecute = false; string commandLine = proc.StartInfo.FileName + " " + proc.StartInfo.Arguments; if (alwaysEmitDiagnostics) { //- In diagnostic mode, we emit the command line twice, once ahead in case Boogie decides //- to run away and never come back. BuildObject failureBatObj = failureBase.makeOutputObject(".bat"); failureBatObj.prepareObjDirectory(); File.WriteAllText(failureBatObj.getFilesystemPath(), commandLine); } proc.Start(); job.AddProcess(proc); proc.BeginOutputReadLine(); proc.BeginErrorReadLine(); proc.WaitForExit(); cpuTime = job.GetCpuTime().TotalSeconds; exitCode = proc.ExitCode; if (stdoutFile != null) { stdoutFile.Close(); } if (passed()) { disposition = new Fresh(); } else { //- sheesh. Some tools emit error messages to stdout. Failed f = new Failed(getStdoutString() + stderr.ToString()); f.AddError("Command line: " + commandLine + "\n"); disposition = f; } #pragma warning disable 429 //- alwaysEmitDiagnostics is a compile-time constant that can hide expression !passed() if (failureBase != null && (alwaysEmitDiagnostics || !passed())) #pragma warning restore 429 { failureBase.prepareObjDirectory(); File.WriteAllText(failureBase.makeOutputObject(".bat").getFilesystemPath(), commandLine); File.WriteAllText(failureBase.makeOutputObject(".txt").getFilesystemPath(), dbgText); File.WriteAllText(failureBase.makeOutputObject(".stdout").getFilesystemPath(), getStdoutString()); File.WriteAllText(failureBase.makeOutputObject(".stderr").getFilesystemPath(), getStderr()); } } } if (passed() && _tmpStdoutPath != null) { File.Delete(finalStdoutPath); File.Move(_tmpStdoutPath, finalStdoutPath); _tmpStdoutPath = null; } }
string dispositionFilePath(BuildObject bob) { return(bob.getFilesystemPath() + dispositionFileExtension); }