Exemplo n.º 1
0
        private async Task <Possible <ProjectGraphResult> > TryComputeBuildGraphAsync(IEnumerable <AbsolutePath> msBuildSearchLocations, IEnumerable <AbsolutePath> dotnetSearchLocations, IEnumerable <AbsolutePath> parsingEntryPoints, BuildParameters.IBuildParameters buildParameters)
        {
            // We create a unique output file on the obj folder associated with the current front end, and using a GUID as the file name
            AbsolutePath outputDirectory = m_host.GetFolderForFrontEnd(MsBuildFrontEnd.Name);
            AbsolutePath outputFile      = outputDirectory.Combine(m_context.PathTable, Guid.NewGuid().ToString());
            // We create a unique response file that will contain the tool arguments
            AbsolutePath responseFile = outputDirectory.Combine(m_context.PathTable, Guid.NewGuid().ToString());

            // Make sure the directories are there
            FileUtilities.CreateDirectory(outputDirectory.ToString(m_context.PathTable));

            Possible <ProjectGraphWithPredictionsResult <AbsolutePath> > maybeProjectGraphResult = await ComputeBuildGraphAsync(responseFile, parsingEntryPoints, outputFile, msBuildSearchLocations, dotnetSearchLocations, buildParameters);

            if (!maybeProjectGraphResult.Succeeded)
            {
                // A more specific error has been logged already
                return(maybeProjectGraphResult.Failure);
            }

            var projectGraphResult = maybeProjectGraphResult.Result;

            if (m_resolverSettings.KeepProjectGraphFile != true)
            {
                DeleteGraphBuilderRelatedFiles(outputFile, responseFile);
            }
            else
            {
                // Graph-related files are requested to be left on disk. Let's print a message with their location.
                Tracing.Logger.Log.GraphBuilderFilesAreNotRemoved(m_context.LoggingContext, outputFile.ToString(m_context.PathTable), responseFile.ToString(m_context.PathTable));
            }

            if (!projectGraphResult.Succeeded)
            {
                var failure = projectGraphResult.Failure;
                Tracing.Logger.Log.ProjectGraphConstructionError(m_context.LoggingContext, failure.HasLocation ? failure.Location : m_resolverSettings.Location(m_context.PathTable), failure.Message);

                return(new MsBuildGraphConstructionFailure(m_resolverSettings, m_context.PathTable));
            }

            ProjectGraphWithPredictions <AbsolutePath> projectGraph = projectGraphResult.Result;

            // The module contains all project files that are part of the graph
            var projectFiles = new HashSet <AbsolutePath>();

            foreach (ProjectWithPredictions <AbsolutePath> node in projectGraph.ProjectNodes)
            {
                projectFiles.Add(node.FullPath);
            }

            var moduleDescriptor = ModuleDescriptor.CreateWithUniqueId(m_context.StringTable, m_resolverSettings.ModuleName, this);
            var moduleDefinition = ModuleDefinition.CreateModuleDefinitionWithImplicitReferences(
                moduleDescriptor,
                m_resolverSettings.RootTraversal,
                m_resolverSettings.File,
                projectFiles,
                allowedModuleDependencies: null, // no module policies
                cyclicalFriendModules: null);    // no whitelist of cycles

            return(new ProjectGraphResult(projectGraph, moduleDefinition, projectGraphResult.PathToMsBuild, projectGraphResult.PathToDotNetExe));
        }
Exemplo n.º 2
0
        public ModuleDefinition GetModuleDefinitionFromContent(
            ModuleDescriptor moduleDescriptor,
            ModuleRepository moduleRepository)
        {
            if (m_nameResolutionSemantics == NameResolutionSemantics.ImplicitProjectReferences && moduleDescriptor.Name != PreludeName)
            {
                var moduleConfigurationPath = moduleRepository.RootDir.Combine(moduleRepository.PathTable, Names.ModuleConfigBm);

                return(ModuleDefinition.CreateModuleDefinitionWithImplicitReferences(
                           moduleDescriptor,
                           moduleRepository.RootDir,
                           moduleConfigurationPath,
                           moduleRepository.GetAllPathsForModule(moduleDescriptor),
                           allowedModuleDependencies: null,
                           cyclicalFriendModules: moduleRepository.GetAllModules().Select(
                               descriptor => ModuleReferenceWithProvenance.FromNameAndPath(descriptor.Name, moduleConfigurationPath.ToString(PathTable))),
                           mounts: null));
            }

            return(ModuleDefinition.CreateModuleDefinitionWithExplicitReferencesWithEmptyQualifierSpace(
                       moduleDescriptor,
                       moduleRepository.RootDir.Combine(moduleRepository.PathTable, "FakeMainFile.dsc"),
                       moduleRepository.RootDir.Combine(moduleRepository.PathTable, Names.ModuleConfigBm),
                       moduleRepository.GetAllPathsForModule(moduleDescriptor),
                       PathTable));
        }
