public static List <ExternalGitDependency> GetDependencies(Context context, string externalFilePath)
        {
            Log.Instance.StatusLine($"  {context.Characters.Bullet} Reading external dependencies from {Utilities.GetRelativePath (BuildPaths.XamarinAndroidSourceRoot, externalFilePath)}");
            string[] unparsedExternals = File.ReadAllLines(externalFilePath);
            var      externals         = new List <ExternalGitDependency> (unparsedExternals.Length);

            foreach (string external in unparsedExternals)
            {
                Match match = externalRegex.Match(external);
                if (match != null && match.Success)
                {
                    if (match.Groups["comment"].Success)
                    {
                        // Ignore matching lines which start with '#'.
                        continue;
                    }

                    var e = new ExternalGitDependency {
                        Branch = match.Groups["branch"].Value,
                        Commit = match.Groups["commit"].Value,
                        Name   = match.Groups["repo"].Value,
                        Owner  = match.Groups["owner"].Value,
                    };
                    externals.Add(e);
                    Log.Instance.StatusLine($"    {context.Characters.Bullet} {e.Owner}/{e.Name} ({e.Commit})");
                }
            }

            return(externals);
        }
Пример #2
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);
            }
        }
Пример #3
0
        public static List <ExternalGitDependency> GetDependencies(Context context, string externalFilePath, bool quiet = false)
        {
            if (!quiet)
            {
                Log.Instance.StatusLine($"  {context.Characters.Bullet} Reading external dependencies from {Utilities.GetRelativePath (BuildPaths.XamarinAndroidSourceRoot, externalFilePath)}");
            }
            string[] unparsedExternals = File.ReadAllLines(externalFilePath);
            var      externals         = new List <ExternalGitDependency> (unparsedExternals.Length);
            bool     includeCommercial = context.CheckCondition(KnownConditions.IncludeCommercial);

            foreach (string external in unparsedExternals)
            {
                Match match = externalRegex.Match(external);
                if (match != null && match.Success)
                {
                    if (match.Groups["comment"].Success)
                    {
                        // Ignore matching lines which start with '#'.
                        continue;
                    }

                    string owner = match.Groups["owner"].Value;
                    string repo  = match.Groups["repo"].Value;
                    if (!includeCommercial && Configurables.Defaults.CommercialExternalDependencies.Contains($"{owner}/{repo}"))
                    {
                        Log.Instance.DebugLine($"Ignoring external commercial dependency '{owner}/{repo}'");
                        continue;
                    }

                    var e = new ExternalGitDependency {
                        Branch = match.Groups["branch"].Value,
                        Commit = match.Groups["commit"].Value,
                        Name   = repo,
                        Owner  = owner,
                    };
                    externals.Add(e);
                    if (!quiet)
                    {
                        Log.Instance.StatusLine($"    {context.Characters.Bullet} {e.Owner}/{e.Name} ({e.Commit})");
                    }
                }
            }

            return(externals);
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        async Task <string> GetGitHubURL(ExternalGitDependency egd, GitRunner git)
        {
            string ghToken = Environment.GetEnvironmentVariable("GH_AUTH_SECRET");

            if (!String.IsNullOrEmpty(ghToken))
            {
                return($"https://{ghToken}@github.com:/{egd.Owner}/{egd.Name}");
            }
            else
            {
                if (await git.IsRepoUrlHttps(BuildPaths.XamarinAndroidSourceRoot))
                {
                    return($"https://github.com:/{egd.Owner}/{egd.Name}");
                }
                else
                {
                    return($"[email protected]:/{egd.Owner}/{egd.Name}");
                }
            }
        }
Пример #6
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);
        }