bool InstallBCL(Context context)
        {
            string redistListDir = MonoRuntimesHelpers.BCLRedistListDestinationDir;

            foreach (KeyValuePair <BclFileTarget, string> kvp in MonoRuntimesHelpers.BCLDestinationDirs)
            {
                Utilities.CreateDirectory(kvp.Value);
            }

            foreach (KeyValuePair <BclFileTarget, string> kvp in MonoRuntimesHelpers.BCLFacadesDestinationDirs)
            {
                Utilities.CreateDirectory(kvp.Value);
            }

            Utilities.CreateDirectory(redistListDir);

            StatusStep(context, "Installing Android BCL assemblies");
            InstallBCLFiles(allRuntimes.BclFilesToInstall);

            StatusStep(context, "Installing Designer Host BCL assemblies");
            InstallBCLFiles(allRuntimes.DesignerHostBclFilesToInstall);

            StatusStep(context, "Installing Designer Windows BCL assemblies");
            InstallBCLFiles(allRuntimes.DesignerWindowsBclFilesToInstall);

            return(GenerateFrameworkList(
                       context,
                       MonoRuntimesHelpers.FrameworkListPath,
                       MonoRuntimesHelpers.BCLDestinationDirs [BclFileTarget.Android],
                       MonoRuntimesHelpers.BCLFacadesDestinationDirs [BclFileTarget.Android]
                       ));
        }
