protected override async Task <bool> Execute(Context context)
        {
            var    allRuntimes = new Runtimes();
            string binRoot     = Configurables.Paths.BinDir;
            string bundlePath  = Path.Combine(binRoot, Configurables.Paths.XABundleFileName);

            Log.StatusLine("Generating bundle archive: ", Utilities.GetRelativePath(BuildPaths.XamarinAndroidSourceRoot, bundlePath), tailColor: ConsoleColor.White);
            Utilities.DeleteFileSilent(bundlePath);

            var sevenZip         = new SevenZipRunner(context);
            CompressionFormat cf = context.CompressionFormat;
            Func <string, string, List <string>, Task <bool> > compressor;

            if (String.Compare(cf.Name, Configurables.Defaults.ZipCompressionFormatName, StringComparison.OrdinalIgnoreCase) == 0)
            {
                compressor = sevenZip.Zip;
            }
            else if (String.Compare(cf.Name, Configurables.Defaults.SevenZipCompressionFormatName, StringComparison.OrdinalIgnoreCase) == 0)
            {
                compressor = sevenZip.SevenZip;
            }
            else
            {
                throw new InvalidOperationException($"Unsupported compression type: {cf.Description}");
            }

            EnsureAllSDKHeadersAreIncluded(context, allRuntimes);
            List <string> items = allRuntimes.BundleItems.Where(item => item.ShouldInclude == null || item.ShouldInclude(context)).Select(
                item => {
                string relPath = Utilities.GetRelativePath(binRoot, item.SourcePath);
                Log.DebugLine($"Bundle item: {item.SourcePath} (archive path: {relPath})");
                return(relPath);
            }
                ).Distinct().ToList();

            items.Sort();

            if (!await compressor(bundlePath, binRoot, items))
            {
                Log.ErrorLine("Bundle archive creation failed, see the log files for details.");
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        async Task <bool> Unpack(string fullArchivePath, string destinationDirectory, bool cleanDestinationBeforeUnpacking = false)
        {
            // https://bintray.com/jetbrains/intellij-jdk/download_file?file_path=jbrsdk-8u202-windows-x64-b1483.37.tar.gz
            // doesn't contain a single root directory!  This causes the
            // "JetBrains root directory not found after unpacking" check to fail on Windows.
            // "Fix" things by setting destinationDirectory to contain RootDirName, allowing
            // the check to succeed.
            if (JdkVersion == Configurables.Defaults.JetBrainsOpenJDK8Version)
            {
                destinationDirectory = Path.Combine(destinationDirectory, RootDirName);
            }

            // On Windows we don't have Tar available and the Windows package is a .tar.gz
            // 7zip can unpack tar.gz but it's a two-stage process - first it decompresses the package, then it can be
            // invoked again to extract the actual tar contents.

            if (cleanDestinationBeforeUnpacking)
            {
                Utilities.DeleteDirectorySilent(destinationDirectory);
            }
            Utilities.CreateDirectory(destinationDirectory);

            var sevenZip = new SevenZipRunner(Context.Instance);

            Log.DebugLine($"Uncompressing {fullArchivePath} to {destinationDirectory}");
            if (!await sevenZip.Extract(fullArchivePath, destinationDirectory))
            {
                Log.DebugLine($"Failed to decompress {fullArchivePath}");
                return(false);
            }

            string tarPath = Path.Combine(destinationDirectory, Path.GetFileNameWithoutExtension(fullArchivePath));
            bool   ret     = await sevenZip.Extract(tarPath, destinationDirectory);

            Utilities.DeleteFileSilent(tarPath);

            if (!ret)
            {
                Log.DebugLine($"Failed to extract TAR contents from {tarPath}");
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        public static async Task <bool> VerifyArchive(string fullArchivePath)
        {
            if (String.IsNullOrEmpty(fullArchivePath))
            {
                throw new ArgumentNullException("must not be null or empty", nameof(fullArchivePath));
            }

            if (!FileExists(fullArchivePath))
            {
                return(false);
            }

            string sevenZip = Context.Instance.Tools.SevenZipPath;

            Log.DebugLine($"Verifying archive {fullArchivePath}");
            var runner = new SevenZipRunner(Context.Instance);

            return(await runner.VerifyArchive(fullArchivePath));
        }
Exemplo n.º 4
0
        public static async Task <bool> Unpack(string fullArchivePath, string destinationDirectory, bool cleanDestinatioBeforeUnpacking = false)
        {
            if (String.IsNullOrEmpty(fullArchivePath))
            {
                throw new ArgumentNullException("must not be null or empty", nameof(fullArchivePath));
            }
            if (String.IsNullOrEmpty(destinationDirectory))
            {
                throw new ArgumentNullException("must not be null or empty", nameof(destinationDirectory));
            }

            if (cleanDestinatioBeforeUnpacking)
            {
                DeleteDirectorySilent(destinationDirectory);
            }

            CreateDirectory(destinationDirectory);

            Log.DebugLine($"Unpacking {fullArchivePath} to directory: {destinationDirectory}");
            bool useTar = false;

            foreach (string ext in tarArchiveExtensions)
            {
                if (fullArchivePath.EndsWith(ext, StringComparison.OrdinalIgnoreCase))
                {
                    useTar = true;
                    break;
                }
            }

            if (useTar)
            {
                var tar = new TarRunner(Context.Instance);
                return(await tar.Extract(fullArchivePath, destinationDirectory));
            }

            var sevenZip = new SevenZipRunner(Context.Instance);

            return(await sevenZip.Extract(fullArchivePath, destinationDirectory));
        }
Exemplo n.º 5
0
        async Task <bool> Unpack(string fullArchivePath, string destinationDirectory, bool cleanDestinationBeforeUnpacking = false)
        {
            if (cleanDestinationBeforeUnpacking)
            {
                Utilities.DeleteDirectorySilent(destinationDirectory);
            }
            Utilities.CreateDirectory(destinationDirectory);

            var sevenZip = new SevenZipRunner(Context.Instance);

            Log.DebugLine($"Uncompressing {fullArchivePath} to {destinationDirectory}");
            if (!await sevenZip.Extract(fullArchivePath, destinationDirectory))
            {
                Log.DebugLine($"Failed to decompress {fullArchivePath}");
                return(false);
            }

            if (fullArchivePath.EndsWith("tar.gz", StringComparison.OrdinalIgnoreCase))
            {
                // On Windows we don't have Tar available and the Windows package is a .tar.gz
                // 7zip can unpack tar.gz but it's a two-stage process - first it decompresses the package, then it can be
                // invoked again to extract the actual tar contents.
                string tarPath = Path.Combine(destinationDirectory, Path.GetFileNameWithoutExtension(fullArchivePath));
                bool   ret     = await sevenZip.Extract(tarPath, destinationDirectory);

                Utilities.DeleteFileSilent(tarPath);

                if (!ret)
                {
                    Log.DebugLine($"Failed to extract TAR contents from {tarPath}");
                    return(false);
                }
            }

            return(true);
        }
        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);
            }
        }