예제 #1
0
        public void UseCompiler(Action <CompilerOption> option = null)
        {
            var compilerOption = new CompilerOption();

            option?.Invoke(compilerOption);
            buildOption.CompilerOption = compilerOption;
        }
예제 #2
0
        private async Task <(bool IsSucceeded, string Logs)> Compile(CompilerOption compiler, List <string> extra)
        {
            try
            {
                extra?.ForEach(i => File.Copy(i, Path.Combine(_workingdir, Path.GetFileName(i)), true));
            }
            catch
            {
                return(false, "Cannot copy one of extra files");
            }

            using (var comp = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    Arguments = compiler.Args,
                    ErrorDialog = false,
                    FileName = compiler.Exec,
                    RedirectStandardError = compiler.ReadStdError,
                    RedirectStandardOutput = compiler.ReadStdOutput,
                    UseShellExecute = false,
                    WorkingDirectory = _workingdir
                }
            })
            {
                try
                {
                    comp.Start();

                    StringBuilder output = new StringBuilder();
                    if (!comp.WaitForExit(30 * 1000))
                    {
                        try
                        {
                            comp.Kill();
                        }
                        catch
                        {
                            /* ignored */
                        }
                    }

                    if (compiler.ReadStdOutput)
                    {
                        var temp = (await comp.StandardOutput.ReadToEndAsync()).Trim();
                        if (!string.IsNullOrWhiteSpace(temp))
                        {
                            output.AppendLine(temp);
                        }
                    }

                    if (compiler.ReadStdError)
                    {
                        var temp = (await comp.StandardError.ReadToEndAsync()).Trim();
                        if (!string.IsNullOrWhiteSpace(temp))
                        {
                            output.AppendLine(temp);
                        }
                    }

                    var log = MatchProblem(output.ToString(), compiler.ProblemMatcher)
                              .Replace(_workingdir, "...")
                              .Replace(_workingdir.Replace("/", "\\"), "...");
                    try
                    {
                        comp.Kill();
                    }
                    catch
                    {
                        /* ignored */
                    }

                    if (comp.ExitCode != 0 || !File.Exists(compiler.OutputFile))
                    {
                        return(false, log);
                    }

                    return(true, log);
                }
                catch (Exception ex)
                {
                    return(false, ex.Message);
                }
            }
        }