/// <summary>
        ///  Ninja builds in CloudBuild are just a prototype and only work by carefully preparing the environment for the pips.
        ///  This method overrides the environment if we are in a cloudbuild build.
        /// </summary>
        private void PrepareEnvironment(
            IEnumerable <KeyValuePair <string, string> > userDefinedEnvironment,
            IEnumerable <string> userDefinedPassthroughs,
            out IEnumerable <KeyValuePair <string, string> > environment,
            out IEnumerable <string> passthroughs)
        {
            // Assume we are building in cloudbuild if the custom directory with the needed tools is
            var inCloudBuild = FileUtilities.Exists(m_manuallyDroppedDependenciesPath.ToString(m_context.PathTable));

            if (!inCloudBuild)
            {
                environment  = userDefinedEnvironment;
                passthroughs = userDefinedPassthroughs;
                return;
            }
            else
            {
                // Augment the environment with our own tools
                var augmentedEnvironment = SpecialCloudConfiguration.OverrideEnvironmentForCloud(userDefinedEnvironment, m_manuallyDroppedDependenciesPath, m_context);

                // Filter passthroughs
                environment  = augmentedEnvironment.Where(kvp => !isCloudBuildPassthrough(kvp.Key));
                passthroughs = userDefinedPassthroughs.Union(augmentedEnvironment.Select(kvp => kvp.Key).Where(k => isCloudBuildPassthrough(k)));

                bool isCloudBuildPassthrough(string envVar)
                {
                    return(SpecialEnvironmentVariables.PassThroughPrefixes.Any(prefix => envVar.StartsWith(prefix)) ||
                           m_frontEndHost.Configuration.Sandbox.GlobalUnsafePassthroughEnvironmentVariables.Contains(envVar));
                }
            }
        }
        // Should be called from a Lazy
        private IDictionary <string, string> GetAllEnvironmentVariables()
        {
            IDictionary <string, string> environment = FrontEndUtilities.GetEngineEnvironment(m_frontEndHost.Engine, m_frontEndName);

            // Check if we are (supposedly) in the cloud (if the special folder exists)
            if (!FileUtilities.Exists(m_manuallyDroppedDependenciesPath.Value.ToString(m_context.PathTable)))
            {
                return(environment);
            }
            else
            {
                return(SpecialCloudConfiguration.OverrideEnvironmentForCloud(environment, m_manuallyDroppedDependenciesPath.Value, m_context));
            }
        }
Beispiel #3
0
        private Task <SandboxedProcessResult> ExecuteCMakeRunner(AbsolutePath argumentsFile, IEnumerable <AbsolutePath> searchLocations)
        {
            AbsolutePath pathToTool = Configuration.Layout.BuildEngineDirectory.Combine(Context.PathTable, m_relativePathToCMakeRunner);
            string       rootString = ProjectRoot.ToString(Context.PathTable);

            AbsolutePath outputDirectory = argumentsFile.GetParent(Context.PathTable);

            FileUtilities.CreateDirectory(outputDirectory.ToString(Context.PathTable)); // Ensure it exists
            SerializeToolArguments(argumentsFile, searchLocations);

            void CleanUpOnResult()
            {
                try
                {
                    FileUtilities.DeleteFile(argumentsFile.ToString(Context.PathTable));
                }
                catch (BuildXLException e)
                {
                    Tracing.Logger.Log.CouldNotDeleteToolArgumentsFile(
                        Context.LoggingContext,
                        m_resolverSettings.Location(Context.PathTable),
                        argumentsFile.ToString(Context.PathTable),
                        e.Message);
                }
            }

            var environment = FrontEndUtilities.GetEngineEnvironment(Engine, m_frontEnd.Name);

            // TODO: This manual configuration is temporary. Remove after the cloud builders have the correct configuration
            var pathToManuallyDroppedTools = Configuration.Layout.BuildEngineDirectory.Combine(Context.PathTable, RelativePath.Create(Context.StringTable, @"tools\CmakeNinjaPipEnvironment"));

            if (FileUtilities.Exists(pathToManuallyDroppedTools.ToString(Context.PathTable)))
            {
                environment = SpecialCloudConfiguration.OverrideEnvironmentForCloud(environment, pathToManuallyDroppedTools, Context);
            }

            var buildParameters = BuildParameters.GetFactory().PopulateFromDictionary(new ReadOnlyDictionary <string, string>(environment));

            return(FrontEndUtilities.RunSandboxedToolAsync(
                       Context,
                       pathToTool.ToString(Context.PathTable),
                       buildStorageDirectory: outputDirectory.ToString(Context.PathTable),
                       fileAccessManifest: GenerateFileAccessManifest(pathToTool.GetParent(Context.PathTable)),
                       arguments: I($@"""{argumentsFile.ToString(Context.PathTable)}"""),
                       workingDirectory: rootString,
                       description: "CMakeRunner",
                       buildParameters,
                       onResult: CleanUpOnResult));
        }