Exemplo n.º 1
0
 void WriteDescription(StreamWriter sw, DateTime date, string configuration, XAVersionInfo xaVersion, AndroidDeviceInfo adi)
 {
     sw.WriteLine();
     sw.WriteLine($"Date (UTC): **{date}**  ");
     sw.WriteLine($"App configuration: **{configuration}**  ");
     sw.WriteLine();
     sw.WriteLine("Xamarin.Android  ");
     sw.WriteLine($"  - Version: **{xaVersion.Version}**  ");
     sw.WriteLine($"  - Branch: **{xaVersion.Branch}**  ");
     sw.WriteLine($"  - Commit: **{xaVersion.Commit}**  ");
     sw.WriteLine();
     sw.WriteLine("Device  ");
     sw.WriteLine($"  - Model: **{adi.Model}**  ");
     sw.WriteLine($"  - Native architecture: **{adi.Architecture}**  ");
     sw.WriteLine($"  - SDK version: **{adi.SdkVersion}**  ");
     sw.WriteLine();
 }
Exemplo n.º 2
0
        async Task <(bool, BuildInfo?)> BuildAndInstall(RunDefinition run)
        {
            if (projectUsesGit && projectGitCommit == null)
            {
                (projectGitCommit, projectGitBranch) = await GetCommitHashAndBranch(FullProjectDirPath);
            }

            string buildCommand = run.BuildCommand;
            bool   usesDotnet   = String.Compare("dotnet", Path.GetFileName(buildCommand), StringComparison.OrdinalIgnoreCase) == 0;

            var args = new List <string> {
                $"-v:quiet"
            };

            args.AddRange(run.Args);

            string        projectPath    = Path.GetRelativePath(FullProjectDirPath, FullProjectFilePath);
            string        binlogBasePath = String.Empty;
            MSBuildCommon builder;
            BuildInfo     buildInfo;

            if (!usesDotnet)
            {
                var msbuild = ConfigureRunner(new MSBuildRunner(context, buildCommand));
                binlogBasePath = GetBinlogBasePath("restore");
                if (!await msbuild.Run(projectPath, binlogBasePath, "Restore", configuration, args))
                {
                    return(false, null);
                }

                binlogBasePath = GetBinlogBasePath("build");
                run.BinlogPath = GetRelativeBinlogPath(binlogBasePath);

                if (!await msbuild.Run(projectPath, binlogBasePath, "SignAndroidPackage", configuration, args))
                {
                    return(false, null);
                }

                buildInfo = FindFirstAndroidBuildInfo(await msbuild.GetBuildInfo(binlogBasePath));
                await Uninstall(buildInfo);

                binlogBasePath = GetBinlogBasePath("install");
                if (!await msbuild.Run(projectPath, binlogBasePath, "Install", configuration, args))
                {
                    return(false, null);
                }

                builder = msbuild;
            }
            else
            {
                var dotnet = ConfigureRunner(new DotnetRunner(context, buildCommand));
                binlogBasePath = GetBinlogBasePath("build");
                run.BinlogPath = GetRelativeBinlogPath(binlogBasePath);
                if (!await dotnet.Build(projectPath, binlogBasePath, configuration, args))
                {
                    return(false, null);
                }

                buildInfo = FindFirstAndroidBuildInfo(await dotnet.GetBuildInfo(binlogBasePath));
                await Uninstall(buildInfo);

                binlogBasePath = GetBinlogBasePath("install");
                if (!await dotnet.Install(projectPath, binlogBasePath, buildInfo.TargetFramework, configuration, args))
                {
                    return(false, null);
                }

                builder = dotnet;
            }

            if (xaVersionNotDetectedYet)
            {
                const string NotGit = "not a git build";

                Log.InfoLine("Retrieving Xamarin.Android version information");
                xaVersion = await GetXAVersion(builder, binlogBasePath);

                Log.InfoLine($"    Location: {xaVersion.RootDir}");
                Log.InfoLine($"     Version: {xaVersion.Version}");

                string hash   = String.IsNullOrEmpty(xaVersion.Commit) ? NotGit : xaVersion.Commit;
                string branch = String.IsNullOrEmpty(xaVersion.Commit) ? NotGit : xaVersion.Branch;
                Log.InfoLine($"  Git branch: {branch}");
                Log.InfoLine($"  Git commit: {hash}");
                xaVersionNotDetectedYet = false;
            }

            return(true, buildInfo);

            async Task <bool> Uninstall(BuildInfo buildInfo)
            {
                (string packageName, _) = GetPackageAndMainActivityNames(buildInfo, run);

                var adb = new AdbRunner(context);

                return(await adb.Uninstall(packageName));
            }

            T ConfigureRunner <T> (T runner) where T : MSBuildCommon
            {
                runner.WorkingDirectory   = FullProjectDirPath;
                runner.EchoStandardOutput = true;
                runner.EchoStandardError  = true;
                return(runner);
            }

            string GetBinlogBasePath(string phase)
            {
                return(GetLogBasePath(Constants.MSBuildLogDir, phase, run.LogTag, projectGitCommit, projectGitBranch));
            }

            string GetRelativeBinlogPath(string binlogBasePath)
            {
                return(Path.GetRelativePath(FullDataDirectoryPath, $"{binlogBasePath}.binlog"));
            }
        }