Beispiel #1
0
        private bool ValidateMount(IMount mount, LocationData location)
        {
            // Mount can be invalid if it is not specified properly in the DScript configuration.
            // For example, one can specify 'undefined' for mount's name or path. The undefined value gets
            // translated into invalid value by ConfigurationConverter.
            if (!mount.Name.IsValid)
            {
                Events.LogWithProvenance(
                    m_loggingContext,
                    Logger.Log.MountHasInvalidName,
                    m_context.PathTable,
                    location);
                return(false);
            }

            if (!mount.Path.IsValid)
            {
                Events.LogWithProvenance(
                    m_loggingContext,
                    Logger.Log.MountHasInvalidPath,
                    m_context.PathTable,
                    location,
                    mount.Name.ToString(m_context.StringTable));
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        private void LogRelatedMountError(RelatedMountLogEventError logEvent, IMount childMount, IMount parentMount)
        {
            logEvent(
                m_loggingContext,
                childMount.Location.Path.ToString(m_context.PathTable),
                childMount.Location.Line,
                childMount.Location.Position,
                childMount.Name.ToString(m_context.StringTable),
                childMount.Path.ToString(m_context.PathTable),
                parentMount.Name.ToString(m_context.StringTable),
                parentMount.Path.ToString(m_context.PathTable));

            Events.LogRelatedLocation(
                m_loggingContext,
                Logger.Log.ErrorRelatedLocation,
                m_context.PathTable,
                parentMount.Location,
                childMount.Location);
        }
Beispiel #3
0
        /// <summary>
        /// Adds a resolved mount as found by parsing the configuration file.
        /// </summary>
        public void AddResolvedMount(IMount mount, LocationData?mountLocation = null)
        {
            var location = mountLocation ?? mount.Location;

            if (!ValidateMount(mount, location))
            {
                m_mountAdditionError = true;
                return;
            }

            if (!VerifyMountAgainstParentMounts(mount))
            {
                m_mountAdditionError = true;
                return;
            }

            if (m_mountPathIdentifiersByMount.TryAdd(mount, mount.Name))
            {
                string mountName = mount.Name.ToString(m_context.StringTable);
                m_mountsByName[mountName]     = mount;
                m_mountMapBuilder[mount.Path] = mount;
            }
        }
Beispiel #4
0
        /// <inheritdoc />
        public override BuildXL.FrontEnd.Sdk.TryGetMountResult TryGetMount(string name, ModuleId currentPackage, out IMount mount)
        {
            Contract.Requires(currentPackage.IsValid);

            if (string.IsNullOrEmpty(name))
            {
                mount = null;
                return(BuildXL.FrontEnd.Sdk.TryGetMountResult.NameNullOrEmpty);
            }

            return(m_mountsByName.TryGetValue(name, out mount)
                ? BuildXL.FrontEnd.Sdk.TryGetMountResult.Success
                : BuildXL.FrontEnd.Sdk.TryGetMountResult.NameNotFound);
        }
Beispiel #5
0
        private bool VerifyMountAgainstParentMounts(IMount childMount)
        {
            if (m_parent == null)
            {
                return(true);
            }

            string mountName = childMount.Name.ToString(m_context.StringTable);
            IMount parentMount;

            if (m_parent.m_mountsByName.TryGetValue(mountName, out parentMount))
            {
                if (parentMount.Path != childMount.Path)
                {
                    LogRelatedMountError(
                        Logger.Log.ModuleMountsWithSameNameAsConfigMountsMustHaveSamePath,
                        childMount: childMount,
                        parentMount: parentMount);
                    return(false);
                }
            }

            if (m_parent.m_mountMapBuilder.TryGetValue(childMount.Path, out parentMount))
            {
                if (!parentMount.Name.CaseInsensitiveEquals(m_context.StringTable, childMount.Name))
                {
                    LogRelatedMountError(
                        Logger.Log.ModuleMountsWithSamePathAsConfigMountsMustHaveSameName,
                        childMount: childMount,
                        parentMount: parentMount);
                    return(false);
                }
            }

            var parentMountInfo = m_parent.MountPathExpander.GetSemanticPathInfo(childMount.Path);

            if (parentMountInfo.IsValid)
            {
                parentMount = m_parent.m_mountMapBuilder[parentMountInfo.Root];
                if (!parentMountInfo.IsWritable && childMount.IsWritable)
                {
                    LogRelatedMountError(
                        Logger.Log.NonWritableConfigMountsMayNotContainWritableModuleMounts,
                        childMount: childMount,
                        parentMount: parentMount);
                    return(false);
                }

                if (!parentMountInfo.IsReadable && childMount.IsReadable)
                {
                    LogRelatedMountError(
                        Logger.Log.NonReadableConfigMountsMayNotContainReadableModuleMounts,
                        childMount: childMount,
                        parentMount: parentMount);
                    return(false);
                }

                if (parentMountInfo.IsScrubbable && !childMount.IsScrubbable)
                {
                    LogRelatedMountError(
                        Logger.Log.ScrubbableMountsMayOnlyContainScrubbableMounts,
                        childMount: childMount,
                        parentMount: parentMount);
                    return(false);
                }
            }

            return(true);
        }