Example #1
0
        async Task <(bool success, string output)> CaptureAdbOutput(ProcessRunner runner, bool firstLineOnly = false)
        {
            string?       outputLine = null;
            List <string>?lines      = null;

            using (var outputSink = (OutputSink)SetupOutputSink(runner, ignoreStderr: true)) {
                outputSink.LineCallback = (string line) => {
                    if (firstLineOnly)
                    {
                        if (outputLine != null)
                        {
                            return;
                        }
                        outputLine = line.Trim();
                        return;
                    }

                    if (lines == null)
                    {
                        lines = new List <string> ();
                    }
                    lines.Add(line.Trim());
                };

                if (!await RunAdb(runner, setupOutputSink: false))
                {
                    return(false, String.Empty);
                }
            }

            if (firstLineOnly)
            {
                return(true, outputLine ?? String.Empty);
            }

            return(true, lines != null ? String.Join(Environment.NewLine, lines) : String.Empty);
        }
Example #2
0
        public async Task <bool> Install(string projectPath, string logBasePath, string targetFramework, string?configuration, List <string>?arguments = null)
        {
            ProcessRunner runner = CreateMSBuildRunner(forBinlog: false);
            string        cfg    = Utilities.FirstOf(configuration, Context.Configuration, Constants.DefaultConfiguration);

            runner
            .AddArgument("build")
            .AddArgument("-f")
            .AddQuotedArgument(targetFramework)
            .AddArgument("--no-restore")
            .AddArgument("--configuration")
            .AddQuotedArgument(cfg)
            .AddQuotedArgument($"/bl:{logBasePath}.binlog")
            .AddQuotedArgument("-t:Install");

            AddArguments(runner, arguments);
            runner.AddQuotedArgument(projectPath);

            string message = GetLogMessage(runner);

            Log.InfoLine(message);

            return(await RunMSBuild(runner));
        }
Example #3
0
        public async Task <Dictionary <string, string> > GetPropertiesFromBinlog(string logBasePath, HashSet <string> neededProperties)
        {
            var    ret        = new Dictionary <string, string> (StringComparer.Ordinal);
            string?binlogPath = GetBinLog(logBasePath);

            if (binlogPath == null)
            {
                return(ret);
            }

            bool echoOutputValue = EchoStandardOutput;

            EchoStandardOutput = false;
            try {
                ProcessRunner runner = CreateMSBuildRunner(forBinlog: true);
                runner.AddArgument("/v:diag");
                runner.AddQuotedArgument(binlogPath);

                bool propertiesStarted = false;
                int  propertiesFound   = 0;
                using (var outputSink = (OutputSink)SetupOutputSink(runner)) {
                    outputSink.SuppressOutput = true;
                    outputSink.LineCallback   = (string l) => {
                        string line = l.Trim();
                        if (!propertiesStarted)
                        {
                            propertiesStarted = line.EndsWith("Initial Properties:");
                            return;
                        }
                        else if (propertiesFound == neededProperties.Count)
                        {
                            return;
                        }

                        int idx = line.IndexOf('=');
                        if (idx < 0)
                        {
                            return;
                        }

                        string propName = line.Substring(0, idx - 1);
                        if (!neededProperties.Contains(propName))
                        {
                            return;
                        }

                        ret [propName] = line.Substring(idx + 1).Trim();
                        propertiesFound++;
                    };

                    if (!await RunMSBuild(runner, setupOutputSink: false))
                    {
                        return(ret);
                    }
                }
            } finally {
                EchoStandardOutput = echoOutputValue;
            }

            return(ret);
        }