/// <summary>
        /// Builds and filters the worksapce.
        /// </summary>
        /// <remarks>
        /// This method not just builds the workspace from scratch, but it also tries to compute it in an efficient way.
        /// If there is a front end snapshot from the previous BuildXL run and the engine gives us a set of changed files,
        /// then we can build a filtered workspace based on the old spec-2-spec map without parsing the entire world.
        /// </remarks>
        private async Task <Workspace> BuildAndFilterWorkspaceAsync(IWorkspaceProvider workspaceProvider, FrontEndEngineAbstraction engineAbstraction, EvaluationFilter evaluationFilter)
        {
            // this step downloads nugets too, and that's why we want to do it outside of the progress reporting block below
            Possible <WorkspaceDefinition> workspaceDefinition = await TryGetWorkspaceDefinitionAsync(workspaceProvider);

            if (!workspaceDefinition.Succeeded)
            {
                // In some cases even if the workspace failed to build some of the pipeline still tries to continue
                // Complete mount initialization to enable mount related queries downstream
                Engine.CompleteMountInitialization();
                return(Workspace.Failure(workspaceProvider, workspaceProvider.Configuration, workspaceDefinition.Failure));
            }

            // As soon as we get the workspace definition, we can configure the mount table with the additional mounts modules may have defined and seal it
            foreach (var module in workspaceDefinition.Result.Modules.Where(module => module.Mounts != null))
            {
                foreach (var mount in module.Mounts)
                {
                    Engine.AddResolvedModuleDefinedMount(mount, LocationData.Create(module.ModuleConfigFile));
                }
            }

            // At this point the mount table can be completed
            if (!Engine.CompleteMountInitialization())
            {
                return(Workspace.Failure(workspaceProvider, workspaceProvider.Configuration, new GenericWorkspaceFailure("Mount points not properly defined. Detailed errors should have been logged.")));
            }

            return(await WithWorkspaceProgressReportingAsync(
                       numSpecs : workspaceDefinition.Result.SpecCount,
                       task : BuildAndFilterWorkspaceAsync(workspaceDefinition.Result, workspaceProvider, engineAbstraction, evaluationFilter)));
        }
示例#2
0
        /// <summary>
        /// Tries coercing qualifier.
        /// </summary>
        public bool TryCoerce(
            QualifierSpaceId targetQualifierSpaceId,
            QualifierTable qualifierTable,
            QualifierValueCache cache,
            PathTable pathTable,
            StringTable stringTable,
            LoggingContext loggingContext,
            out QualifierValue qualifierValue,
            LineInfo location,
            bool useDefaultsForCoercion,
            AbsolutePath path)
        {
            Contract.Requires(targetQualifierSpaceId.IsValid);
            Contract.Requires(qualifierTable != null);
            Contract.Requires(qualifierTable.IsValidQualifierSpaceId(targetQualifierSpaceId));
            Contract.Requires(pathTable != null);
            Contract.Requires(stringTable != null);
            Contract.Requires(loggingContext != null);
#if DEBUG
            Contract.Ensures(Contract.ValueAtReturn(out qualifierValue) == null || Contract.Result <bool>() == true, "expected 'qualifierValue' to be set to null when return value is 'false'");
            Contract.Ensures(Contract.ValueAtReturn(out qualifierValue) != null || Contract.Result <bool>() == false, "expected 'qualifierValue' to be set to non-null when return value is 'true'");
#endif
            qualifierValue = null;

            if (targetQualifierSpaceId == qualifierTable.EmptyQualifierSpaceId)
            {
                qualifierValue = CreateEmpty(qualifierTable);
                return(true);
            }

            if (qualifierTable.TryCreateQualifierForQualifierSpace(
                    pathTable,
                    loggingContext,
                    QualifierId,
                    targetQualifierSpaceId,
                    useDefaultsForCoercion,
                    out QualifierId resultingQualifierId,
                    out UnsupportedQualifierValue error))
            {
                qualifierValue = Create(resultingQualifierId, cache, qualifierTable, stringTable);
                return(true);
            }

            var errorLocation = LocationData.Create(path, location.Line, location.Position);
            error.Location = errorLocation.ToLogLocation(pathTable);

            Logger.Log.ErrorUnsupportedQualifierValue(
                loggingContext,
                error.Location,
                error.QualifierKey,
                error.InvalidValue,
                error.LegalValues);

            return(false);
        }
