예제 #1
0
        public override void Init(Context context)
        {
            if (MinGW)
            {
                NativeLibraryExtension = Configurables.Defaults.MonoHostMingwRuntimeNativeLibraryExtension;
                NativeLibraryDirPrefix = Configurables.Paths.MonoRuntimeHostMingwNativeLibraryPrefix;
            }
            else
            {
                NativeLibraryExtension = Configurables.Defaults.NativeLibraryExtension;
            }

            if (Context.IsNativeHostAbi(Name))
            {
                OutputAotProfilerFilename = Configurables.Defaults.MonoRuntimeOutputAotProfilerFilename;
                OutputProfilerFilename    = Configurables.Defaults.MonoRuntimeOutputProfilerFilename;
            }
            else
            {
                OutputAotProfilerFilename = String.Empty;
                OutputProfilerFilename    = String.Empty;
            }
            OutputMonoBtlsFilename        = String.Empty;
            OutputMonoPosixHelperFilename = Configurables.Defaults.MonoRuntimeOutputMonoPosixHelperFilename;

            if (Context.IsMingwHostAbi(Name))
            {
                string prefix;
                if (Context.Is32BitMingwHostAbi(Name))
                {
                    prefix = Context.Properties.GetRequiredValue(KnownProperties.MingwCommandPrefix32);
                }
                else if (Context.Is64BitMingwHostAbi(Name))
                {
                    prefix = Context.Properties.GetRequiredValue(KnownProperties.MingwCommandPrefix64);
                }
                else
                {
                    throw new InvalidOperationException($"MinGW host ABI {Name} is neither 32 nor 64-bit (?!)");
                }
                Strip = Path.Combine(Configurables.Paths.MingwBinDir, $"{prefix}-strip");
            }
            else
            {
                Strip      = "strip";
                StripFlags = "-S";
            }

            InitOS();
        }
예제 #2
0
        async Task <bool> InstallRuntimes(Context context, List <Runtime> enabledRuntimes)
        {
            StatusStep(context, "Installing tests");
            EnsureAllRuntimes();
            foreach (TestAssembly tasm in allRuntimes !.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.Length > 0)
                {
                    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.DisplayName}");

                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 || src.Length == 0 || dst.Length == 0)
                    {
                        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.DisplayName} doesn't define the strip command");
                    return(true);
                }

                if (context.OS.IsWindows && (context.IsWindowsCrossAotAbi(monoRuntime.Name) || context.IsMingwHostAbi(monoRuntime.Name)))
                {
                    Log.WarningLine($"Unable to strip '{monoRuntime.DisplayName}' on Windows.");
                    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 {monoRuntime.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);
            }
        }