Example #1
0
        static int HandleCommand(string assembliesPath, string sourcePath, string[]?referencesPaths, bool verbose, bool quiet, bool debug, string?debugPath)
        {
            // If user provided a debug path then assume we should write debug outputs.
            debug |= debugPath is object;
            debugPath ??= Path.Combine(Path.GetTempPath(), $"BuildValidator");
            referencesPaths ??= Array.Empty <string>();

            var options = new Options(assembliesPath, referencesPaths, sourcePath, verbose, quiet, debug, debugPath);

            // TODO: remove the DemoLoggerProvider, update this dependency,
            // and move to the built in logger.
            var loggerFactory = new LoggerFactory(
                new[] { new ConsoleLoggerProvider(new ConsoleLoggerSettings()) },
                new LoggerFilterOptions()
            {
                MinLevel = options.Verbose ? LogLevel.Trace : LogLevel.Information
            });

            if (!options.Quiet)
            {
                loggerFactory.AddProvider(new DemoLoggerProvider());
            }

            var logger = loggerFactory.CreateLogger <Program>();

            try
            {
                var fullDebugPath = Path.GetFullPath(debugPath);
                logger.LogInformation($@"Using debug folder: ""{fullDebugPath}""");
                Directory.Delete(debugPath, recursive: true);
                logger.LogInformation($@"Cleaned debug folder: ""{fullDebugPath}""");
            }
            catch (IOException)
            {
                // no-op
            }

            try
            {
                var sourceResolver    = new LocalSourceResolver(options, loggerFactory);
                var referenceResolver = new LocalReferenceResolver(options, loggerFactory);

                var buildConstructor = new BuildConstructor(referenceResolver, sourceResolver, logger);

                var artifactsDir = new DirectoryInfo(options.AssembliesPath);

                var filesToValidate = artifactsDir.EnumerateFiles("*.exe", SearchOption.AllDirectories)
                                      .Concat(artifactsDir.EnumerateFiles("*.dll", SearchOption.AllDirectories))
                                      .Distinct(FileNameEqualityComparer.Instance);

                var success = ValidateFiles(filesToValidate, buildConstructor, logger, options);
                Console.Out.Flush();
                return(success ? ExitSuccess : ExitFailure);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
                throw;
            }
        }
Example #2
0
 internal RebuildArtifactResolver(
     LocalSourceResolver sourceResolver,
     LocalReferenceResolver referenceResolver
     )
 {
     SourceResolver    = sourceResolver;
     ReferenceResolver = referenceResolver;
 }
Example #3
0
        static void Main(string[] args)
        {
            Options options;

            try
            {
                options = Options.Create(args);
            }
            catch (InvalidDataException)
            {
                PrintHelp();
                return;
            }

            var loggerFactory = new LoggerFactory(Enumerable.Empty <ILoggerProvider>(), new LoggerFilterOptions()
            {
                MinLevel = options.Verbose ? LogLevel.Trace : LogLevel.Information
            });

            if (options.ConsoleOutput)
            {
                loggerFactory.AddConsole();
            }

            s_logger = loggerFactory.CreateLogger <Program>();

            var sourceResolver    = new LocalSourceResolver(loggerFactory);
            var referenceResolver = new LocalReferenceResolver(loggerFactory);

            var buildConstructor = new BuildConstructor(referenceResolver, sourceResolver);

            var artifactsDir        = LocalReferenceResolver.GetArtifactsDirectory();
            var thisCompilerVersion = options.IgnoreCompilerVersion
                ? null
                : typeof(Compilation).Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>()?.InformationalVersion;

            var filesToValidate = artifactsDir.EnumerateFiles("*.exe", SearchOption.AllDirectories)
                                  .Concat(artifactsDir.EnumerateFiles("*.dll", SearchOption.AllDirectories))
                                  .Distinct(FileNameEqualityComparer.Instance);

            ValidateFiles(filesToValidate, buildConstructor, thisCompilerVersion);
        }
Example #4
0
 public BuildConstructor(LocalReferenceResolver referenceResolver, LocalSourceResolver sourceResolver, ILogger logger)
 {
     _referenceResolver = referenceResolver;
     _sourceResolver    = sourceResolver;
     _logger            = logger;
 }