public void IsInitialized() { RelativePath p = default(RelativePath); XAssert.IsFalse(p.IsValid); var st = new StringTable(0); p = RelativePath.Create(st, @"usr/src"); XAssert.AreEqual(@"usr/src", p.ToString(st)); XAssert.IsTrue(p.IsValid); XAssert.IsFalse(p.IsEmpty); p = RelativePath.Create(st, string.Empty); XAssert.IsTrue(p.IsValid); XAssert.IsTrue(p.IsEmpty); p = RelativePath.Create(st, "path1:/path2/"); XAssert.IsTrue(p.IsValid); }
public void GlobalUntrackedDirectoryScopesAreHonored() { var projectB = CreateRushProject("@ms/B"); var projectA = CreateRushProject("@ms/A", dependencies: new[] { projectB }); var relativeScopeToUntrack = RelativePath.Create(StringTable, @"untracked\scope"); var untrackedScopes = Start(new RushResolverSettings { UntrackedGlobalDirectoryScopes = new[] { relativeScopeToUntrack } }) .Add(projectB) .Add(projectA) .ScheduleAll() .RetrieveSuccessfulProcess(projectA) .UntrackedScopes; // The untracked scope should be configured under every project root XAssert.Contains(untrackedScopes, projectA.ProjectFolder.Combine(PathTable, relativeScopeToUntrack), projectB.ProjectFolder.Combine(PathTable, relativeScopeToUntrack)); }
public void TestNoSourceSealDirectoryShouldLaterBeSpecifiedAboveOutputDirectory(AddDirectory addDirectory, bool allDirectories) { using (TestEnv env = TestEnv.CreateTestEnvWithPausedScheduler()) { AbsolutePath path = env.Configuration.Layout.ObjectDirectory.Combine( env.PathTable, RelativePath.Create(env.PathTable.StringTable, @"a\b\c\Dir1")); var pip1 = CreatePipBuilderWithTag(env, "test"); addDirectory(pip1, path); env.PipConstructionHelper.AddProcess(pip1); AbsolutePath ssdPath = env.Configuration.Layout.ObjectDirectory.Combine(env.PathTable, "a"); env.PipConstructionHelper.SealDirectorySource( ssdPath, allDirectories ? SealDirectoryKind.SourceAllDirectories : SealDirectoryKind.SourceTopDirectoryOnly ); AssertFailedGraphBuilding(env); } }
/// <summary> /// Helper method with defaults for convenient creation from unit tests /// </summary> public static PipConstructionHelper CreateForTesting( PipExecutionContext context, AbsolutePath?objectRoot = null, AbsolutePath?tempRoot = null, string moduleName = null, string specRelativePath = null, string symbol = null, AbsolutePath?specPath = null, QualifierId?qualifierId = null) { return(Create( context, objectRoot ?? AbsolutePath.Create(context.PathTable, "d:\\test\\obj"), tempRoot ?? objectRoot ?? AbsolutePath.Create(context.PathTable, "d:\\test\\tmp"), new ModuleId(1), moduleName ?? "TestModule", RelativePath.Create(context.StringTable, specRelativePath ?? "spec"), FullSymbol.Create(context.SymbolTable, symbol ?? "testValue"), new LocationData(specPath ?? AbsolutePath.Create(context.PathTable, "d:\\src\\spec.dsc"), 0, 0), qualifierId ?? QualifierId.Unqualified)); }
/// <summary> /// Starts the addition of projects /// </summary> public override ProjectBuilder <JavaScriptProject, RushResolverSettings> Start( RushResolverSettings resolverSettings = null, QualifierId currentQualifier = default, QualifierId[] requestedQualifiers = default) { var settings = resolverSettings ?? new RushResolverSettings(); // Make sure the Root is set if (settings.Root == AbsolutePath.Invalid) { settings.Root = AbsolutePath.Create(PathTable, TestRoot); } // If the common temp folder is not set explicitly, use <sourceRoot>/common/temp, which is usually the Rush default if (!m_commonTempFolder.IsValid) { m_commonTempFolder = settings.Root.Combine(PathTable, RelativePath.Create(StringTable, "common/temp")); } return(base.Start(settings, currentQualifier, requestedQualifiers)); }
public void Combine() { var pt = new PathTable(); AbsolutePath a1 = AbsolutePath.Create(pt, @"C:\"); PathAtom p1 = PathAtom.Create(pt.StringTable, "A"); AbsolutePath a2 = a1.Combine(pt, p1); XAssert.AreEqual(@"C:\A", a2.ToString(pt)); a1 = AbsolutePath.Create(pt, @"C:\X"); p1 = PathAtom.Create(pt.StringTable, "A"); a2 = a1.Combine(pt, p1); XAssert.AreEqual(@"C:\X\A", a2.ToString(pt)); a1 = AbsolutePath.Create(pt, @"C:\X"); p1 = PathAtom.Create(pt.StringTable, "A"); PathAtom p2 = PathAtom.Create(pt.StringTable, "B"); a2 = a1.Combine(pt, p1, p2); XAssert.AreEqual(@"C:\X\A\B", a2.ToString(pt)); a1 = AbsolutePath.Create(pt, @"C:\X"); p1 = PathAtom.Create(pt.StringTable, "A"); p2 = PathAtom.Create(pt.StringTable, "B"); PathAtom p3 = PathAtom.Create(pt.StringTable, "C"); a2 = a1.Combine(pt, p1, p2, p3); XAssert.AreEqual(@"C:\X\A\B\C", a2.ToString(pt)); a1 = AbsolutePath.Create(pt, @"C:\"); RelativePath rp = RelativePath.Create(pt.StringTable, @"A\B"); a2 = a1.Combine(pt, rp); XAssert.AreEqual(@"C:\A\B", a2.ToString(pt)); a1 = AbsolutePath.Create(pt, @"C:\X"); rp = RelativePath.Create(pt.StringTable, @"A\B"); a2 = a1.Combine(pt, rp); XAssert.AreEqual(@"C:\X\A\B", a2.ToString(pt)); }
public void Equality() { var st = new StringTable(0); RelativePath a1 = RelativePath.Create(st, @"usr/src"); RelativePath a2 = RelativePath.Create(st, @"usr/src"); RelativePath a3 = RelativePath.Create(st, @"lib/src"); XAssert.IsTrue(a1.Equals(a1)); XAssert.IsTrue(a1.Equals(a2)); XAssert.IsTrue(a2.Equals(a1)); XAssert.IsFalse(a1.Equals(a3)); XAssert.IsFalse(a2.Equals(a3)); XAssert.IsTrue(a1.Equals((object)a1)); XAssert.IsTrue(a1.Equals((object)a2)); XAssert.IsTrue(a2.Equals((object)a1)); XAssert.IsFalse(a1.Equals((object)a3)); XAssert.IsFalse(a2.Equals((object)a3)); XAssert.IsFalse(a2.Equals("home")); XAssert.IsTrue(a1 == a2); XAssert.IsTrue(a2 == a1); XAssert.IsFalse(a1 == a3); XAssert.IsFalse(a2 == a3); XAssert.IsFalse(a1 != a2); XAssert.IsFalse(a2 != a1); XAssert.IsTrue(a1 != a3); XAssert.IsTrue(a2 != a3); int h1 = a1.GetHashCode(); int h2 = a2.GetHashCode(); XAssert.AreEqual(h1, h2); a1 = RelativePath.Create(st, string.Empty); XAssert.AreEqual(HashCodeHelper.Fnv1Basis32, a1.GetHashCode()); XAssert.IsFalse(a1.Equals(a2)); }
public void Combine() { var pt = new PathTable(); AbsolutePath a1 = AbsolutePath.Create(pt, @"/"); PathAtom p1 = PathAtom.Create(pt.StringTable, "home"); AbsolutePath a2 = a1.Combine(pt, p1); XAssert.AreEqual(@"/home", a2.ToString(pt)); a1 = AbsolutePath.Create(pt, @"/home"); p1 = PathAtom.Create(pt.StringTable, "root"); a2 = a1.Combine(pt, p1); XAssert.AreEqual(@"/home/root", a2.ToString(pt)); a1 = AbsolutePath.Create(pt, @"/home"); p1 = PathAtom.Create(pt.StringTable, "root"); PathAtom p2 = PathAtom.Create(pt.StringTable, "documents"); a2 = a1.Combine(pt, p1, p2); XAssert.AreEqual(@"/home/root/documents", a2.ToString(pt)); a1 = AbsolutePath.Create(pt, @"/home"); p1 = PathAtom.Create(pt.StringTable, "root"); p2 = PathAtom.Create(pt.StringTable, "documents"); PathAtom p3 = PathAtom.Create(pt.StringTable, "config"); a2 = a1.Combine(pt, p1, p2, p3); XAssert.AreEqual(@"/home/root/documents/config", a2.ToString(pt)); a1 = AbsolutePath.Create(pt, @"/"); RelativePath rp = RelativePath.Create(pt.StringTable, @"home/root"); a2 = a1.Combine(pt, rp); XAssert.AreEqual(@"/home/root", a2.ToString(pt)); a1 = AbsolutePath.Create(pt, @"/home"); rp = RelativePath.Create(pt.StringTable, @"root/documents"); a2 = a1.Combine(pt, rp); XAssert.AreEqual(@"/home/root/documents", a2.ToString(pt)); }
public void Equality() { var st = new StringTable(0); RelativePath a1 = RelativePath.Create(st, @"AAA\CCC"); RelativePath a2 = RelativePath.Create(st, @"AAA\CCC"); RelativePath a3 = RelativePath.Create(st, @"BBB\CCC"); XAssert.IsTrue(a1.Equals(a1)); XAssert.IsTrue(a1.Equals(a2)); XAssert.IsTrue(a2.Equals(a1)); XAssert.IsFalse(a1.Equals(a3)); XAssert.IsFalse(a2.Equals(a3)); XAssert.IsTrue(a1.Equals((object)a1)); XAssert.IsTrue(a1.Equals((object)a2)); XAssert.IsTrue(a2.Equals((object)a1)); XAssert.IsFalse(a1.Equals((object)a3)); XAssert.IsFalse(a2.Equals((object)a3)); XAssert.IsFalse(a2.Equals("XYZ")); XAssert.IsTrue(a1 == a2); XAssert.IsTrue(a2 == a1); XAssert.IsFalse(a1 == a3); XAssert.IsFalse(a2 == a3); XAssert.IsFalse(a1 != a2); XAssert.IsFalse(a2 != a1); XAssert.IsTrue(a1 != a3); XAssert.IsTrue(a2 != a3); int h1 = a1.GetHashCode(); int h2 = a2.GetHashCode(); XAssert.AreEqual(h1, h2); a1 = RelativePath.Create(st, string.Empty); XAssert.AreEqual(0, a1.GetHashCode()); XAssert.IsFalse(a1.Equals(a2)); }
/// <summary> /// Helper method to create a rush project /// </summary> public RushProject CreateRushProject( string projectName = null, string buildCommand = null, AbsolutePath?tempFolder = null, IReadOnlyCollection <AbsolutePath> additionalOutputDirectories = null, IReadOnlyCollection <RushProject> dependencies = null) { projectName ??= "@ms/rush-proj"; var tempDirectory = tempFolder.HasValue ? tempFolder.Value : AbsolutePath.Create(PathTable, GetTempDir()); var rushProject = new RushProject( projectName, TestPath.Combine(PathTable, RelativePath.Create(StringTable, projectName)), buildCommand ?? "node ./main.js", tempDirectory, additionalOutputDirectories ?? CollectionUtilities.EmptyArray <AbsolutePath>() ); rushProject.SetDependencies(dependencies ?? CollectionUtilities.EmptyArray <RushProject>()); return(rushProject); }
/// <summary> /// Helper method to create a project with predictions rooted at the test root /// </summary> /// <returns></returns> public ProjectWithPredictions CreateProjectWithPredictions( string projectName = null, IReadOnlyCollection <AbsolutePath> inputs = null, IReadOnlyCollection <AbsolutePath> outputs = null, IEnumerable <ProjectWithPredictions> references = null, GlobalProperties globalProperties = null, PredictedTargetsToExecute predictedTargetsToExecute = null, bool implementsTargetProtocol = true) { var projectNameRelative = RelativePath.Create(StringTable, projectName ?? "testProj.proj"); var projectWithPredictions = new ProjectWithPredictions( TestPath.Combine(PathTable, projectNameRelative), implementsTargetProtocol, globalProperties ?? GlobalProperties.Empty, inputs ?? CollectionUtilities.EmptyArray <AbsolutePath>(), outputs ?? CollectionUtilities.EmptyArray <AbsolutePath>(), projectReferences: references?.ToArray() ?? CollectionUtilities.EmptyArray <ProjectWithPredictions>(), predictedTargetsToExecute: predictedTargetsToExecute ?? PredictedTargetsToExecute.Create(new[] { "Build" })); return(projectWithPredictions); }
public void IncrementalPreserveOutputTool() { Configuration.Sandbox.UnsafeSandboxConfigurationMutable.PreserveOutputs = PreserveOutputsMode.Enabled; Configuration.IncrementalTools = new List <RelativePath> { RelativePath.Create(Context.StringTable, TestProcessToolName) }; AbsolutePath readonlyRootPath; AbsolutePath.TryCreate(Context.PathTable, ReadonlyRoot, out readonlyRootPath); // Create /readonly/a.txt FileArtifact aTxtFile = CreateFileArtifactWithName("a.txt", ReadonlyRoot); WriteSourceFile(aTxtFile); DirectoryArtifact readonlyRootDir = SealDirectory(readonlyRootPath, SealDirectoryKind.SourceAllDirectories); var builder = CreatePipBuilder(new Operation[] { Operation.Probe(aTxtFile, doNotInfer: true), Operation.WriteFile(CreateOutputFileArtifact()) }); builder.AddInputDirectory(readonlyRootDir); builder.Options |= Process.Options.AllowPreserveOutputs; builder.Options |= Process.Options.IncrementalTool; var pip = SchedulePipBuilder(builder).Process; RunScheduler().AssertCacheMiss(pip.PipId); RunScheduler().AssertCacheHit(pip.PipId); WriteSourceFile(aTxtFile); RunScheduler().AssertCacheMiss(pip.PipId); }
public void NoSourceSealDirectoryShouldBeSpecifiedAboveSharedOpaqueDirectory(string SharedOpaqueDir, string sourceSealDir, bool allDirectories) { using (TestEnv env = TestEnv.CreateTestEnvWithPausedScheduler()) { AbsolutePath sodPath = env.Configuration.Layout.ObjectDirectory.Combine( env.PathTable, RelativePath.Create(env.PathTable.StringTable, SharedOpaqueDir)); var pip1 = CreatePipBuilderWithTag(env, "test"); pip1.AddOutputDirectory(sodPath, SealDirectoryKind.SharedOpaque); env.PipConstructionHelper.AddProcess(pip1); AbsolutePath ssdPath = env.Configuration.Layout.ObjectDirectory.Combine( env.PathTable, RelativePath.Create(env.PathTable.StringTable, sourceSealDir)); env.PipConstructionHelper.SealDirectorySource( ssdPath, kind: allDirectories ? SealDirectoryKind.SourceAllDirectories : SealDirectoryKind.SourceTopDirectoryOnly); AssertFailedGraphBuilding(env); } }
public void ComplexEnvironmentVariableIsHonored() { var data = new EnvironmentData(new CompoundEnvironmentData() { Separator = "|", Contents = new[] { new EnvironmentData(1), new EnvironmentData("2"), new EnvironmentData(AbsolutePath.Create(PathTable, "C:\\foo\\bar")), new EnvironmentData(new CompoundEnvironmentData() { Separator = " ", Contents = new [] { new EnvironmentData(PathAtom.Create(StringTable, "atom")), new EnvironmentData(RelativePath.Create(StringTable, "relative\\path")) } }), new EnvironmentData(DirectoryArtifact.CreateWithZeroPartialSealId(AbsolutePath.Create(PathTable, "C:\\foo\\baaz"))) } }); var project = CreateProjectWithPredictions("A.proj"); var testProj = Start(new MsBuildResolverSettings { Environment = new Dictionary <string, EnvironmentData> { ["Test"] = data } }) .Add(project) .ScheduleAll() .AssertSuccess() .RetrieveSuccessfulProcess(project); var testEnvironmentVariable = testProj.EnvironmentVariables.First(e => e.Name.ToString(PathTable.StringTable).Equals("Test")); Assert.Equal("1|2|C:\\foo\\bar|atom relative\\path|C:\\foo\\baaz", testEnvironmentVariable.Value.ToString(PathTable)); }
public void TryCreate() { var st = new StringTable(0); RelativePath p; XAssert.IsTrue(RelativePath.TryCreate(st, @"AAA\CCC", out p)); XAssert.AreEqual(@"AAA\CCC", p.ToString(st)); XAssert.IsFalse(RelativePath.TryCreate(st, @"C\:AAA", out p)); XAssert.IsFalse(RelativePath.TryCreate(st, @"AAA:", out p)); XAssert.IsFalse(RelativePath.TryCreate(st, @":AAA", out p)); XAssert.IsFalse(RelativePath.TryCreate(st, @"..", out p)); p = RelativePath.Create(st, "."); XAssert.AreEqual(string.Empty, p.ToString(st)); p = RelativePath.Create(st, "BBB"); XAssert.AreEqual("BBB", p.ToString(st)); p = RelativePath.Create(st, @"BBB\."); XAssert.AreEqual("BBB", p.ToString(st)); p = RelativePath.Create(st, @"BBB\.."); XAssert.AreEqual(string.Empty, p.ToString(st)); p = RelativePath.Create(st, @"BBB\CCC\.."); XAssert.AreEqual("BBB", p.ToString(st)); PathAtom a1 = PathAtom.Create(st, "AAA"); PathAtom a2 = PathAtom.Create(st, "BBB"); PathAtom a3 = PathAtom.Create(st, "CCC"); p = RelativePath.Create(a1, a2, a3); XAssert.AreEqual(@"AAA\BBB\CCC", p.ToString(st)); }
public void TryCreate() { var st = new StringTable(0); RelativePath p; XAssert.IsTrue(RelativePath.TryCreate(st, @"usr/src", out p)); XAssert.AreEqual(@"usr/src", p.ToString(st)); XAssert.IsFalse(RelativePath.TryCreate(st, @"C\:AAA", out p)); XAssert.IsFalse(RelativePath.TryCreate(st, @"AAA:", out p)); XAssert.IsFalse(RelativePath.TryCreate(st, @":AAA", out p)); XAssert.IsFalse(RelativePath.TryCreate(st, @"..", out p)); p = RelativePath.Create(st, "."); XAssert.AreEqual(string.Empty, p.ToString(st)); p = RelativePath.Create(st, "usr"); XAssert.AreEqual("usr", p.ToString(st)); p = RelativePath.Create(st, @"usr/."); XAssert.AreEqual("usr", p.ToString(st)); p = RelativePath.Create(st, @"usr\.."); XAssert.AreEqual(string.Empty, p.ToString(st)); p = RelativePath.Create(st, @"usr/src/.."); XAssert.AreEqual("usr", p.ToString(st)); PathAtom a1 = PathAtom.Create(st, "usr"); PathAtom a2 = PathAtom.Create(st, "src"); PathAtom a3 = PathAtom.Create(st, "include"); p = RelativePath.Create(a1, a2, a3); XAssert.AreEqual(@"usr/src/include", p.ToString(st)); }
public NinjaPipConstructor(FrontEndContext context, FrontEndHost frontEndHost, string frontEndName, ModuleDefinition moduleDefinition, QualifierId qualifierId, AbsolutePath projectRoot, AbsolutePath specPath, bool suppressDebugFlags, IUntrackingSettings untrackingSettings) { Contract.Requires(context != null); Contract.Requires(frontEndHost != null); Contract.Requires(moduleDefinition != null); Contract.Requires(projectRoot.IsValid); Contract.Requires(specPath.IsValid); m_context = context; m_frontEndHost = frontEndHost; m_moduleDefinition = moduleDefinition; m_projectRoot = projectRoot; m_specPath = specPath; m_suppressDebugFlags = suppressDebugFlags; m_untrackingSettings = untrackingSettings; m_pipConstructionHelper = GetPipConstructionHelperForModule(m_projectRoot, moduleDefinition, qualifierId); m_frontEndName = frontEndName; m_manuallyDroppedDependenciesPath = Lazy.Create(() => m_frontEndHost.Configuration.Layout.BuildEngineDirectory .Combine(m_context.PathTable, RelativePath.Create(m_context.StringTable, @"tools\CMakeNinjaPipEnvironment"))); // Lazy initialization of environment variables and passthroughs var allEnvironmentVariables = Lazy.Create(GetAllEnvironmentVariables); m_environmentVariables = Lazy.Create(() => allEnvironmentVariables.Value.Where(kvp => SpecialEnvironmentVariables.PassThroughPrefixes.All(prefix => !kvp.Key.StartsWith(prefix)))); m_passThroughEnvironmentVariables = Lazy.Create(() => allEnvironmentVariables.Value.Where(kvp => SpecialEnvironmentVariables.PassThroughPrefixes.Any(prefix => kvp.Key.StartsWith(prefix)))); }
private string GetRelativePathString(string relative) { return RelativePath.Create(StringTable, relative).ToString(StringTable); }
private AbsolutePath CreateAbsolutePath(AbsolutePath root, string relative) => root.Combine( Context.PathTable, RelativePath.Create(Context.StringTable, relative));
private Task <SandboxedProcessResult> ExecuteCMakeRunner(AbsolutePath argumentsFile, IEnumerable <AbsolutePath> searchLocations) { string rootString = ProjectRoot.ToString(m_context.PathTable); AbsolutePath outputDirectory = argumentsFile.GetParent(m_context.PathTable); FileUtilities.CreateDirectory(outputDirectory.ToString(m_context.PathTable)); // Ensure it exists SerializeToolArguments(argumentsFile, searchLocations); void CleanUpOnResult() { try { FileUtilities.DeleteFile(argumentsFile.ToString(m_context.PathTable)); } catch (BuildXLException e) { Tracing.Logger.Log.CouldNotDeleteToolArgumentsFile( m_context.LoggingContext, m_resolverSettings.Location(m_context.PathTable), argumentsFile.ToString(m_context.PathTable), e.Message); } } var environment = FrontEndUtilities.GetEngineEnvironment(m_host.Engine, CMakeResolverName); // TODO: This manual configuration is temporary. Remove after the cloud builders have the correct configuration var pathToManuallyDroppedTools = m_configuration.Layout.BuildEngineDirectory.Combine(m_context.PathTable, RelativePath.Create(m_context.StringTable, @"tools\CmakeNinjaPipEnvironment")); if (FileUtilities.Exists(pathToManuallyDroppedTools.ToString(m_context.PathTable))) { environment = SpecialCloudConfiguration.OverrideEnvironmentForCloud(environment, pathToManuallyDroppedTools, m_context); } var buildParameters = BuildParameters.GetFactory().PopulateFromDictionary(new ReadOnlyDictionary <string, string>(environment)); return(FrontEndUtilities.RunSandboxedToolAsync( m_context, m_pathToTool.ToString(m_context.PathTable), buildStorageDirectory: outputDirectory.ToString(m_context.PathTable), fileAccessManifest: GenerateFileAccessManifest(m_pathToTool.GetParent(m_context.PathTable)), arguments: I($@"""{argumentsFile.ToString(m_context.PathTable)}"""), workingDirectory: rootString, description: "CMakeRunner", buildParameters, onResult: CleanUpOnResult)); }
/// <summary> /// Creates an output file artifact. /// </summary> public FileArtifact CreateOutputFile(string relative) => FileArtifact.CreateOutputFile(m_objectRoot.Combine( Context.PathTable, RelativePath.Create(Context.StringTable, relative)));
/// <summary> /// Creates a source file artifact. /// </summary> public FileArtifact CreateSourceFile(string relative) => FileArtifact.CreateSourceFile(m_sourceRoot.Combine( Context.PathTable, RelativePath.Create(Context.StringTable, relative)));
/// <summary> /// Creates a new PipConstructionHelper /// </summary> /// <remarks> /// Ideally this function would take ModuleId, FullSymbol QualifierId and compute uniqueOutputLocation itself. Unfortunately today the data is not yet /// exposed via IPipGraph, therefore the responsibility is on the call site for now. /// </remarks> public static PipConstructionHelper Create( PipExecutionContext context, AbsolutePath objectRoot, AbsolutePath redirectedRoot, AbsolutePath tempRoot, IMutablePipGraph pipGraph, ModuleId moduleId, string moduleName, RelativePath specRelativePath, FullSymbol symbol, LocationData thunkLocation, QualifierId qualifierId) { var stringTable = context.StringTable; var pathTable = context.PathTable; // We have to manually compute the pipPipUniqueString here, Ideally we pass PackageId, SpecFile, FullSymbol and qualiferId and have it computed inside, but the IPipGraph does not allow querying it for now. string hashString; long semiStableHashSeed = 0; using (var builderWrapper = Pools.GetStringBuilder()) { var builder = builderWrapper.Instance; builder.Append(moduleName); builder.Append('/'); semiStableHashSeed = HashCodeHelper.GetOrdinalHashCode64(moduleName); if (specRelativePath.IsValid) { string specPath = specRelativePath.ToString(stringTable); builder.Append(specPath); builder.Append('/'); semiStableHashSeed = HashCodeHelper.Combine(semiStableHashSeed, HashCodeHelper.GetOrdinalHashCode64(specPath)); } var symbolName = symbol.ToStringAsCharArray(context.SymbolTable); builder.Append(symbolName); builder.Append('/'); semiStableHashSeed = HashCodeHelper.Combine(semiStableHashSeed, HashCodeHelper.GetOrdinalHashCode64(symbolName)); var qualifierDisplayValue = context.QualifierTable.GetCanonicalDisplayString(qualifierId); builder.Append(qualifierDisplayValue); semiStableHashSeed = HashCodeHelper.Combine(semiStableHashSeed, HashCodeHelper.GetOrdinalHashCode64(qualifierDisplayValue)); var pipPipUniqueString = builder.ToString(); hashString = Hash(pipPipUniqueString); } var pipRelativePath = RelativePath.Create( PathAtom.Create(stringTable, hashString.Substring(0, 1)), PathAtom.Create(stringTable, hashString.Substring(1, 1)), PathAtom.Create(stringTable, hashString.Substring(2))); var valuePip = new ValuePip(symbol, qualifierId, thunkLocation); return(new PipConstructionHelper( context, objectRoot, redirectedRoot, tempRoot, pipGraph, moduleId, moduleName, valuePip, pipRelativePath, semiStableHashSeed)); }
private static object CreateInstance(BuildXLContext context, Type type, bool booleanDefault) { string path = A("x", "path"); type = GetNonNullableType(type); if (type == typeof(bool)) { return(booleanDefault); } if (type == typeof(double)) { return((double)0.23423); } if (type == typeof(byte)) { return((byte)123); } if (type == typeof(sbyte)) { return((sbyte)123); } if (type == typeof(short)) { return((short)123); } if (type == typeof(ushort)) { return((ushort)123); } if (type == typeof(int)) { return(123); } if (type == typeof(uint)) { return((uint)123); } if (type == typeof(long)) { return((long)123); } if (type == typeof(ulong)) { return((ulong)123); } if (type == typeof(string)) { return("nonDefaultString"); } if (type == typeof(ModuleId)) { return(new ModuleId(123)); } if (type == typeof(LocationData)) { return(new LocationData(AbsolutePath.Create(context.PathTable, path), 12, 23)); } if (type == typeof(AbsolutePath)) { return(AbsolutePath.Create(context.PathTable, path)); } if (type == typeof(RelativePath)) { string relativePath = R("rel1", "dir1", "path"); return(RelativePath.Create(context.StringTable, relativePath)); } if (type == typeof(FileArtifact)) { return(FileArtifact.CreateSourceFile(AbsolutePath.Create(context.PathTable, path))); } if (type == typeof(PathAtom)) { return(PathAtom.Create(context.StringTable, "atom")); } if (type == typeof(global::BuildXL.Utilities.LineInfo)) { return(new global::BuildXL.Utilities.LineInfo(1, 1)); } if (type.GetTypeInfo().IsEnum) { bool first = true; foreach (var value in Enum.GetValues(type)) { if (!first) { return(value); } first = false; } XAssert.Fail($"Enum {type.FullName} doesn't have more than one value, so can't pick the second one."); } if (type.GetTypeInfo().IsGenericType) { var generic = type.GetGenericTypeDefinition(); if (generic == typeof(IReadOnlyList <>)) { // Treat IReadOnlyList as if it was List type = typeof(List <>).MakeGenericType(type.GenericTypeArguments[0]); generic = type.GetGenericTypeDefinition(); } if (generic == typeof(List <>)) { var newList = (IList)Activator.CreateInstance(type); newList.Add(CreateInstance(context, type.GenericTypeArguments[0], booleanDefault)); return(newList); } if (generic == typeof(IReadOnlyDictionary <,>)) { // Treat IReadOnlyList as if it was List type = typeof(Dictionary <,>).MakeGenericType(type.GenericTypeArguments[0], type.GenericTypeArguments[1]); generic = type.GetGenericTypeDefinition(); } if (generic == typeof(Dictionary <,>)) { var newDictionary = (IDictionary)Activator.CreateInstance(type); newDictionary.Add( CreateInstance(context, type.GenericTypeArguments[0], booleanDefault), CreateInstance(context, type.GenericTypeArguments[1], booleanDefault)); return(newDictionary); } } if (type.GetTypeInfo().IsInterface) { // Treat interfaces as if it was the mutable class type = ConfigurationConverter.FindImplementationType( type, ObjectLiteral.Create(new List <Binding>(), default(LineInfo), AbsolutePath.Invalid), // Return a SourceResolver to instantiate () => "SourceResolver"); } if (type.GetTypeInfo().IsClass) { var instance = Activator.CreateInstance(type); PopulateObject(context, type, instance, booleanDefault); return(instance); } XAssert.Fail($"Don't know how to create objects for this type: {type.FullName}."); return(null); }
public void TestRelativePathLiteral() { RelativePathLiteral node = new RelativePathLiteral(RelativePath.Create(GetPathAtom()), DefaultLineInfo); CheckSerializationRoundTrip(node); }
public void PredictedInputsUnderUntrackedDirectoriesAreSkipped(bool pathRelativeToProject) { var project = CreateProjectWithPredictions(inputs: CreatePath(@"untracked\input.txt", "input2.txt")); var processInputs = Start(new MsBuildResolverSettings { UntrackedDirectories = CreatePath("untracked").Select(path => pathRelativeToProject ? new DiscriminatingUnion <DirectoryArtifact, RelativePath>(RelativePath.Create(StringTable, @"untracked\input.txt")) : new DiscriminatingUnion <DirectoryArtifact, RelativePath>(DirectoryArtifact.CreateWithZeroPartialSealId(path))) .ToList() }) .Add(project) .ScheduleAll() .RetrieveSuccessfulProcess(project) .Dependencies; // The only source file (besides MSBuild.exe itself) should be input2 var input = processInputs.Single(i => (i.IsSourceFile && i.Path.GetName(PathTable) != PathAtom.Create(StringTable, "MSBuild.exe"))); XAssert.AreEqual("input2.txt", input.Path.GetName(PathTable).ToString(PathTable.StringTable)); }
public void ChangeExtension() { var st = new StringTable(0); // change a single char extension RelativePath rp1 = RelativePath.Create(st, @"a.c"); RelativePath rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"a.d", rp2.ToString(st)); // change a multi char extension rp1 = RelativePath.Create(st, @"a.cpp"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"a.d", rp2.ToString(st)); // change nothing rp1 = RelativePath.Create(st, @"a"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"a.d", rp2.ToString(st)); // change a single char extension rp1 = RelativePath.Create(st, @"ab.c"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"ab.d", rp2.ToString(st)); // change a multi char extension rp1 = RelativePath.Create(st, @"ab.cpp"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"ab.d", rp2.ToString(st)); // change nothing rp1 = RelativePath.Create(st, @"ab"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"ab.d", rp2.ToString(st)); // change a single char extension rp1 = RelativePath.Create(st, @"ab.xyz.c"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"ab.xyz.d", rp2.ToString(st)); // change a multi char extension rp1 = RelativePath.Create(st, @"ab.xyz.cpp"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"ab.xyz.d", rp2.ToString(st)); rp1 = RelativePath.Create(st, @".cpp"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@".d", rp2.ToString(st)); // change a single char extension rp1 = RelativePath.Create(st, @"xyz\a.c"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"xyz\a.d", rp2.ToString(st)); // change a multi char extension rp1 = RelativePath.Create(st, @"xyz\a.cpp"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"xyz\a.d", rp2.ToString(st)); // change nothing rp1 = RelativePath.Create(st, @"xyz\a"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"xyz\a.d", rp2.ToString(st)); // change a single char extension rp1 = RelativePath.Create(st, @"xyz\ab.c"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"xyz\ab.d", rp2.ToString(st)); // change a multi char extension rp1 = RelativePath.Create(st, @"xyz\ab.cpp"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"xyz\ab.d", rp2.ToString(st)); // change nothing rp1 = RelativePath.Create(st, @"xyz\ab"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"xyz\ab.d", rp2.ToString(st)); // change a single char extension rp1 = RelativePath.Create(st, @"xyz\ab.xyz.c"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"xyz\ab.xyz.d", rp2.ToString(st)); // change a multi char extension rp1 = RelativePath.Create(st, @"xyz\ab.xyz.cpp"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"xyz\ab.xyz.d", rp2.ToString(st)); rp1 = RelativePath.Create(st, @"xyz\.cpp"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".d")); XAssert.AreEqual(@"xyz\.d", rp2.ToString(st)); // nop change rp1 = RelativePath.Create(st, @"xyz\ab.xyz.cpp"); rp2 = rp1.ChangeExtension(st, PathAtom.Create(st, ".cpp")); XAssert.AreEqual(rp1, rp2); rp1 = RelativePath.Create(st, @"xyz\ab.xyz.cpp"); rp2 = rp1.ChangeExtension(st, PathAtom.Invalid); XAssert.AreEqual(@"xyz\ab.xyz", rp2.ToString(st)); }
public void RemoveExtension() { var st = new StringTable(0); // remove a single char extension RelativePath rp1 = RelativePath.Create(st, @"a.c"); RelativePath rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(@"a", rp2.ToString(st)); // remove a multi char extension rp1 = RelativePath.Create(st, @"a.cpp"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(@"a", rp2.ToString(st)); // remove nothing rp1 = RelativePath.Create(st, @"a"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(rp1, rp2); // remove a single char extension rp1 = RelativePath.Create(st, @"ab.c"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(@"ab", rp2.ToString(st)); // remove a multi char extension rp1 = RelativePath.Create(st, @"ab.cpp"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(@"ab", rp2.ToString(st)); // remove nothing rp1 = RelativePath.Create(st, @"ab"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(rp1, rp2); rp1 = RelativePath.Create(st, @"ab.xyz.c"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(@"ab.xyz", rp2.ToString(st)); // remove a multi char extension rp1 = RelativePath.Create(st, @"ab.xyz.cpp"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(@"ab.xyz", rp2.ToString(st)); rp1 = RelativePath.Create(st, @".cpp"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(rp1, rp2); // remove a single char extension rp1 = RelativePath.Create(st, @"xyz\a.c"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(@"xyz\a", rp2.ToString(st)); // remove a multi char extension rp1 = RelativePath.Create(st, @"xyz\a.cpp"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(@"xyz\a", rp2.ToString(st)); // remove nothing rp1 = RelativePath.Create(st, @"xyz\a"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(rp1, rp2); // remove a single char extension rp1 = RelativePath.Create(st, @"xyz\ab.c"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(@"xyz\ab", rp2.ToString(st)); // remove a multi char extension rp1 = RelativePath.Create(st, @"xyz\ab.cpp"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(@"xyz\ab", rp2.ToString(st)); // remove nothing rp1 = RelativePath.Create(st, @"xyz\ab"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(rp1, rp2); rp1 = RelativePath.Create(st, @"xyz\ab.xyz.c"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(@"xyz\ab.xyz", rp2.ToString(st)); // remove a multi char extension rp1 = RelativePath.Create(st, @"xyz\ab.xyz.cpp"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(@"xyz\ab.xyz", rp2.ToString(st)); rp1 = RelativePath.Create(st, @"xyz\.cpp"); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(rp1, rp2); rp1 = RelativePath.Create(st, string.Empty); rp2 = rp1.RemoveExtension(st); XAssert.AreEqual(rp1, rp2); }
/// <summary> /// Extracts a file into a folder with in manifest based incrementality. /// </summary> internal async Task <EvaluationResult> PerformExtractOrIncrementalCheckAsync(DownloadData downloadData) { if (m_context.CancellationToken.IsCancellationRequested) { return(EvaluationResult.Canceled); } // Ensure file is downloaded var extractedFileResult = await DownloadFile(downloadData); if (extractedFileResult.IsErrorValue) { return(extractedFileResult); } var extractedFile = (FileArtifact)extractedFileResult.Value; var moduleDescriptor = m_workspaceResolver.GetModuleDescriptor(downloadData); var pipConstructionHelper = PipConstructionHelper.Create( m_context, m_frontEndHost.Engine.Layout.ObjectDirectory, m_frontEndHost.Engine.Layout.RedirectedDirectory, m_frontEndHost.Engine.Layout.TempDirectory, m_frontEndHost.PipGraph, moduleDescriptor.Id, moduleDescriptor.Name, RelativePath.Create(downloadData.ModuleSpecFile.GetName(m_context.PathTable)), FullSymbol.Create(m_context.SymbolTable, "extracted"), new LocationData(downloadData.ModuleSpecFile, 0, 0), m_context.QualifierTable.EmptyQualifierId); // When we don't have to extract we'll expose the downloaded file in the contents. if (downloadData.Settings.ArchiveType == DownloadArchiveType.File) { return(SealDirectory( pipConstructionHelper, downloadData, DirectoryArtifact.CreateWithZeroPartialSealId(downloadData.DownloadedFilePath.GetParent(m_context.PathTable)), SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> .FromSortedArrayUnsafe( ReadOnlyArray <FileArtifact> .FromWithoutCopy(new[] { extractedFile }), OrdinalFileArtifactComparer.Instance))); } Statistics.Extractions.Total.Increment(); using (Statistics.Extractions.UpToDateCheckDuration.Start(downloadData.Settings.Url)) { var result = await CheckIfExtractIsNeededAsync(pipConstructionHelper, downloadData); if (result.IsErrorValue) { Statistics.Extractions.Failures.Increment(); } if (result != EvaluationResult.Continue) { Statistics.Extractions.SkippedDueToManifest.Increment(); return(result); } } using (Statistics.Extractions.Duration.Start(downloadData.Settings.Url)) { try { if (!await Task.Run( () => TryExtractToDisk(downloadData), m_context.CancellationToken)) { Statistics.Extractions.Failures.Increment(); return(EvaluationResult.Error); } } catch (TaskCanceledException) { return(EvaluationResult.Canceled); } } using (Statistics.Extractions.UpToDateCheckDuration.Start(downloadData.Settings.Url)) { var result = await ValidateAndStoreIncrementalExtractState(pipConstructionHelper, downloadData); if (result.IsErrorValue) { Statistics.Extractions.Failures.Increment(); } return(result); } }
private IReadOnlyCollection <AbsolutePath> CreatePath(params string[] paths) { return(paths.Select(path => TestPath.Combine(PathTable, RelativePath.Create(PathTable.StringTable, path))).ToList()); }