示例#1
0
        /// <summary>
        /// Runs AST conversion on the given target path.
        /// </summary>
        /// <remarks>
        /// The target path is assumed to already be part of the workspace contained by the given host
        /// </remarks>
        public static Task <SourceFileParseResult> RunAstConversionAsync(FrontEndHost host, FrontEndContext context, Script.Tracing.Logger logger, IFrontEndStatistics stats, Package package, AbsolutePath conversionTarget)
        {
            Contract.RequiresNotNull(host);
            Contract.RequiresNotNull(context);
            Contract.RequiresNotNull(logger);
            Contract.RequiresNotNull(stats);
            Contract.RequiresNotNull(package);
            Contract.Requires(conversionTarget.IsValid);

            var configuration = AstConversionConfiguration.FromConfiguration(host.Configuration.FrontEnd);
            var linter        = DiagnosticAnalyzer.Create(
                logger,
                context.LoggingContext,
                new HashSet <string>(configuration.PolicyRules),
                configuration.DisableLanguagePolicies);

            var workspace     = (Workspace)host.Workspace;
            var factory       = new RuntimeModelFactory(stats, configuration, linter, workspace);
            var parserContext = new RuntimeModelContext(
                host,
                frontEndContext: context,
                logger,
                package: package,
                origin: default(LocationData));

            var sourceFile = workspace.GetSourceFile(conversionTarget);

            return(factory.ConvertSourceFileAsync(parserContext, sourceFile));
        }
示例#2
0
 /// <summary>
 /// Creates a linter given <see cref="AstConversionConfiguration"/>.
 /// </summary>
 protected DiagnosticAnalyzer CreateLinter(AstConversionConfiguration configuration)
 {
     return(DiagnosticAnalyzer.Create(
                Logger,
                Context.LoggingContext,
                new HashSet <string>(configuration.PolicyRules),
                configuration.DisableLanguagePolicies));
 }
示例#3
0
        /// <summary>
        /// Lints a given set of specs that belong to a workspace and include any potential linter failures in the resulting one.
        /// </summary>
        public static Workspace CreateLintedWorkspaceForChangedSpecs(
            Workspace workspace,
            IEnumerable <ISourceFile> changedSpecsToLint,
            LoggingContext loggingContext,
            IFrontEndConfiguration configuration,
            PathTable pathTable)
        {
            var logger = BuildXL.FrontEnd.Script.Tracing.Logger.CreateLogger(preserveLogEvents: true);

            var linter = DiagnosticAnalyzer.Create(
                logger,
                loggingContext,
                new HashSet <string>(configuration.EnabledPolicyRules),
                disableLanguagePolicies: false);

            // Lint all files in parallel and wait for queue completion
            var linterQueue = new ActionBlock <ISourceFile>(
                (Action <ISourceFile>)LintFile,
                new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = configuration.MaxFrontEndConcurrency()
            });

            foreach (var sourceFile in changedSpecsToLint)
            {
                linterQueue.Post(sourceFile);
            }

            linterQueue.Complete();

            linterQueue.Completion.GetAwaiter().GetResult();

            // Create a workspace with the extra failures (if any) and return it
            var linterFailures = ComputeLinterFailures(workspace, logger, pathTable);

            return(linterFailures.Count > 0 ? workspace.WithExtraFailures(linterFailures) : workspace);

            // Local functions
            void LintFile(ISourceFile sourceFile)
            {
                if (!sourceFile.HasDiagnostics())
                {
                    linter.AnalyzeFile(sourceFile, logger, loggingContext, pathTable, workspace);
                }
            }
        }