コード例 #1
0
        private static void RegisterRedirectedMount(
            BuildXLContext context,
            IReadOnlyDictionary <string, string> properties,
            MountsTable table,
            string mountName,
            string envVariable        = null,
            bool allowCreateDirectory = false)
        {
            envVariable = envVariable ?? mountName.ToCanonicalizedEnvVar();

            if (!properties.TryGetValue(envVariable, out string redirectedPath))
            {
                Contract.Assert(false, $"Failed to register a redirected mount ('{mountName}') using a path defined by '{envVariable}' environment variable. The variable was not specified.");
            }

            table.AddStaticSystemMount(mountName, redirectedPath, allowCreateDirectory);

            // We don't need to add the real path of redirected mount into alternative roots.
            // Internally inside BuildXL itself, all accesses to user-related paths should go through the redirected paths by querying the mount table,
            // e.g. in DScript, one should use Context.getMount(...) to get user-related paths.
            // For any executed tool, if the tool accesses a user-related path, then the directory translation will translate that path into the redirected one.
            // We also don't want to add the real paths to the mount table because those paths will also go to the path expander that is part of the cached graph.
            // If the graph is used across builds, then the real user-related paths are not guaranteed to be the same.
        }
コード例 #2
0
        public static MountsTable CreateAndRegister(
            LoggingContext loggingContext,
            BuildXLContext context,
            IConfiguration configuration,
            [CanBeNull] IReadOnlyDictionary <string, string> properties)
        {
            Contract.Requires(context != null);
            Contract.Requires(configuration != null);
            Contract.Requires(loggingContext != null);

            ILayoutConfiguration layout = configuration.Layout;
            IReadOnlyList <IResolverSettings> resolverSettings = configuration.Resolvers;

            var table = new MountsTable(loggingContext, context);

            // If any resolver settings allows for a writable source directory, then the source directory is writable
            var writableSourceRoot = resolverSettings.Any(resolverSetting => resolverSetting.AllowWritableSourceDirectory);

            table.AddStaticMount("BuildEnginePath", layout.BuildEngineDirectory, isWriteable: false);
            table.AddStaticMount("SourceRoot", layout.SourceDirectory, isWriteable: writableSourceRoot);
            table.AddStaticMount("ObjectRoot", layout.ObjectDirectory, isWriteable: true, isScrubbable: true);
            table.AddStaticMount(
                "LogsDirectory",
                configuration.Logging.RedirectedLogsDirectory.IsValid
                ? configuration.Logging.RedirectedLogsDirectory
                : configuration.Logging.LogsDirectory,
                isWriteable: true,
                allowCreateDirectory: true);

            if (layout.FrontEndDirectory.IsValid)
            {
                // This location is used only for storing nuget packages and generated specs so far.
                table.AddStaticMount("FrontEnd", layout.FrontEndDirectory, isWriteable: true, isScrubbable: false);
            }
            if (layout.TempDirectory.IsValid)
            {
                table.AddStaticMount("TempRoot", layout.TempDirectory, isWriteable: true, isScrubbable: true);
            }

            // Cross Plat supported MountPoints
            table.AddStaticSystemMount("ProgramData", Environment.SpecialFolder.CommonApplicationData);
            table.AddStaticSystemMount("ProgramFiles", Environment.SpecialFolder.ProgramFiles, trackSourceFileChanges: true);
            table.AddStaticSystemMount("System", Environment.SpecialFolder.System);
            if (!layout.RedirectedUserProfileJunctionRoot.IsValid)
            {
                table.AddStaticSystemMount("UserProfile", Environment.SpecialFolder.UserProfile);
                table.AddStaticSystemMount("AppData", Environment.SpecialFolder.ApplicationData, allowCreateDirectory: true);
                table.AddStaticSystemMount("LocalAppData", Environment.SpecialFolder.LocalApplicationData, allowCreateDirectory: true);
            }
            else
            {
                // User profile is redirected; need to use the paths specified in the env block.
                Contract.Assert(properties != null);
                RegisterRedirectedMount(context, properties, table, "UserProfile");
                RegisterRedirectedMount(context, properties, table, "AppData", allowCreateDirectory: true);
                RegisterRedirectedMount(context, properties, table, "LocalAppData", allowCreateDirectory: true);
            }

            if (!OperatingSystemHelper.IsUnixOS)
            {
                // Add system mounts that are Windows Only
                table.AddStaticSystemMount("Windows", Environment.SpecialFolder.Windows);
                table.AddStaticSystemMount("ProgramFilesX86", Environment.SpecialFolder.ProgramFilesX86, trackSourceFileChanges: true);
                table.AddStaticSystemMount("CommonProgramFiles", Environment.SpecialFolder.CommonProgramFiles, trackSourceFileChanges: true);
                table.AddStaticSystemMount("CommonProgramFilesX86", Environment.SpecialFolder.CommonProgramFilesX86, trackSourceFileChanges: true);

                if (!layout.RedirectedUserProfileJunctionRoot.IsValid)
                {
                    table.AddStaticSystemMount("InternetCache", Environment.SpecialFolder.InternetCache);
                    table.AddStaticSystemMount("InternetHistory", Environment.SpecialFolder.History);
                    table.AddStaticSystemMount("INetCookies", Environment.SpecialFolder.Cookies, allowCreateDirectory: true);
                    table.AddStaticSystemMount("LocalLow", FileUtilities.KnownFolderLocalLow);
                }
                else
                {
                    // User profile is redirected; need to use the paths specified in the env block.
                    Contract.Assert(properties != null);
                    RegisterRedirectedMount(context, properties, table, "InternetCache");
                    RegisterRedirectedMount(context, properties, table, "InternetHistory");
                    RegisterRedirectedMount(context, properties, table, "INetCookies", allowCreateDirectory: true);
                    RegisterRedirectedMount(context, properties, table, "LocalLow");
                }
            }
            else
            {
                table.AddStaticSystemMount("Applications", MacPaths.Applications, trackSourceFileChanges: true);
                table.AddStaticSystemMount("Bin", MacPaths.Bin, trackSourceFileChanges: true);
                table.AddStaticSystemMount("UsrBin", MacPaths.UsrBin, trackSourceFileChanges: true);
                table.AddStaticSystemMount("UsrInclude", MacPaths.UsrInclude, trackSourceFileChanges: true);
                table.AddStaticSystemMount("UsrLib", MacPaths.UsrLib, trackSourceFileChanges: true);
                table.AddStaticSystemMount("Library", MacPaths.Library, trackSourceFileChanges: true);
                table.AddStaticSystemMount("UserProvisioning", MacPaths.UserProvisioning, trackSourceFileChanges: true);
            }

            return(table);
        }