Esempio n. 1
0
        void DetermineMonoHash(Context context)
        {
            GitRunner git = CreateGitRunner(context);

            Log.StatusLine($"  {context.Characters.Bullet} Mono commit hash", ConsoleColor.Gray);
            List <ExternalGitDependency> externalDependencies = ExternalGitDependency.GetDependencies(context, Configurables.Paths.ExternalGitDepsFilePath, quiet: true);
            ExternalGitDependency        mono = externalDependencies?.Where(
                eg => eg != null &&
                String.Compare("mono", eg.Owner, StringComparison.Ordinal) == 0 &&
                String.Compare("mono", eg.Name, StringComparison.Ordinal) == 0).FirstOrDefault();

            FullMonoHash = mono?.Commit?.Trim();
            MonoHash     = EnsureHash("Mono", Utilities.ShortenGitHash(FullMonoHash));

            string EnsureHash(string name, string hash)
            {
                if (String.IsNullOrEmpty(hash))
                {
                    throw new InvalidOperationException($"Unable to determine {name} commit hash");
                }
                Log.StatusLine("    Commit: ", hash, tailColor: ConsoleColor.Cyan);
                Log.StatusLine();

                return(hash);
            }
        }
        void DetermineBundleHashes(Context context)
        {
            GitRunner git = CreateGitRunner(context);

            Log.StatusLine($"  {context.Characters.Bullet} LibZip commit hash", ConsoleColor.Gray);
            FullLibZipHash = git.GetTopCommitHash(context.Properties.GetRequiredValue(KnownProperties.LibZipSourceFullPath), shortHash: false);
            LibZipHash     = EnsureHash("LibZip", Utilities.ShortenGitHash(FullLibZipHash));

            Log.StatusLine($"  {context.Characters.Bullet} Mono commit hash", ConsoleColor.Gray);
            List <ExternalGitDependency> externalDependencies = ExternalGitDependency.GetDependencies(context, Configurables.Paths.ExternalGitDepsFilePath, quiet: true);
            ExternalGitDependency        mono = externalDependencies?.Where(
                eg => eg != null &&
                String.Compare("mono", eg.Owner, StringComparison.Ordinal) == 0 &&
                String.Compare("mono", eg.Name, StringComparison.Ordinal) == 0).FirstOrDefault();

            FullMonoHash = mono?.Commit?.Trim();
            MonoHash     = EnsureHash("Mono", Utilities.ShortenGitHash(FullMonoHash));

            if (Configurables.Paths.BundleVersionHashFiles == null || Configurables.Paths.BundleVersionHashFiles.Count == 0)
            {
                Log.WarningLine("Bundle version hash files not specified");
                return;
            }

            Log.StatusLine($"  {context.Characters.Bullet} Generating bundle version hash", ConsoleColor.Gray);
            using (var ha = HashAlgorithm.Create(context.HashAlgorithm)) {
                HashFiles(ha, Configurables.Paths.BundleVersionHashFiles);
                VersionHash = FormatHash(ha.Hash).Substring(0, (int)Configurables.Defaults.AbbreviatedHashLength);
                Log.StatusLine("    Hash: ", VersionHash, tailColor: ConsoleColor.Cyan);
            }

            string EnsureHash(string name, string hash)
            {
                if (String.IsNullOrEmpty(hash))
                {
                    throw new InvalidOperationException($"Unable to determine {name} commit hash");
                }
                Log.StatusLine("    Commit: ", hash, tailColor: ConsoleColor.Cyan);
                Log.StatusLine();

                return(hash);
            }
        }
Esempio n. 3
0
        protected override async Task <bool> Execute(Context context)
        {
            List <ExternalGitDependency> externalDependencies = ExternalGitDependency.GetDependencies(context, Configurables.Paths.ExternalGitDepsFilePath);

            bool failed = false;

            Log.StatusLine();
            Log.StatusLine("Updating external repositories");
            var git = new GitRunner(context)
            {
                EchoCmdAndArguments = false
            };

            foreach (ExternalGitDependency egd in externalDependencies)
            {
                Log.StatusLine($"  {context.Characters.Bullet} {egd.Name}");
                string destDir = Path.Combine(Configurables.Paths.ExternalGitDepsDestDir, egd.Name);
                if (!Directory.Exists(destDir))
                {
                    var egdUrl = await GetGitHubURL(egd, git);

                    Log.StatusLine($"    {context.Characters.Link} cloning from {egd.Owner}/{egd.Name}");
                    if (!await git.Clone(egdUrl, destDir))
                    {
                        Log.ErrorLine($"Failed to clone {egd.Name}");
                        failed = true;
                        continue;
                    }
                }

                Log.StatusLine($"    {context.Characters.Link} fetching changes from {egd.Owner}/{egd.Name}");
                if (!await git.Fetch(destDir))
                {
                    Log.ErrorLine($"Failed to fetch changes for {egd.Name}");
                    failed = true;
                    continue;
                }

                Log.StatusLine($"    {context.Characters.Bullet} checking out commit {egd.Commit}");
                if (!await git.CheckoutCommit(destDir, egd.Commit))
                {
                    Log.ErrorLine($"Failed to checkout commit {egd.Commit} for {egd.Name}");
                    failed = true;
                    continue;
                }

                //
                // Commented out for now because we only have monodroid in .external and its submodules are updated
                // elsewhere and there's no need to duplicate the (time-consuming) work. However, it might be a good
                // idea to re-enable this code for the benefit of future .external additions (and, possibly, monodroid
                // itself after its integration code is updated to not initialize submodules)
                //

                // string gitModules = Path.Combine (destDir, ".gitmodules");
                // if (!Utilities.FileExists (gitModules))
                //  continue;

                // Log.StatusLine ($"    {context.Characters.Bullet} updating submodules");
                // if (!await git.SubmoduleUpdate (destDir)) {
                //  Log.ErrorLine ($"Failed to update submodules for {egd.Name}");
                //  failed = true;
                // }
            }

            return(!failed);
        }