Esempio n. 1
0
        /// <summary>
        /// Initializes the static fields
        /// </summary>
        /// <remarks>
        /// This function handles the manifest not being there for test and developer builds, but is very strict in the format
        /// since the generation and reading are inherently linked to the exact same build.
        /// </remarks>
        static Branding()
        {
            var assemblyRoot = Path.GetDirectoryName(AssemblyHelper.GetAssemblyLocation(Assembly.GetExecutingAssembly()));

            var manifestFilePath = Path.Combine(assemblyRoot, "BuildXL.manifest");

            if (File.Exists(manifestFilePath))
            {
                var lines = File.ReadAllLines(manifestFilePath);
                Contract.Assert(lines.Length == 6, "Branding file is malformed. Encountered wrong number of lines.");

                int line = 0;
                s_shortProductName       = lines[line++];
                s_longProductName        = lines[line++];
                s_version                = lines[line++];
                s_sourceVersion          = lines[line++];
                s_productExecutableName  = lines[line++];
                s_analyzerExecutableName = lines[line++];

                Contract.Assert(!string.IsNullOrEmpty(s_shortProductName), "Branding file is malformed. Short product name is malformed.");
                Contract.Assert(!string.IsNullOrEmpty(s_longProductName), "Branding file is malformed. Long product name is malformed.");
                Contract.Assert(!string.IsNullOrEmpty(s_version), "Branding file is malformed. Version is malformed.");
                Contract.Assert(!string.IsNullOrEmpty(s_sourceVersion), "Branding file is malformed. SourceVersion is malformed.");
                Contract.Assert(!string.IsNullOrEmpty(s_productExecutableName), "Branding file is malformed. ProductExecutableName is malformed.");
                Contract.Assert(!string.IsNullOrEmpty(s_analyzerExecutableName), "Branding file is malformed. AnalyzerExecutableName is malformed.");
            }
        }
Esempio n. 2
0
 protected static AppDeployment CreateAppDeployment(TempFileStorage tempFiles)
 {
     string manifestPath = tempFiles.GetFileName(AppDeployment.DeploymentManifestFileName);
     File.WriteAllText(
         Path.Combine(Path.GetDirectoryName(manifestPath), AppDeployment.DeploymentManifestFileName),
         AssemblyHelper.GetAssemblyLocation(Assembly.GetExecutingAssembly()));
     AppDeployment appDeployment = AppDeployment.ReadDeploymentManifest(Path.GetDirectoryName(manifestPath), AppDeployment.DeploymentManifestFileName, skipManifestCheckTestHook: true);
     return appDeployment;
 }
Esempio n. 3
0
 /// <summary>
 /// Helper to create instances of tokens.
 /// </summary>
 public static Token Create(BuildXLContext context, Type type, string text = "", int line = 0, int column = 0)
 {
     Contract.RequiresNotNull(context);
     Contract.RequiresNotNull(type);
     Contract.RequiresNotNull(text);
     return(new Token(
                AbsolutePath.Create(context.PathTable, AssemblyHelper.GetAssemblyLocation(type.GetTypeInfo().Assembly)),
                line,
                column,
                TokenText.Create(context.TokenTextTable, text)));
 }
Esempio n. 4
0
 private Optional <global::BuildXL.Storage.ChangeJournalService.IChangeJournalAccessor> TryGetJournalAccessor(VolumeMap map)
 {
     return(map.Volumes.Any()
         ? JournalAccessorGetter.TryGetJournalAccessor(LoggingContext, map, AssemblyHelper.GetAssemblyLocation(Assembly.GetExecutingAssembly()))
         : Optional <global::BuildXL.Storage.ChangeJournalService.IChangeJournalAccessor> .Invalid);
 }
