private static bool TryScheduleSealDirectory(TestEnv env, AbsolutePath path, SealDirectoryKind partial, FileArtifact[] contents) { var pip = new SealDirectory( path, SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> .CloneAndSort(contents, OrdinalFileArtifactComparer.Instance), kind: partial, provenance: env.CreatePipProvenance(StringId.Invalid), tags: ReadOnlyArray <StringId> .Empty, patterns: ReadOnlyArray <StringId> .Empty); DirectoryArtifact artifact = env.PipGraph.AddSealDirectory(pip, PipId.Invalid); bool succeeded = artifact.IsValid; if (succeeded) { FileArtifact[] actualContents = GetSealedDirectoryContents(env, artifact); XAssert.AreEqual(contents.Length, actualContents.Length, "Wrong number of contents sealed"); for (int i = 0; i < contents.Length; i++) { XAssert.IsTrue(contents[i] == actualContents[i], "Content artifact at position {0} mismatched", i); } } return(succeeded); }
public void TrustedAccessesAreBlockedIfPipDependsOnSourceSeal() { using (TestEnv env = TestEnv.CreateTestEnvWithPausedScheduler()) { var sourceSealedDirectory = new SealDirectory( env.SourceRoot, CollectionUtilities.EmptySortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer>(OrdinalFileArtifactComparer.Instance), outputDirectoryContents: CollectionUtilities.EmptySortedReadOnlyArray <DirectoryArtifact, OrdinalDirectoryArtifactComparer>(OrdinalDirectoryArtifactComparer.Instance), kind: SealDirectoryKind.SourceAllDirectories, provenance: env.CreatePipProvenance(StringId.Invalid), tags: ReadOnlyArray <StringId> .Empty, patterns: ReadOnlyArray <StringId> .Empty); DirectoryArtifact artifact = env.PipGraph.AddSealDirectory(sourceSealedDirectory, PipId.Invalid); Assert.True(artifact.IsValid); var pip = CreatePipBuilderWithTag(env, "test"); pip.AddInputDirectory(artifact); pip.Options |= Process.Options.TrustStaticallyDeclaredAccesses; var success = env.PipConstructionHelper.TryAddProcess(pip); Assert.False(success, "Finish should fail, a process depending on a source sealed directory is not allowed to trust declared accesses"); } }
private static SealDirectory CreateSeal(TestEnv env, AbsolutePath path, bool partial, FileArtifact[] contents) { var seal = new SealDirectory( path, SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> .CloneAndSort(contents, OrdinalFileArtifactComparer.Instance), kind: partial ? SealDirectoryKind.Partial : SealDirectoryKind.Full, provenance: env.CreatePipProvenance(StringId.Invalid), tags: ReadOnlyArray <StringId> .Empty, patterns: ReadOnlyArray <StringId> .Empty); env.PipTable.Add(((PipGraph.Builder)(env.PipGraph)).MutableDataflowGraph.CreateNode().Value, seal); return(seal); }
/// <summary> /// Schedules a pip to produce a file at the specified path under the given output directory. /// </summary> private static bool TryScheduleRewrite( TestEnv env, FileArtifact source, FileArtifact target, out FileArtifact written) { Contract.Requires(env != null); Contract.Requires(source.IsValid); Contract.Requires(target.IsValid); written = target.CreateNextWrittenVersion(); var pip = new CopyFile( source, written, ReadOnlyArray <StringId> .Empty, env.CreatePipProvenance(StringId.Invalid)); return(env.PipGraph.AddCopyFile(pip, PipId.Invalid)); }
/// <summary> /// Schedules a pip to produce a file at the specified path under the given output directory. /// </summary> private static bool TryScheduleWriteOutputFileUnderDirectory( TestEnv env, AbsolutePath directory, string relativePath, out FileArtifact target) { Contract.Requires(env != null); Contract.Requires(directory.IsValid); Contract.Requires(!string.IsNullOrEmpty(relativePath)); target = FileArtifact.CreateSourceFile(env.Paths.CreateAbsolutePath(directory, env.Paths.CreateRelativePath(relativePath))).CreateNextWrittenVersion(); var pip = new WriteFile( target, PipDataBuilder.CreatePipData(env.PathTable.StringTable, string.Empty, PipDataFragmentEscaping.NoEscaping, "content"), WriteFileEncoding.Utf8, ReadOnlyArray <StringId> .Empty, env.CreatePipProvenance(StringId.Invalid)); return(env.PipGraph.AddWriteFile(pip, PipId.Invalid)); }