Ejemplo n.º 1
0
        private async Task <Possible <Unit> > GenerateBuildDirectoryAsync()
        {
            Contract.Assert(m_buildDirectory.IsValid);
            AbsolutePath outputDirectory = m_host.GetFolderForFrontEnd(Name);
            AbsolutePath argumentsFile   = outputDirectory.Combine(m_context.PathTable, Guid.NewGuid().ToString());

            if (!TryRetrieveCMakeSearchLocations(out IEnumerable <AbsolutePath> searchLocations))
            {
                return(new CMakeGenerationError(m_resolverSettings.ModuleName, m_buildDirectory.ToString(m_context.PathTable)));
            }

            SandboxedProcessResult result = await ExecuteCMakeRunner(argumentsFile, searchLocations);

            string standardError = result.StandardError.CreateReader().ReadToEndAsync().GetAwaiter().GetResult();

            if (result.ExitCode != 0)
            {
                if (!m_context.CancellationToken.IsCancellationRequested)
                {
                    Tracing.Logger.Log.CMakeRunnerInternalError(
                        m_context.LoggingContext,
                        m_resolverSettings.Location(m_context.PathTable),
                        standardError);
                }

                return(new CMakeGenerationError(m_resolverSettings.ModuleName, m_buildDirectory.ToString(m_context.PathTable)));
            }

            FrontEndUtilities.TrackToolFileAccesses(m_host.Engine, m_context, Name, result.AllUnexpectedFileAccesses, outputDirectory);
            return(Possible.Create(Unit.Void));
        }
Ejemplo n.º 2
0
        private async Task <Possible <ProjectGraphResult> > TryComputeBuildGraphAsync(IEnumerable <AbsolutePath> searchLocations, 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 = FrontEndHost.GetFolderForFrontEnd(MsBuildFrontEnd.Name);
            AbsolutePath outputFile      = outputDirectory.Combine(Context.PathTable, Guid.NewGuid().ToString());
            // We create a unique response file that will contain the tool arguments
            AbsolutePath responseFile = outputDirectory.Combine(Context.PathTable, Guid.NewGuid().ToString());

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

            Possible <ProjectGraphWithPredictionsResult <AbsolutePath> > maybeProjectGraphResult = await ComputeBuildGraphAsync(responseFile, parsingEntryPoints, outputFile, searchLocations, 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(Context.LoggingContext, outputFile.ToString(Context.PathTable), responseFile.ToString(Context.PathTable));
            }

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

                return(new MsBuildGraphConstructionFailure(m_resolverSettings, 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_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.PathToMsBuildExe));
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public bool TryInitialize([NotNull] FrontEndHost host, [NotNull] FrontEndContext context, [NotNull] IConfiguration configuration, [NotNull] IResolverSettings resolverSettings)
        {
            Contract.Requires(context != null);
            Contract.Requires(host != null);
            Contract.Requires(configuration != null);
            Contract.Requires(resolverSettings != null);

            var settings = resolverSettings as IDownloadResolverSettings;

            Contract.Assert(settings != null);

            m_context = context;
            Name      = resolverSettings.Name;

            var resolverFolder = host.GetFolderForFrontEnd(resolverSettings.Name ?? Kind);

            var downloads = new Dictionary <string, DownloadData>(StringComparer.Ordinal);

            foreach (var downloadSettings in settings.Downloads)
            {
                if (!ValidateAndExtractDownloadData(context, downloadSettings, downloads, resolverFolder, out var downloadData))
                {
                    return(false);
                }

                downloads.Add(downloadSettings.ModuleName, downloadData);
                UpdateDataForDownloadData(downloadData);
            }

            Downloads = downloads;

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get the output path for the JSON graph associated with this resolver
        /// </summary>
        private AbsolutePath GetToolOutputPath()
        {
            AbsolutePath outputDirectory = FrontEndHost.GetFolderForFrontEnd(NinjaFrontEnd.Name);
            var          now             = DateTime.UtcNow.ToString("yyyy-MM-dd-THH-mm-ss.SSS-Z");
            var          uniqueName      = $"ninja_graph_{now}.json";

            return(outputDirectory.Combine(Context.PathTable, uniqueName));
        }