Exemplo n.º 3
0
        private static ParsedModule CreateModuleFor(RuntimeModelContext context, ISourceFile sourceFile)
        {
            const string ModuleName = "ModuleWith1File";
            var          specPath   = sourceFile.GetAbsolutePath(context.PathTable);

            var moduleRootDirectory = specPath.GetParent(context.PathTable);
            var moduleDefinition    = ModuleDefinition.CreateModuleDefinitionWithImplicitReferences(
                new ModuleDescriptor(
                    id: ModuleId.Create(context.StringTable, ModuleName),
                    name: ModuleName,
                    displayName: ModuleName,
                    version: "1.0.0",
                    resolverKind: KnownResolverKind.SourceResolverKind,
                    resolverName: "DScriptExpression"),
                moduleRootDirectory: moduleRootDirectory,
                moduleConfigFile: moduleRootDirectory.Combine(context.PathTable, "package.config.dsc"),
                specs: new [] { specPath },
                allowedModuleDependencies: null,
                cyclicalFriendModules: null
                );

            return(new ParsedModule(moduleDefinition, new Dictionary <AbsolutePath, ISourceFile>()
            {
                [specPath] = sourceFile
            }));
        }
        internal void UpdateDataForDownloadData(DownloadData downloadData, int resolverSettingsIndex, FrontEndContext context = null)
        {
            context = context ?? m_context;
            Contract.Assert(context != null);

            var name = downloadData.Settings.ModuleName;

            var moduleId   = ModuleId.Create(context.StringTable, name);
            var descriptor = new ModuleDescriptor(moduleId, name, name, string.Empty, Kind, Name);

            var definition = ModuleDefinition.CreateModuleDefinitionWithImplicitReferences(
                descriptor,
                downloadData.ModuleRoot,
                downloadData.ModuleConfigFile,
                new[] { downloadData.ModuleSpecFile },
                allowedModuleDependencies: null,
                cyclicalFriendModules: null,
                mounts: new Mount[] {
                new Mount {
                    Name = PathAtom.Create(m_context.StringTable, $"Download#{resolverSettingsIndex}"),
                    Path = downloadData.ModuleRoot,
                    TrackSourceFileChanges = true,
                    IsWritable             = true,
                    IsReadable             = true,
                    IsScrubbable           = true
                }
            });     // A Download package does not have any module dependency restrictions nor allowlist cycles

            m_descriptors.Add(descriptor);
            m_descriptorsByName.Add(name, descriptor);
            m_descriptorsBySpecPath.Add(downloadData.ModuleSpecFile, descriptor);
            m_definitions.Add(descriptor, definition);
        }
Exemplo n.º 5
0
        private async Task <Possible <RushGraphResult> > TryComputeBuildGraphAsync(BuildParameters.IBuildParameters buildParameters)
        {
            // We create a unique output file on the obj folder associated with the current front end, and using a GUID as the file name
            AbsolutePath outputDirectory = m_host.GetFolderForFrontEnd(Name);
            AbsolutePath outputFile      = outputDirectory.Combine(m_context.PathTable, Guid.NewGuid().ToString());

            // Make sure the directories are there
            FileUtilities.CreateDirectory(outputDirectory.ToString(m_context.PathTable));

            Possible <RushGraph> maybeRushGraph = await ComputeBuildGraphAsync(outputFile, buildParameters);

            if (!maybeRushGraph.Succeeded)
            {
                // A more specific error has been logged already
                return(maybeRushGraph.Failure);
            }

            var rushGraph = maybeRushGraph.Result;

            if (m_resolverSettings.KeepProjectGraphFile != true)
            {
                DeleteGraphBuilderRelatedFiles(outputFile);
            }
            else
            {
                // Graph-related files are requested to be left on disk. Let's print a message with their location.
                Tracing.Logger.Log.GraphBuilderFilesAreNotRemoved(m_context.LoggingContext, outputFile.ToString(m_context.PathTable));
            }

            // The module contains all project files that are part of the graph
            var projectFiles = new HashSet <AbsolutePath>();

            foreach (RushProject project in rushGraph.Projects)
            {
                projectFiles.Add(project.ProjectPath(m_context.PathTable));
            }

            var moduleDescriptor = ModuleDescriptor.CreateWithUniqueId(m_context.StringTable, m_resolverSettings.ModuleName, this);
            var moduleDefinition = ModuleDefinition.CreateModuleDefinitionWithImplicitReferences(
                moduleDescriptor,
                m_resolverSettings.Root,
                m_resolverSettings.File,
                projectFiles,
                allowedModuleDependencies: null, // no module policies
                cyclicalFriendModules: null);    // no whitelist of cycles

            return(new RushGraphResult(rushGraph, moduleDefinition));
        }