Esempio n. 2
0
        bool InstallUtilities(Context context)
        {
            string destDir = MonoRuntimesHelpers.UtilitiesDestinationDir;

            Utilities.CreateDirectory(destDir);

            string managedRuntime     = context.Properties.GetRequiredValue(KnownProperties.ManagedRuntime);
            bool   haveManagedRuntime = !String.IsNullOrEmpty(managedRuntime);
            string remapper           = Utilities.GetRelativePath(BuildPaths.XamarinAndroidSourceRoot, context.Properties.GetRequiredValue(KnownProperties.RemapAssemblyRefToolExecutable));
            string targetCecil        = Utilities.GetRelativePath(BuildPaths.XamarinAndroidSourceRoot, Path.Combine(Configurables.Paths.BuildBinDir, "Xamarin.Android.Cecil.dll"));

            StatusStep(context, "Installing runtime utilities");
            foreach (MonoUtilityFile muf in allRuntimes.UtilityFilesToInstall)
            {
                (string destFilePath, string debugSymbolsDestPath) = MonoRuntimesHelpers.GetDestinationPaths(muf);
                Utilities.CopyFile(muf.SourcePath, destFilePath);
                if (!muf.IgnoreDebugInfo)
                {
                    if (!String.IsNullOrEmpty(debugSymbolsDestPath))
                    {
                        Utilities.CopyFile(muf.DebugSymbolsPath, debugSymbolsDestPath);
                    }
                    else
                    {
                        Log.DebugLine($"Debug symbols not found for utility file {Path.GetFileName (muf.SourcePath)}");
                    }
                }

                if (!muf.RemapCecil)
                {
                    continue;
                }

                string relDestFilePath = Utilities.GetRelativePath(BuildPaths.XamarinAndroidSourceRoot, destFilePath);
                StatusSubStep(context, $"Remapping Cecil references for {relDestFilePath}");
                bool result = Utilities.RunCommand(
                    haveManagedRuntime ? managedRuntime : remapper, // command
                    BuildPaths.XamarinAndroidSourceRoot,            // workingDirectory
                    true,                                           // ignoreEmptyArguments

                    // arguments
                    haveManagedRuntime ? remapper : String.Empty,
                    Utilities.GetRelativePath(BuildPaths.XamarinAndroidSourceRoot, muf.SourcePath),
                    relDestFilePath,
                    "Mono.Cecil",
                    targetCecil);

                if (result)
                {
                    continue;
                }

                Log.ErrorLine($"Failed to remap cecil reference for {destFilePath}");
                return(false);
            }

            return(true);
        }
        async Task <bool> FetchFiles(HashSet <string> neededFiles, string destinationDirectory, Uri url)
        {
            Utilities.CreateDirectory(destinationDirectory);
            using (var httpClient = new HttpClient()) {
                bool success;
                long size;

                Log.StatusLine($"Accessing {url}");
                (success, size) = await GetFileSize(httpClient, url);

                if (!success)
                {
                    return(false);
                }

                Log.DebugLine($"  File size: {size}");

                EOCD eocd;
                (success, eocd) = await GetEOCD(httpClient, url, size);

                if (!success)
                {
                    Log.ErrorLine("Failed to find the End of Central Directory record");
                    return(false);
                }

                if (eocd.DiskNumber != 0)
                {
                    throw new InvalidOperationException("Multi-disk ZIP archives not supported");
                }

                Log.DebugLine($"  Central Directory offset: {eocd.CDOffset} (0x{eocd.CDOffset:x})");
                Log.DebugLine($"  Central Directory size: {eocd.CDSize} (0x{eocd.CDSize})");
                Log.DebugLine($"  Total Entries: {eocd.TotalEntries}");

                Stream cd;
                (success, cd) = await ReadCD(httpClient, url, eocd.CDOffset, eocd.CDSize, size);

                if (!success)
                {
                    Log.ErrorLine("Failed to read the Central Directory");
                    return(false);
                }

                Log.StatusLine("Files:");
                if (!await ProcessEntries(httpClient, url, eocd, cd, neededFiles, destinationDirectory))
                {
                    return(false);
                }
            }

            return(true);
        }
        protected override async Task <bool> Execute(Context context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            Uri    nugetUrl       = Configurables.Urls.NugetUri;
            string localNugetPath = Configurables.Paths.LocalNugetPath;

            if (Utilities.FileExists(localNugetPath))
            {
                Log.StatusLine($"NuGet already downloaded ({localNugetPath})");
                return(true);
            }

            Utilities.CreateDirectory(Path.GetDirectoryName(localNugetPath));
            Log.StatusLine("Downloading NuGet");

            (bool success, ulong size, HttpStatusCode status) = await Utilities.GetDownloadSizeWithStatus(nugetUrl);

            if (!success)
            {
                if (status == HttpStatusCode.NotFound)
                {
                    Log.ErrorLine("NuGet URL not found");
                }
                else
                {
                    Log.ErrorLine("Failed to obtain NuGet size. HTTP status code: {status} ({(int)status})");
                }
                return(false);
            }

            DownloadStatus downloadStatus = Utilities.SetupDownloadStatus(context, size, context.InteractiveSession);

            Log.StatusLine($"  {context.Characters.Link} {nugetUrl}", ConsoleColor.White);
            await Download(context, nugetUrl, localNugetPath, "NuGet", Path.GetFileName(localNugetPath), downloadStatus);

            if (!File.Exists(localNugetPath))
            {
                Log.ErrorLine($"Download of NuGet from {nugetUrl} failed");
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
        protected override async Task <bool> Execute(Context context)
        {
            string hostDestinationDirectory    = Configurables.Paths.HostBinutilsInstallDir;
            string windowsDestinationDirectory = Configurables.Paths.WindowsBinutilsInstallDir;

            bool hostHaveAll    = HaveAllBinutils(hostDestinationDirectory);
            bool windowsHaveAll = HaveAllBinutils(windowsDestinationDirectory, ".exe");

            if (hostHaveAll && windowsHaveAll)
            {
                Log.StatusLine("All Binutils are already installed");
                return(true);
            }

            string packageName      = Path.GetFileName(Configurables.Urls.BinutilsArchive.LocalPath);
            string localArchivePath = Path.Combine(Configurables.Paths.BinutilsCacheDir, packageName);

            if (!await DownloadBinutils(context, localArchivePath, Configurables.Urls.BinutilsArchive))
            {
                return(false);
            }

            string tempDir = Path.Combine(Path.GetTempPath(), "xaprepare-binutils");

            Utilities.DeleteDirectorySilent(tempDir);
            Utilities.CreateDirectory(tempDir);

            Log.DebugLine($"Unpacking {ProductName} archive {localArchivePath} into {tempDir}");
            if (!await Utilities.Unpack(localArchivePath, tempDir, cleanDestinatioBeforeUnpacking: true))
            {
                return(false);
            }

            if (!hostHaveAll)
            {
                CopyToDestination(context, "Host", tempDir, hostDestinationDirectory, executableExtension: ExecutableExtension);
            }

            if (!windowsHaveAll)
            {
                CopyToDestination(context, "Windows", tempDir, windowsDestinationDirectory, "windows", ".exe");
            }

            return(true);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public async Task <bool> Clone(string url, string destinationDirectoryPath)
        {
            if (String.IsNullOrEmpty(url))
            {
                throw new ArgumentException("must not be null or empty", nameof(url));
            }
            if (String.IsNullOrEmpty(destinationDirectoryPath))
            {
                throw new ArgumentException("must not be null or empty", nameof(destinationDirectoryPath));
            }

            string parentDir = Path.GetDirectoryName(destinationDirectoryPath);
            string dirName   = Path.GetFileName(destinationDirectoryPath);

            Utilities.CreateDirectory(parentDir);
            var runner = CreateGitRunner(parentDir);;

            runner.AddArgument("clone");
            runner.AddArgument("--progress");
            runner.AddQuotedArgument(url);

            return(await RunGit(runner, $"clone-{dirName}"));
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
 protected void EnsureOutputDir()
 {
     Utilities.CreateDirectory(Path.GetDirectoryName(OutputPath));
 }
Esempio n. 10
0
        async Task <bool> ConjureXamarinCecilAndRemapRef(Context context, bool haveManagedRuntime, string managedRuntime)
        {
            StatusStep(context, "Building remap-assembly-ref");
            bool result = await Utilities.BuildRemapRef(context, haveManagedRuntime, managedRuntime, quiet : true);

            if (!result)
            {
                return(false);
            }

            var msbuild = new MSBuildRunner(context);

            StatusStep(context, "Building conjure-xamarin-android-cecil");
            string projectPath = Path.Combine(Configurables.Paths.BuildToolsDir, "conjure-xamarin-android-cecil", "conjure-xamarin-android-cecil.csproj");

            result = await msbuild.Run(
                projectPath : projectPath,
                logTag : "conjure-xamarin-android-cecil",
                binlogName : "build-conjure-xamarin-android-cecil"
                );

            if (!result)
            {
                Log.ErrorLine("Failed to build conjure-xamarin-android-cecil");
                return(false);
            }

            StatusStep(context, "Conjuring Xamarin.Android.Cecil and Xamari.Android.Cecil.Mdb");
            string conjurer          = Path.Combine(Configurables.Paths.BuildBinDir, "conjure-xamarin-android-cecil.exe");
            string conjurerSourceDir = Configurables.Paths.MonoProfileToolsDir;
            string conjurerDestDir   = Configurables.Paths.BuildBinDir;

            result = Utilities.RunCommand(
                haveManagedRuntime ? managedRuntime : conjurer, // command
                BuildPaths.XamarinAndroidSourceRoot,            // workingDirectory
                true,                                           // ignoreEmptyArguments

                // arguments
                haveManagedRuntime ? conjurer : String.Empty,
                Configurables.Paths.MonoProfileToolsDir,        // source dir
                Configurables.Paths.BuildBinDir                 // destination dir
                );

            StatusStep(context, "Re-signing Xamarin.Android.Cecil.dll");
            var    sn           = new SnRunner(context);
            string snkPath      = Path.Combine(BuildPaths.XamarinAndroidSourceRoot, "mono.snk");
            string assemblyPath = Path.Combine(Configurables.Paths.BuildBinDir, "Xamarin.Android.Cecil.dll");

            result = await sn.ReSign(snkPath, assemblyPath, $"sign-xamarin-android-cecil");

            if (!result)
            {
                Log.ErrorLine("Failed to re-sign Xamarin.Android.Cecil.dll");
                return(false);
            }

            Utilities.CreateDirectory(Configurables.Paths.NetCoreBinDir);
            Utilities.CopyFile(assemblyPath, Path.Combine(Configurables.Paths.NetCoreBinDir, "Xamarin.Android.Cecil.dll"));

            StatusStep(context, "Re-signing Xamarin.Android.Cecil.Mdb.dll");
            assemblyPath = Path.Combine(Configurables.Paths.BuildBinDir, "Xamarin.Android.Cecil.Mdb.dll");
            result       = await sn.ReSign(snkPath, assemblyPath, $"sign-xamarin-android-cecil-mdb");

            if (!result)
            {
                Log.ErrorLine("Failed to re-sign Xamarin.Android.Cecil.Mdb.dll");
                return(false);
            }

            Utilities.CopyFile(assemblyPath, Path.Combine(Configurables.Paths.NetCoreBinDir, "Xamarin.Android.Cecil.Mdb.dll"));

            return(true);
        }
Esempio n. 11
0
        async Task <(bool disabled, bool success)> ConfigureBuildAndInstall(Context context, string abiName)
        {
            if (!context.IsHostJitAbiEnabled(abiName))
            {
                Log.DebugLine($"Windows target {abiName} disabled, not building libzip");
                return(true, true);
            }

            bool   sixtyFourBit = context.Is64BitMingwHostAbi(abiName);
            string sourceDir    = context.Properties.GetRequiredValue(KnownProperties.LibZipSourceFullPath);
            string buildDir     = Path.Combine(Configurables.Paths.BuildBinDir, $"libzip-windows-{abiName}");
            string stampFile    = Path.Combine(buildDir, $".build-{context.BuildInfo.FullLibZipHash}");
            string outputPath;

            if (sixtyFourBit)
            {
                outputPath = Path.Combine("x64", LibZipName);
            }
            else
            {
                outputPath = LibZipName;
            }

            string sourceFile = Path.Combine(buildDir, "lib", LibZipName);
            string destFile   = Path.Combine(Configurables.Paths.LibZipOutputPath, outputPath);
            bool   needBuild;

            if (Utilities.FileExists(stampFile) && Utilities.FileExists(sourceFile))
            {
                Log.DebugLine($"LibZip-Windows build stamp file exists: {stampFile}");
                Log.StatusLine($"LibZip for {abiName} already built, skipping compilation");
                needBuild = false;
            }
            else
            {
                needBuild = true;
            }

            if (needBuild)
            {
                Utilities.DeleteDirectorySilent(buildDir);
                Utilities.CreateDirectory(buildDir);
                List <string> arguments = GetCmakeArguments(context, buildDir, sixtyFourBit);

                string logTag = $"libzip-windows-{abiName}";
                var    cmake  = new CMakeRunner(context);
                bool   result = await cmake.Run(
                    logTag : logTag,
                    sourceDirectory : sourceDir,
                    workingDirectory : buildDir,
                    arguments : arguments
                    );

                if (!result)
                {
                    return(false, false);
                }

                var ninja = new NinjaRunner(context);
                result = await ninja.Run(
                    logTag : logTag,
                    workingDirectory : buildDir
                    );

                if (!result)
                {
                    return(false, false);
                }
            }

            Utilities.CopyFile(sourceFile, destFile);

            if (!File.Exists(destFile))
            {
                Log.ErrorLine($"Failed to copy {sourceFile} to {destFile}");
                return(false, false);
            }

            TouchStampFile(stampFile);
            return(false, true);
        }