Esempio n. 5
0
        private async Task ProcessWindowsCallHelper(
            string functionName,
            SandboxConfiguration config            = null,
            IEnumerable <string> extraDependencies = null,
            IEnumerable <string> extraOutputs      = null,
            int callCount                   = 1,
            string commandPrefix            = "",
            bool readsAndWritesDirectories  = false,
            bool untrackedOutputs           = false,
            string[] expectedWarningStrings = null,
            string[] expectedErrorStrings   = null)
        {
            if (config == null)
            {
                config = new SandboxConfiguration {
                    FileAccessIgnoreCodeCoverage = true, FailUnexpectedFileAccesses = true
                };
            }

            var context          = BuildXLContext.CreateInstanceForTesting();
            var pathTable        = context.PathTable;
            var fileContentTable = FileContentTable.CreateNew(LoggingContext);

            // have to force the config for truncation
            config.OutputReportingMode = OutputReportingMode.FullOutputOnWarningOrError;

            bool expectSuccess = expectedErrorStrings == null && expectedWarningStrings == null;

            using (var tempFiles = new TempFileStorage(canGetFileNames: true, rootPath: TemporaryDirectory))
            {
                string currentCodeFolder = Path.GetDirectoryName(AssemblyHelper.GetAssemblyLocation(Assembly.GetExecutingAssembly()));
                Contract.Assume(currentCodeFolder != null);

                string executable = Path.Combine(currentCodeFolder, DetourTestFolder, "DetoursTests.exe");

                string       workingDirectory             = tempFiles.GetUniqueDirectory();
                AbsolutePath workingDirectoryAbsolutePath = AbsolutePath.Create(pathTable, workingDirectory);

                XAssert.IsTrue(File.Exists(executable), "Could not find the test file: " + executable);
                FileArtifact executableFileArtifact = FileArtifact.CreateSourceFile(AbsolutePath.Create(pathTable, executable));

                var extraUntrackedScopes = new List <AbsolutePath>();

                var dependencies = new List <FileArtifact> {
                    executableFileArtifact
                };
                if (extraDependencies != null)
                {
                    foreach (string file in extraDependencies)
                    {
                        string       filePath = Path.Combine(workingDirectory, file);
                        AbsolutePath path     = AbsolutePath.Create(pathTable, filePath);

                        if (readsAndWritesDirectories)
                        {
                            Directory.CreateDirectory(filePath);

                            // We don't support directories as inputs in BuildXL yet.
                            extraUntrackedScopes.Add(path);
                        }
                        else
                        {
                            File.WriteAllText(filePath, "Definitely a file");
                            FileArtifact fileArtifact = FileArtifact.CreateSourceFile(path);
                            dependencies.Add(fileArtifact);
                        }
                    }
                }

                var outputs = new List <FileArtifactWithAttributes>();
                if (extraOutputs != null)
                {
                    foreach (string file in extraOutputs)
                    {
                        string       filePath = Path.Combine(workingDirectory, file);
                        AbsolutePath path     = AbsolutePath.Create(pathTable, filePath);

                        if (readsAndWritesDirectories)
                        {
                            // We don't support directory outputs in BuildXL at the moment, so e.g. deleting a directory needs to be untracked.
                            extraUntrackedScopes.Add(path);
                        }
                        else if (untrackedOutputs)
                        {
                            extraUntrackedScopes.Add(path);
                        }
                        else
                        {
                            FileArtifact fileArtifact = FileArtifact.CreateSourceFile(path).CreateNextWrittenVersion();
                            outputs.Add(fileArtifact.WithAttributes());
                        }
                    }
                }

                var tempDirectory        = tempFiles.GetUniqueDirectory();
                var environmentVariables = new List <EnvironmentVariable>();
                var environmentValue     = new PipDataBuilder(pathTable.StringTable);
                var tempPath             = AbsolutePath.Create(pathTable, tempDirectory);
                environmentValue.Add(tempPath);
                environmentVariables.Add(new EnvironmentVariable(StringId.Create(pathTable.StringTable, "TMP"), environmentValue.ToPipData(" ", PipDataFragmentEscaping.NoEscaping)));
                environmentVariables.Add(new EnvironmentVariable(StringId.Create(pathTable.StringTable, "TEMP"), environmentValue.ToPipData(" ", PipDataFragmentEscaping.NoEscaping)));

                var untrackedPaths  = CmdHelper.GetCmdDependencies(pathTable);
                var untrackedScopes = extraUntrackedScopes.Concat(CmdHelper.GetCmdDependencyScopes(pathTable).Concat(new[] { tempPath })).Distinct();

                var pip = new Process(
                    executableFileArtifact,
                    workingDirectoryAbsolutePath,
                    PipDataBuilder.CreatePipData(pathTable.StringTable, " ", PipDataFragmentEscaping.NoEscaping, commandPrefix + functionName + "Logging"),
                    FileArtifact.Invalid,
                    PipData.Invalid,
                    ReadOnlyArray <EnvironmentVariable> .From(environmentVariables),
                    FileArtifact.Invalid,
                    FileArtifact.Invalid,
                    FileArtifact.Invalid,
                    tempFiles.GetUniqueDirectory(pathTable),
                    null,
                    null,
                    ReadOnlyArray <FileArtifact> .From(dependencies),
                    ReadOnlyArray <FileArtifactWithAttributes> .From(outputs),
                    ReadOnlyArray <DirectoryArtifact> .Empty,
                    ReadOnlyArray <DirectoryArtifact> .Empty,
                    ReadOnlyArray <PipId> .Empty,
                    ReadOnlyArray <AbsolutePath> .From(untrackedPaths),
                    ReadOnlyArray <AbsolutePath> .From(untrackedScopes),
                    ReadOnlyArray <StringId> .Empty,
                    ReadOnlyArray <int> .Empty,
                    ReadOnlyArray <ProcessSemaphoreInfo> .Empty,
                    provenance: PipProvenance.CreateDummy(context),
                    toolDescription: StringId.Invalid,
                    additionalTempDirectories: ReadOnlyArray <AbsolutePath> .Empty);

                if (expectSuccess)
                {
                    await AssertProcessSucceedsAsync(
                        context,
                        config,
                        pip);
                }
                else
                {
                    await AssertProcessCompletesWithStatusAsync(
                        SandboxedProcessPipExecutionStatus.ExecutionFailed,
                        context,
                        config,
                        pip,
                        null);
                }
            }

            int expectedErrorCount   = 0;
            int expectedWarningCount = 0;
            IEnumerable <string> requiredLogMessageSubstrings = new string[] { };

            if (expectedErrorStrings != null)
            {
                expectedErrorCount           = expectedErrorStrings.Count();
                requiredLogMessageSubstrings = requiredLogMessageSubstrings.Concat(expectedErrorStrings);
            }

            if (expectedWarningStrings != null)
            {
                expectedWarningCount         = expectedWarningStrings.Count();
                requiredLogMessageSubstrings = requiredLogMessageSubstrings.Concat(expectedWarningStrings);
            }

            SetExpectedFailures(expectedErrorCount, expectedWarningCount, requiredLogMessageSubstrings.ToArray());
        }
Esempio n. 6
0
            public static ChangeTrackerSupport Initialize(FileContentTableWithTrackerTests test)
            {
                var loggingContext   = new LoggingContext("Dummy", "Dummy");
                var fileContentTable = FileContentTable.CreateNew();

                VolumeMap volumeMap = VolumeMap.TryCreateMapOfAllLocalVolumes(loggingContext);

                XAssert.IsNotNull(volumeMap);

                var journal = JournalAccessorGetter.TryGetJournalAccessor(loggingContext, volumeMap, AssemblyHelper.GetAssemblyLocation(Assembly.GetExecutingAssembly())).Value;

                XAssert.IsNotNull(journal);

                var fileChangeTracker = FileChangeTracker.StartTrackingChanges(loggingContext, volumeMap, journal, null);

                return(new ChangeTrackerSupport(
                           loggingContext,
                           test.m_pathTable,
                           fileChangeTracker,
                           fileContentTable,
                           volumeMap,
                           journal,
                           AbsolutePath.Create(test.m_pathTable, test.TemporaryDirectory),
                           null));
            }