Exemplo n.º 6
0
        /// <nodoc/>
        public PipSchedulingTestBase(ITestOutputHelper output, bool usePassThroughFileSystem = false) : base(output, usePassThroughFileSystem)
        {
            TestPath = AbsolutePath.Create(PathTable, TestRoot);

            m_testModule = ModuleDefinition.CreateModuleDefinitionWithImplicitReferences(
                ModuleDescriptor.CreateForTesting("Test"),
                TestPath,
                TestPath.Combine(PathTable, "module.config.bm"),
                new[] { TestPath.Combine(PathTable, "spec.dsc") },
                allowedModuleDependencies: null,
                cyclicalFriendModules: null);

            m_configFilePath = TestPath.Combine(PathTable, "config.dsc");

            PopulateMainConfigAndPrelude();
        }
Exemplo n.º 7
0
        internal void UpdateDataForDownloadData(DownloadData downloadData)
        {
            var name = downloadData.Settings.ModuleName;

            var moduleId   = new ModuleId(ModuleIdProvider.GetNextId().Value, name);
            var descriptor = new ModuleDescriptor(moduleId, name, name, string.Empty, Kind, Name);

            var definition = ModuleDefinition.CreateModuleDefinitionWithImplicitReferences(
                descriptor,
                downloadData.ModuleRoot,
                downloadData.ModuleConfigFile,
                new[] { downloadData.ModuleSpecFile },
                allowedModuleDependencies: null,
                cyclicalFriendModules: null); // A Download package does not have any module dependency restrictions nor whitelists cycles

            m_descriptors.Add(descriptor);
            m_descriptorsByName.Add(name, descriptor);
            m_descriptorsBySpecPath.Add(downloadData.ModuleSpecFile, descriptor);
            m_definitions.Add(descriptor, definition);
        }
Exemplo n.º 8
0
        private async Task <Possible <NinjaGraphWithModuleDefinition> > TryComputeBuildGraphAsync()
        {
            Possible <NinjaGraphResult> maybeGraph = await ComputeBuildGraphAsync();

            var result         = maybeGraph.Result;
            var specFileConfig = SpecFile.ChangeExtension(m_context.PathTable, PathAtom.Create(m_context.StringTable, ".ninja.dsc")); // It needs to be a .dsc for the parsing to work

            var moduleDescriptor = ModuleDescriptor.CreateWithUniqueId(m_context.StringTable, m_resolverSettings.ModuleName, this);
            var moduleDefinition = ModuleDefinition.CreateModuleDefinitionWithImplicitReferences(
                moduleDescriptor,
                ProjectRoot,
                m_resolverSettings.File,
                new List <AbsolutePath>()
            {
                specFileConfig
            },
                allowedModuleDependencies: null, // no module policies
                cyclicalFriendModules: null);    // no whitelist of cycles

            return(new NinjaGraphWithModuleDefinition(result.Graph, moduleDefinition));
        }
Exemplo n.º 9
0
        internal void UpdateDataForDownloadData(DownloadData downloadData, FrontEndContext context = null)
        {
            context = context ?? m_context;
            Contract.Assert(context != null);

            var name = downloadData.Settings.ModuleName;

            var moduleId   = ModuleId.Create(context.StringTable, name);
            var descriptor = new ModuleDescriptor(moduleId, name, name, string.Empty, Kind, Name);

            var definition = ModuleDefinition.CreateModuleDefinitionWithImplicitReferences(
                descriptor,
                downloadData.ModuleRoot,
                downloadData.ModuleConfigFile,
                new[] { downloadData.ModuleSpecFile },
                allowedModuleDependencies: null,
                cyclicalFriendModules: null); // A Download package does not have any module dependency restrictions nor whitelists cycles

            m_descriptors.Add(descriptor);
            m_descriptorsByName.Add(name, descriptor);
            m_descriptorsBySpecPath.Add(downloadData.ModuleSpecFile, descriptor);
            m_definitions.Add(descriptor, definition);
        }