private void RegisterAccesses(ParseResult results)
        {
            // Even thought CommandLineArguments class claims to always report back absolute paths, that's not the case.
            // Use the base directory to resolve relative paths if needed
            // The base directory is what CommandLineArgument claims to be resolving all paths against anyway
            var accessRegister = new AccessRegistrar(m_augmentedReporter, results.ParsedArguments.BaseDirectory);

            // All inputs
            accessRegister.RegisterInputs(results.ParsedArguments.AnalyzerReferences.Select(r => ResolveRelativePathIfNeeded(r.FilePath, results.ParsedArguments.BaseDirectory, results.ParsedArguments.ReferencePaths)));
            accessRegister.RegisterInputs(results.ParsedArguments.MetadataReferences.Select(r => ResolveRelativePathIfNeeded(r.Reference, results.ParsedArguments.BaseDirectory, results.ParsedArguments.ReferencePaths)));
            accessRegister.RegisterInputs(results.ParsedArguments.SourceFiles.Select(source => source.Path));
            accessRegister.RegisterInputs(results.ParsedArguments.EmbeddedFiles.Select(embedded => embedded.Path));
            accessRegister.RegisterInput(results.ParsedArguments.Win32ResourceFile);
            accessRegister.RegisterInput(results.ParsedArguments.Win32Icon);
            accessRegister.RegisterInput(results.ParsedArguments.Win32Manifest);
            accessRegister.RegisterInputs(results.ParsedArguments.AdditionalFiles.Select(additional => additional.Path));
            accessRegister.RegisterInput(results.ParsedArguments.AppConfigPath);
            accessRegister.RegisterInput(results.ParsedArguments.RuleSetPath);
            accessRegister.RegisterInput(results.ParsedArguments.SourceLink);
            accessRegister.RegisterInput(results.ParsedArguments.CompilationOptions.CryptoKeyFile);
#if !TEST
            // When building for tests we intentionally use an older version of CommandLineArguments where these fields are not available
            accessRegister.RegisterInputs(results.ParsedArguments.AnalyzerConfigPaths);
            accessRegister.RegisterOutput(results.ParsedArguments.ErrorLogOptions?.Path);

            // If there is any analyzer configured and the generated output directory is not null, that means some of the configured analyzers could be source generators, and therefore they might
            // produce files under the generated output directory. We cannot predict those outputs files, so we bail out for this case
            if (results.ParsedArguments.GeneratedFilesOutputDirectory != null && results.ParsedArguments.AnalyzerReferences.Length > 0 && !results.ParsedArguments.SkipAnalyzers)
            {
                throw new InvalidOperationException("The compilation is configured to emit generated sources which cannot be statically predicted. Static predictions are required for managed compilers when shared compilation is enabled. " +
                                                    "Please disable shared compilation.");
            }
#endif
            // /resource: parameters end up in ParsedArguments.ManifestResources, but the returned class drops the file path. We'll have to get them explicitly.
            // We might be able to simply use ParsedArguments.ManifestResources if this gets resolved: https://github.com/dotnet/roslyn/issues/41372
            accessRegister.RegisterInputs(results.EmbeddedResourcePaths);

            // All outputs
            accessRegister.RegisterOutput(results.ParsedArguments.TouchedFilesPath?.Insert(results.ParsedArguments.TouchedFilesPath.Length - 1, ".read"));
            accessRegister.RegisterOutput(results.ParsedArguments.TouchedFilesPath?.Insert(results.ParsedArguments.TouchedFilesPath.Length - 1, ".write"));
            accessRegister.RegisterOutput(results.ParsedArguments.DocumentationPath);
            accessRegister.RegisterOutput(results.ParsedArguments.ErrorLogPath);
            accessRegister.RegisterOutput(results.ParsedArguments.OutputRefFilePath);
            var outputFileName = ComputeOutputFileName(results.ParsedArguments);
            accessRegister.RegisterOutput(Path.Combine(results.ParsedArguments.OutputDirectory, outputFileName));
            if (results.ParsedArguments.EmitPdb)
            {
                accessRegister.RegisterOutput(Path.Combine(results.ParsedArguments.OutputDirectory, results.ParsedArguments.PdbPath ?? Path.ChangeExtension(outputFileName, ".pdb")));
            }
        }
