コード例 #1
0
        private static bool TryGetEvaluationFilter(Tracing.Logger logger, LoggingContext loggingContext, EngineContext engineContext, string filter, out EvaluationFilter evaluationFilter)
        {
            FilterParser parser = new FilterParser(
                engineContext,
                DummyPathResolver,
                filter);
            RootFilter        rootFilter;
            FilterParserError error;

            if (!parser.TryParse(out rootFilter, out error))
            {
                logger.ErrorParsingFilter(loggingContext, filter, error.Position, error.Message, error.FormatFilterPointingToPosition(filter));
                evaluationFilter = null;
                return(false);
            }

            evaluationFilter = rootFilter.GetEvaluationFilter(engineContext.SymbolTable, engineContext.PathTable);
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Builds a workspace and uses filter to find specs to evaluate.
        /// </summary>
        public static bool TryBuildWorkspaceAndCollectFilesToAnalyze(
            Tracing.Logger logger,
            PathTable pathTable,
            ICommandLineConfiguration configuation,
            out Workspace workspace,
            out IPipGraph pipGraph,
            out IReadOnlyDictionary <AbsolutePath, ISourceFile> filesToAnalyze,
            out FrontEndContext context)
        {
            workspace      = null;
            pipGraph       = null;
            filesToAnalyze = null;

            var loggingContext = new LoggingContext("DScriptAnalyzer");
            var fileSystem     = new PassThroughFileSystem(pathTable);
            var engineContext  = EngineContext.CreateNew(CancellationToken.None, pathTable, fileSystem);

            context = engineContext.ToFrontEndContext(loggingContext);

            // Parse filter string into EvaluationFilter
            var evaluationFilter = EvaluationFilter.Empty;

            if (!string.IsNullOrEmpty(configuation.Filter))
            {
                if (!TryGetEvaluationFilter(logger, loggingContext, engineContext, configuation.Filter, out evaluationFilter))
                {
                    // Error has been reported already
                    return(false);
                }
            }

            // Try parsing the workspace from config and evaluation filter
            if (!TryBuildWorkspace(
                    configuation,
                    context,
                    engineContext,
                    evaluationFilter,
                    progressHandler: null,
                    workspace: out workspace,
                    frontEndHostController: out _,
                    pipGraph: out pipGraph,
                    configuration: GetDefaultConfiguration()))
            {
                return(false);
            }

            if (configuation.Engine.Phase == EnginePhases.AnalyzeWorkspace)
            {
                // Find strict subset of specs in workspace that should be analyzed
                var collectedFilesToAnalyze = CollectFilesToAnalyze(
                    workspace,
                    pathTable,
                    configuation.Startup.ConfigFile,
                    evaluationFilter);

                if (collectedFilesToAnalyze.Count == 0)
                {
                    logger.ErrorFilterHasNoMatchingSpecs(loggingContext, configuation.Filter);
                    return(false);
                }

                filesToAnalyze = collectedFilesToAnalyze;
            }
            else
            {
                filesToAnalyze = new Dictionary <AbsolutePath, ISourceFile>();
            }

            return(true);
        }