示例#3
0
        /// <summary>
        /// Tries coercing qualifier.
        /// </summary>
        public bool TryCoerce(
            QualifierSpaceId targetQualifierSpaceId,
            QualifierTable qualifierTable,
            QualifierValueCache cache,
            PathTable pathTable,
            StringTable stringTable,
            LoggingContext loggingContext,
            out QualifierValue qualifierValue,
            LineInfo location,
            bool useDefaultsForCoercion,
            AbsolutePath path)
        {
            Contract.Requires(targetQualifierSpaceId.IsValid);
            Contract.Requires(qualifierTable != null);
            Contract.Requires(qualifierTable.IsValidQualifierSpaceId(targetQualifierSpaceId));
            Contract.Requires(pathTable != null);
            Contract.Requires(stringTable != null);
            Contract.Requires(loggingContext != null);

            qualifierValue = null;

            if (targetQualifierSpaceId == qualifierTable.EmptyQualifierSpaceId)
            {
                qualifierValue = CreateEmpty(qualifierTable);
                return(true);
            }

            if (qualifierTable.TryCreateQualifierForQualifierSpace(
                    pathTable,
                    loggingContext,
                    QualifierId,
                    targetQualifierSpaceId,
                    useDefaultsForCoercion,
                    out QualifierId resultingQualifierId,
                    out UnsupportedQualifierValue error))
            {
                qualifierValue = Create(resultingQualifierId, cache, qualifierTable, stringTable);
                return(true);
            }

            var errorLocation = LocationData.Create(path, location.Line, location.Position);

            error.Location = errorLocation.ToLogLocation(pathTable);

            Logger.Log.ErrorUnsupportedQualifierValue(
                loggingContext,
                error.Location,
                error.QualifierKey,
                error.InvalidValue,
                error.LegalValues);

            return(false);
        }
示例#4
0
        private void TestTryCoerceScopeToSpace(
            Func <QualifierTable, QualifierId> getQualifier,
            Dictionary <string, string[]> space,
            string expectedQualifier,
            bool expectedSuccess       = true,
            bool useDefaultsOnCoercion = true)
        {
            var context = FrontEndContext.CreateInstanceForTesting();
            var table   = new QualifierTable(context.StringTable);

            var testQualifier = getQualifier(table);
            var testSpace     = table.CreateQualifierSpace(space.Select(kvp => new Tuple <string, string[]>(kvp.Key, kvp.Value)).ToArray());

            QualifierId q;
            UnsupportedQualifierValue error;
            var result = table.TryCreateQualifierForQualifierSpace(
                context.PathTable,
                context.LoggingContext,
                testQualifier,
                testSpace,
                useDefaultsForCoercion: useDefaultsOnCoercion,
                resultingQualifierId: out q,
                error: out error);

            XAssert.AreEqual(expectedSuccess, result);

            if (result)
            {
                XAssert.AreEqual(expectedQualifier, ToString(q, table, context));
            }
            else
            {
                var location = LocationData.Create(AbsolutePath.Create(context.PathTable, m_path), 10, 10);
                Logger.Log.ErrorUnsupportedQualifierValue(
                    context.LoggingContext,
                    location.ToLogLocation(context.PathTable),
                    error.QualifierKey,
                    error.InvalidValue,
                    error.LegalValues
                    );
            }
        }
示例#5
0
 /// <summary>
 /// Helper to create a token with given text.
 /// </summary>
 private static LocationData CreateToken(BuildXLContext context)
 {
     return(LocationData.Create(AbsolutePath.Create(context.PathTable, AssemblyHelper.GetAssemblyLocation(typeof(MountsTable).GetTypeInfo().Assembly))));
 }