Example #2
0
        private void RegisterAccesses(ParseResult results)
        {
            // Even thought CommandLineArguments class claims to always report back absolute paths, that's not the case.
            // Use the base directory to resolve relative paths if needed
            // The base directory is what CommandLineArgument claims to be resolving all paths against anyway
            var accessRegister = new AccessRegistrar(m_augmentedReporter, results.ParsedArguments.BaseDirectory);

            // All inputs
            accessRegister.RegisterInputs(results.ParsedArguments.AnalyzerReferences.Select(r => ResolveRelativePathIfNeeded(r.FilePath, results.ParsedArguments.BaseDirectory, results.ParsedArguments.ReferencePaths)));
            accessRegister.RegisterInputs(results.ParsedArguments.MetadataReferences.Select(r => ResolveRelativePathIfNeeded(r.Reference, results.ParsedArguments.BaseDirectory, results.ParsedArguments.ReferencePaths)));
            accessRegister.RegisterInputs(results.ParsedArguments.SourceFiles.Select(source => source.Path));
            accessRegister.RegisterInputs(results.ParsedArguments.EmbeddedFiles.Select(embedded => embedded.Path));
            accessRegister.RegisterInput(results.ParsedArguments.Win32ResourceFile);
            accessRegister.RegisterInput(results.ParsedArguments.Win32Icon);
            accessRegister.RegisterInput(results.ParsedArguments.Win32Manifest);
            accessRegister.RegisterInputs(results.ParsedArguments.AdditionalFiles.Select(additional => additional.Path));
            accessRegister.RegisterInput(results.ParsedArguments.AppConfigPath);
            accessRegister.RegisterInput(results.ParsedArguments.RuleSetPath);
            accessRegister.RegisterInput(results.ParsedArguments.SourceLink);
            accessRegister.RegisterInput(results.ParsedArguments.CompilationOptions.CryptoKeyFile);
#if !TEST
            // When building for tests we intentionally use an older version of CommandLineArguments where this field is not available
            accessRegister.RegisterInputs(results.ParsedArguments.AnalyzerConfigPaths);
#endif
            // /resource: parameters end up in ParsedArguments.ManifestResources, but the returned class drops the file path. We'll have to get them explicitly.
            // We might be able to simply use ParsedArguments.ManifestResources if this gets resolved: https://github.com/dotnet/roslyn/issues/41372
            accessRegister.RegisterInputs(results.EmbeddedResourcePaths);

            // All outputs
            accessRegister.RegisterOutput(results.ParsedArguments.TouchedFilesPath?.Insert(results.ParsedArguments.TouchedFilesPath.Length - 1, ".read"));
            accessRegister.RegisterOutput(results.ParsedArguments.TouchedFilesPath?.Insert(results.ParsedArguments.TouchedFilesPath.Length - 1, ".write"));
            accessRegister.RegisterOutput(results.ParsedArguments.DocumentationPath);
            accessRegister.RegisterOutput(results.ParsedArguments.ErrorLogPath);
            accessRegister.RegisterOutput(results.ParsedArguments.OutputRefFilePath);
            var outputFileName = ComputeOutputFileName(results.ParsedArguments);
            accessRegister.RegisterOutput(Path.Combine(results.ParsedArguments.OutputDirectory, outputFileName));
            if (results.ParsedArguments.EmitPdb)
            {
                accessRegister.RegisterOutput(Path.Combine(results.ParsedArguments.OutputDirectory, results.ParsedArguments.PdbPath ?? Path.ChangeExtension(outputFileName, ".pdb")));
            }
        }
        private void RegisterAccesses(CommandLineArguments args)
        {
            // Even thought CommandLineArguments class claims to always report back absolute paths, that's not the case.
            // Use the base directory to resolve relative paths if needed
            // The base directory is what CommandLineArgument claims to be resolving all paths against anyway
            var accessRegister = new AccessRegistrar(m_augmentedReporter, args.BaseDirectory);

            // All inputs
            accessRegister.RegisterInputs(args.AnalyzerReferences.Select(r => ResolveRelativePathIfNeeded(r.FilePath, args.BaseDirectory, args.ReferencePaths)));
            accessRegister.RegisterInputs(args.MetadataReferences.Select(r => ResolveRelativePathIfNeeded(r.Reference, args.BaseDirectory, args.ReferencePaths)));
            accessRegister.RegisterInputs(args.SourceFiles.Select(source => source.Path));
            accessRegister.RegisterInputs(args.EmbeddedFiles.Select(embedded => embedded.Path));
            accessRegister.RegisterInput(args.Win32ResourceFile);
            accessRegister.RegisterInput(args.Win32Icon);
            accessRegister.RegisterInput(args.Win32Manifest);
            accessRegister.RegisterInputs(args.AdditionalFiles.Select(additional => additional.Path));
            accessRegister.RegisterInput(args.AppConfigPath);
            accessRegister.RegisterInput(args.RuleSetPath);
            accessRegister.RegisterInput(args.SourceLink);
            accessRegister.RegisterInput(args.CompilationOptions.CryptoKeyFile);
#if !TEST
            // When building for tests we intentioally use an older version of CommandLinArguments where this field is not available
            accessRegister.RegisterInputs(args.AnalyzerConfigPaths);
#endif

            // All outputs
            accessRegister.RegisterOutput(args.TouchedFilesPath?.Insert(args.TouchedFilesPath.Length - 1, ".read"));
            accessRegister.RegisterOutput(args.TouchedFilesPath?.Insert(args.TouchedFilesPath.Length - 1, ".write"));
            accessRegister.RegisterOutput(args.DocumentationPath);
            accessRegister.RegisterOutput(args.ErrorLogPath);
            accessRegister.RegisterOutput(args.OutputRefFilePath);
            var outputFileName = ComputeOutputFileName(args);
            accessRegister.RegisterOutput(Path.Combine(args.OutputDirectory, outputFileName));
            if (args.EmitPdb)
            {
                accessRegister.RegisterOutput(Path.Combine(args.OutputDirectory, args.PdbPath ?? Path.ChangeExtension(outputFileName, ".pdb")));
            }
        }