Exemplo n.º 1
0
        public override StrategyResult?Execute()
        {
            Logger.Debug("Executing {0} reproducibility strategy.", GetType().Name);
            if (!StrategyApplies())
            {
                Logger.Debug("Strategy does not apply, so cannot execute.");
                return(null);
            }

            StrategyResult?strategyResult = new StrategyResult()
            {
                Strategy = GetType()
            };

            if (Options.IncludeDiffoscope)
            {
                string?diffoscopeTempDir = Path.Join(Options.TemporaryDirectory, "diffoscope");
                string?diffoscopeResults = GenerateDiffoscope(diffoscopeTempDir, Options.SourceDirectory !, Options.PackageDirectory !);
                strategyResult.Diffoscope = diffoscopeResults;
            }

            System.Collections.Generic.IEnumerable <DirectoryDifference>?diffResults = OssReproducibleHelpers.DirectoryDifference(Options.PackageDirectory !, Options.SourceDirectory !, Options.DiffTechnique);
            int diffResultsOriginalCount = diffResults.Count();

            diffResults = diffResults.Where(d => !IgnoreFilter.IsIgnored(Options.PackageUrl, GetType().Name, d.Filename));
            strategyResult.NumIgnoredFiles += (diffResultsOriginalCount - diffResults.Count());
            strategyResult.AddDifferencesToStrategyResult(diffResults);

            return(strategyResult);
        }
Exemplo n.º 2
0
        public override StrategyResult?Execute()
        {
            Logger.Debug("Executing {0} reproducibility strategy.", GetType().Name);
            if (!StrategyApplies())
            {
                Logger.Debug("Strategy does not apply, so cannot execute.");
                return(null);
            }

            string?workingDirectory = OssReproducibleHelpers.GetFirstNonSingularDirectory(Options.SourceDirectory);

            if (workingDirectory == null)
            {
                Logger.Warn("Unable to find correct source directory to run Oryx against. Unable to continue.");
                return(null);
            }

            string?outputDirectory = Path.Join(Options.TemporaryDirectory, "build");

            Directory.CreateDirectory(outputDirectory);
            string?tempBuildArchiveDirectory = Path.Join(Options.TemporaryDirectory, "archive");

            Directory.CreateDirectory(tempBuildArchiveDirectory);

            bool runResult = OssReproducibleHelpers.RunCommand(workingDirectory, "docker", new[] {
                "run",
                "--rm",
                "--volume", $"{Path.GetFullPath(workingDirectory)}:/repo",
                "--volume", $"{Path.GetFullPath(outputDirectory)}:/build-output",
                "mcr.microsoft.com/oryx/build:latest",
                "oryx",
                "build",
                "/repo",
                "--output", "/build-output"
            }, out string?stdout, out string?stderr);

            StrategyResult?strategyResult = new StrategyResult()
            {
                Strategy = GetType()
            };

            if (runResult)
            {
                if (Directory.GetFiles(outputDirectory, "*", SearchOption.AllDirectories).Any())
                {
                    if (Options.IncludeDiffoscope)
                    {
                        string?diffoscopeTempDir = Path.Join(Options.TemporaryDirectory, "diffoscope");
                        string?diffoscopeResults = GenerateDiffoscope(diffoscopeTempDir, outputDirectory, Options.PackageDirectory !);
                        strategyResult.Diffoscope = diffoscopeResults;
                    }

                    System.Collections.Generic.IEnumerable <DirectoryDifference>?diffResults = OssReproducibleHelpers.DirectoryDifference(Options.PackageDirectory !, outputDirectory, Options.DiffTechnique);
                    int diffResultsOriginalCount = diffResults.Count();
                    diffResults = diffResults.Where(d => !IgnoreFilter.IsIgnored(Options.PackageUrl, GetType().Name, d.Filename));
                    strategyResult.NumIgnoredFiles += (diffResultsOriginalCount - diffResults.Count());
                    strategyResult.AddDifferencesToStrategyResult(diffResults);
                }
                else
                {
                    strategyResult.IsError = true;
                    strategyResult.Summary = "The OryxBuildStrategy did not complete successfully (no files produced).";
                }
            }
            else
            {
                strategyResult.IsError = true;
                strategyResult.Summary = "The OryxBuildStrategy did not complete successfully (container execution failed).";
            }

            return(strategyResult);
        }