Example #1
0
        public static (string assembly, string debugSymbols) GetDestinationPaths(TestAssembly tasm)
        {
            if (tasm == null)
            {
                throw new ArgumentNullException(nameof(tasm));
            }

            bool pdbRequired;

            switch (tasm.TestType)
            {
            case TestAssemblyType.Reference:
            case TestAssemblyType.TestRunner:
            case TestAssemblyType.XUnit:
            case TestAssemblyType.NUnit:
            case TestAssemblyType.Satellite:
                pdbRequired = tasm.TestType != TestAssemblyType.Satellite && !tasm.ExcludeDebugSymbols;
                break;

            default:
                throw new InvalidOperationException($"Unsupported test assembly type: {tasm.TestType}");
            }

            string destDir;

            if (tasm.Name.IndexOf(Path.DirectorySeparatorChar) >= 0)
            {
                destDir = Path.Combine(BCLTestsDestinationDir, Path.GetDirectoryName(tasm.Name));
            }
            else
            {
                destDir = BCLTestsDestinationDir;
            }

            string destFile = Path.Combine(destDir, Path.GetFileName(tasm.Name));

            return(destFile, pdbRequired ? Utilities.GetDebugSymbolsPath(destFile) : null);
        }
        public static (string executable, string debugSymbols) GetDestinationPaths(MonoUtilityFile muf)
        {
            string destDir = UtilitiesDestinationDir;
            string targetFileName;

            if (!String.IsNullOrEmpty(muf.TargetName))
            {
                targetFileName = muf.TargetName !;
            }
            else
            {
                targetFileName = Path.GetFileName(muf.SourcePath);
            }

            string destFilePath = Path.Combine(destDir, targetFileName);

            if (String.IsNullOrEmpty(muf.DebugSymbolsPath))
            {
                return(destFilePath, String.Empty);
            }

            return(destFilePath, Path.Combine(destDir, Utilities.GetDebugSymbolsPath(targetFileName)));
        }
        async Task <bool> InstallRuntimes(Context context, List <Runtime> enabledRuntimes)
        {
            StatusStep(context, "Installing tests");
            foreach (TestAssembly tasm in Runtimes.TestAssemblies)
            {
                string sourceBasePath;

                switch (tasm.TestType)
                {
                case TestAssemblyType.Reference:
                case TestAssemblyType.TestRunner:
                    sourceBasePath = Path.Combine(Configurables.Paths.MonoProfileDir);
                    break;

                case TestAssemblyType.XUnit:
                case TestAssemblyType.NUnit:
                case TestAssemblyType.Satellite:
                    sourceBasePath = Configurables.Paths.BCLTestsSourceDir;
                    break;

                default:
                    throw new InvalidOperationException($"Unsupported test assembly type: {tasm.TestType}");
                }

                (string destFilePath, string debugSymbolsDestPath) = MonoRuntimesHelpers.GetDestinationPaths(tasm);
                CopyFile(Path.Combine(sourceBasePath, tasm.Name), destFilePath);
                if (debugSymbolsDestPath != null)
                {
                    CopyFile(Path.Combine(sourceBasePath, Utilities.GetDebugSymbolsPath(tasm.Name)), debugSymbolsDestPath);
                }
            }

            StatusSubStep(context, "Creating BCL tests archive");
            Utilities.DeleteFileSilent(MonoRuntimesHelpers.BCLTestsArchivePath);
            var sevenZip = new SevenZipRunner(context);

            if (!await sevenZip.Zip(MonoRuntimesHelpers.BCLTestsArchivePath, MonoRuntimesHelpers.BCLTestsDestinationDir, new List <string> {
                "."
            }))
            {
                Log.ErrorLine("BCL tests archive creation failed, see the log files for details.");
                return(false);
            }

            StatusStep(context, "Installing runtimes");
            foreach (Runtime runtime in enabledRuntimes)
            {
                StatusSubStep(context, $"Installing {runtime.Flavor} runtime {runtime.Name}");

                string src, dst;
                bool   skipFile;
                foreach (RuntimeFile rtf in allRuntimes.RuntimeFilesToInstall)
                {
                    if (rtf.Shared && rtf.AlreadyCopied)
                    {
                        continue;
                    }

                    (skipFile, src, dst) = MonoRuntimesHelpers.GetRuntimeFilePaths(runtime, rtf);
                    if (skipFile)
                    {
                        continue;
                    }

                    CopyFile(src, dst);
                    if (!StripFile(runtime, rtf, dst))
                    {
                        return(false);
                    }

                    if (rtf.Shared)
                    {
                        rtf.AlreadyCopied = true;
                    }
                }
            }

            return(true);

            bool StripFile(Runtime runtime, RuntimeFile rtf, string filePath)
            {
                if (rtf.Type != RuntimeFileType.StrippableBinary)
                {
                    return(true);
                }

                var monoRuntime = runtime.As <MonoRuntime> ();

                if (monoRuntime == null || !monoRuntime.CanStripNativeLibrary || !rtf.Strip)
                {
                    return(true);
                }

                if (String.IsNullOrEmpty(monoRuntime.Strip))
                {
                    Log.WarningLine($"Binary stripping impossible, runtime {monoRuntime.Name} doesn't define the strip command");
                    return(true);
                }

                bool result;

                if (!String.IsNullOrEmpty(monoRuntime.StripFlags))
                {
                    result = Utilities.RunCommand(monoRuntime.Strip, monoRuntime.StripFlags, filePath);
                }
                else
                {
                    result = Utilities.RunCommand(monoRuntime.Strip, filePath);
                }

                if (result)
                {
                    return(true);
                }

                Log.ErrorLine($"Failed to strip the binary file {filePath}, see logs for error details");
                return(false);
            }

            void CopyFile(string src, string dest)
            {
                if (!CheckFileExists(src, true))
                {
                    return;
                }

                Utilities.CopyFile(src, dest);
            }
        }