From 22c32b40be54a9e4062655f90908f98b11e73966 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Wed, 17 Jul 2019 03:23:59 -0700 Subject: Add json mapping for command and commandResult. Also exports the fields on these structs so that json can read/write them. BUG=chromium:773875 TEST=unit test Change-Id: I0efead41693dd35548738a0b3a3e5c71c97c319c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1706790 Reviewed-by: George Burgess Tested-by: Tobias Bosch --- compiler_wrapper/bisect_flag.go | 6 +++--- compiler_wrapper/clang_flags.go | 4 ++-- compiler_wrapper/clang_syntax_flag.go | 6 +++--- compiler_wrapper/clang_tidy_flag.go | 12 +++++------ compiler_wrapper/command.go | 28 +++++++++++++------------- compiler_wrapper/compiler_wrapper_test.go | 4 ++-- compiler_wrapper/disable_werror_flag.go | 8 ++++---- compiler_wrapper/disable_werror_flag_test.go | 4 ++-- compiler_wrapper/env.go | 24 +++++++++++----------- compiler_wrapper/errors.go | 4 ++-- compiler_wrapper/errors_test.go | 4 ++-- compiler_wrapper/oldwrapper.go | 30 ++++++++++++++-------------- compiler_wrapper/oldwrapper_test.go | 12 +++++------ compiler_wrapper/print_cmdline_flag_test.go | 12 +++++------ compiler_wrapper/rusage_flag.go | 8 ++++---- compiler_wrapper/testutil_test.go | 26 ++++++++++++------------ compiler_wrapper/unsupported_flags.go | 2 +- 17 files changed, 97 insertions(+), 97 deletions(-) diff --git a/compiler_wrapper/bisect_flag.go b/compiler_wrapper/bisect_flag.go index eb96939a..9cab75bd 100644 --- a/compiler_wrapper/bisect_flag.go +++ b/compiler_wrapper/bisect_flag.go @@ -13,13 +13,13 @@ func calcBisectCommand(env env, bisectStage string, compilerCmd *command) *comma } absCompilerPath := getAbsCmdPath(env, compilerCmd) return &command{ - path: "/usr/bin/python2", - args: append([]string{ + Path: "/usr/bin/python2", + Args: append([]string{ "-c", bisectPythonCommand, bisectStage, bisectDir, absCompilerPath, - }, compilerCmd.args...), + }, compilerCmd.Args...), } } diff --git a/compiler_wrapper/clang_flags.go b/compiler_wrapper/clang_flags.go index 2b158e88..3d15d972 100644 --- a/compiler_wrapper/clang_flags.go +++ b/compiler_wrapper/clang_flags.go @@ -149,8 +149,8 @@ func processClangFlags(builder *commandBuilder) error { func getClangResourceDir(env env, clangPath string) (string, error) { readResourceCmd := &command{ - path: clangPath, - args: []string{"--print-resource-dir"}, + Path: clangPath, + Args: []string{"--print-resource-dir"}, } stdoutBuffer := bytes.Buffer{} if err := env.run(readResourceCmd, &stdoutBuffer, env.stderr()); err != nil { diff --git a/compiler_wrapper/clang_syntax_flag.go b/compiler_wrapper/clang_syntax_flag.go index 5ea1cca1..e36607b4 100644 --- a/compiler_wrapper/clang_syntax_flag.go +++ b/compiler_wrapper/clang_syntax_flag.go @@ -13,9 +13,9 @@ func processClangSyntaxFlag(builder *commandBuilder) (clangSyntax bool) { func checkClangSyntax(env env, clangCmd *command) (exitCode int, err error) { clangSyntaxCmd := &command{ - path: clangCmd.path, - args: append(clangCmd.args, "-fsyntax-only", "-stdlib=libstdc++"), - envUpdates: clangCmd.envUpdates, + Path: clangCmd.Path, + Args: append(clangCmd.Args, "-fsyntax-only", "-stdlib=libstdc++"), + EnvUpdates: clangCmd.EnvUpdates, } return wrapSubprocessErrorWithSourceLoc(clangSyntaxCmd, env.run(clangSyntaxCmd, env.stdout(), env.stderr())) diff --git a/compiler_wrapper/clang_tidy_flag.go b/compiler_wrapper/clang_tidy_flag.go index ce53cb51..bc4b7368 100644 --- a/compiler_wrapper/clang_tidy_flag.go +++ b/compiler_wrapper/clang_tidy_flag.go @@ -56,21 +56,21 @@ func runClangTidy(env env, clangCmd *command, cSrcFile string) error { "-readability-*", }, ",") - resourceDir, err := getClangResourceDir(env, clangCmd.path) + resourceDir, err := getClangResourceDir(env, clangCmd.Path) if err != nil { return err } - clangTidyPath := filepath.Join(filepath.Dir(clangCmd.path), "clang-tidy") + clangTidyPath := filepath.Join(filepath.Dir(clangCmd.Path), "clang-tidy") clangTidyCmd := &command{ - path: clangTidyPath, - args: append([]string{ + Path: clangTidyPath, + Args: append([]string{ "-checks=" + defaultTidyChecks, cSrcFile, "--", "-resource-dir=" + resourceDir, - }, clangCmd.args...), - envUpdates: clangCmd.envUpdates, + }, clangCmd.Args...), + EnvUpdates: clangCmd.EnvUpdates, } exitCode, err := wrapSubprocessErrorWithSourceLoc(clangTidyCmd, diff --git a/compiler_wrapper/command.go b/compiler_wrapper/command.go index 4e44e1a7..15e1d32b 100644 --- a/compiler_wrapper/command.go +++ b/compiler_wrapper/command.go @@ -8,21 +8,21 @@ import ( ) type command struct { - path string - args []string - envUpdates []string + Path string `json:"path"` + Args []string `json:"args"` + EnvUpdates []string `json:"env_updates,omitempty"` } func newProcessCommand() *command { return &command{ - path: os.Args[0], - args: os.Args[1:], + Path: os.Args[0], + Args: os.Args[1:], } } func newExecCmd(env env, cmd *command) *exec.Cmd { - execCmd := exec.Command(cmd.path, cmd.args...) - execCmd.Env = append(env.environ(), cmd.envUpdates...) + execCmd := exec.Command(cmd.Path, cmd.Args...) + execCmd.Env = append(env.environ(), cmd.EnvUpdates...) ensurePathEnv(execCmd) execCmd.Dir = env.getwd() return execCmd @@ -38,7 +38,7 @@ func ensurePathEnv(cmd *exec.Cmd) { } func getAbsCmdPath(env env, cmd *command) string { - path := cmd.path + path := cmd.Path if !filepath.IsAbs(path) { path = filepath.Join(env.getwd(), path) } @@ -46,7 +46,7 @@ func getAbsCmdPath(env env, cmd *command) string { } func newCommandBuilder(env env, cfg *config, cmd *command) (*commandBuilder, error) { - basename := filepath.Base(cmd.path) + basename := filepath.Base(cmd.Path) nameParts := strings.Split(basename, "-") if len(nameParts) != 5 { return nil, newErrorwithSourceLocf("expected 5 parts in the compiler name. Actual: %s", basename) @@ -66,8 +66,8 @@ func newCommandBuilder(env env, cfg *config, cmd *command) (*commandBuilder, err } rootPath := filepath.Join(absWrapperDir, cfg.rootRelPath) return &commandBuilder{ - path: cmd.path, - args: createBuilderArgs( /*fromUser=*/ true, cmd.args), + path: cmd.Path, + args: createBuilderArgs( /*fromUser=*/ true, cmd.Args), env: env, cfg: cfg, rootPath: rootPath, @@ -180,8 +180,8 @@ func (builder *commandBuilder) build() *command { cmdArgs[i] = builderArg.value } return &command{ - path: builder.path, - args: cmdArgs, - envUpdates: builder.envUpdates, + Path: builder.path, + Args: cmdArgs, + EnvUpdates: builder.envUpdates, } } diff --git a/compiler_wrapper/compiler_wrapper_test.go b/compiler_wrapper/compiler_wrapper_test.go index 5e347ec1..ccab1b37 100644 --- a/compiler_wrapper/compiler_wrapper_test.go +++ b/compiler_wrapper/compiler_wrapper_test.go @@ -104,8 +104,8 @@ func TestLogExitCodeErrorWhenComparingToOldWrapper(t *testing.T) { writeMockWrapper(ctx, &mockWrapperConfig{ Cmds: []*mockWrapperCmd{ { - Path: cmd.path, - Args: cmd.args, + Path: cmd.Path, + Args: cmd.Args, ExitCode: 2, }, }, diff --git a/compiler_wrapper/disable_werror_flag.go b/compiler_wrapper/disable_werror_flag.go index 28b257b0..e4037bad 100644 --- a/compiler_wrapper/disable_werror_flag.go +++ b/compiler_wrapper/disable_werror_flag.go @@ -31,9 +31,9 @@ func doubleBuildWithWNoError(env env, cfg *config, originalCmd *command) (exitCo retryStdoutBuffer := &bytes.Buffer{} retryStderrBuffer := &bytes.Buffer{} retryCommand := &command{ - path: originalCmd.path, - args: append(originalCmd.args, "-Wno-error"), - envUpdates: originalCmd.envUpdates, + Path: originalCmd.Path, + Args: append(originalCmd.Args, "-Wno-error"), + EnvUpdates: originalCmd.EnvUpdates, } retryExitCode, err := wrapSubprocessErrorWithSourceLoc(retryCommand, env.run(retryCommand, retryStdoutBuffer, retryStderrBuffer)) @@ -84,7 +84,7 @@ func doubleBuildWithWNoError(env env, cfg *config, originalCmd *command) (exitCo jsonData := warningsJSONData{ Cwd: env.getwd(), - Command: append([]string{originalCmd.path}, originalCmd.args...), + Command: append([]string{originalCmd.Path}, originalCmd.Args...), Stdout: outputToLog, } enc := json.NewEncoder(tmpFile) diff --git a/compiler_wrapper/disable_werror_flag_test.go b/compiler_wrapper/disable_werror_flag_test.go index d9f1758b..affd8875 100644 --- a/compiler_wrapper/disable_werror_flag_test.go +++ b/compiler_wrapper/disable_werror_flag_test.go @@ -185,8 +185,8 @@ func TestLogWarningsWhenDoubleBuildSucceeds(t *testing.T) { t.Fatalf("unexpected cwd. Got: %s", loggedWarnings.Cwd) } loggedCmd := &command{ - path: loggedWarnings.Command[0], - args: loggedWarnings.Command[1:], + Path: loggedWarnings.Command[0], + Args: loggedWarnings.Command[1:], } if err := verifyPath(loggedCmd, "usr/bin/clang"); err != nil { t.Error(err) diff --git a/compiler_wrapper/env.go b/compiler_wrapper/env.go index 600366c4..2bafaf3d 100644 --- a/compiler_wrapper/env.go +++ b/compiler_wrapper/env.go @@ -70,10 +70,10 @@ type commandRecordingEnv struct { cmdResults []*commandResult } type commandResult struct { - cmd *command - stdout string - stderr string - exitCode int + Cmd *command `json:"cmd"` + Stdout string `json:"stdout,omitempty"` + Stderr string `json:"stderr,omitempty"` + ExitCode int `json:"exitcode,omitempty"` } var _ env = (*commandRecordingEnv)(nil) @@ -90,10 +90,10 @@ func (env *commandRecordingEnv) run(cmd *command, stdout io.Writer, stderr io.Wr err := env.env.run(cmd, io.MultiWriter(stdout, stdoutBuffer), io.MultiWriter(stderr, stderrBuffer)) if exitCode, ok := getExitCode(err); ok { env.cmdResults = append(env.cmdResults, &commandResult{ - cmd: cmd, - stdout: stdoutBuffer.String(), - stderr: stderrBuffer.String(), - exitCode: exitCode, + Cmd: cmd, + Stdout: stdoutBuffer.String(), + Stderr: stderrBuffer.String(), + ExitCode: exitCode, }) } return err @@ -117,12 +117,12 @@ func (env *printingEnv) run(cmd *command, stdout io.Writer, stderr io.Writer) er func printCmd(env env, cmd *command) { fmt.Fprintf(env.stderr(), "cd '%s' &&", env.getwd()) - if len(cmd.envUpdates) > 0 { - fmt.Fprintf(env.stderr(), " env '%s'", strings.Join(cmd.envUpdates, "' '")) + if len(cmd.EnvUpdates) > 0 { + fmt.Fprintf(env.stderr(), " env '%s'", strings.Join(cmd.EnvUpdates, "' '")) } fmt.Fprintf(env.stderr(), " '%s'", getAbsCmdPath(env, cmd)) - if len(cmd.args) > 0 { - fmt.Fprintf(env.stderr(), " '%s'", strings.Join(cmd.args, "' '")) + if len(cmd.Args) > 0 { + fmt.Fprintf(env.stderr(), " '%s'", strings.Join(cmd.Args, "' '")) } io.WriteString(env.stderr(), "\n") } diff --git a/compiler_wrapper/errors.go b/compiler_wrapper/errors.go index 7095e37d..8cf96344 100644 --- a/compiler_wrapper/errors.go +++ b/compiler_wrapper/errors.go @@ -72,10 +72,10 @@ func getExitCode(err error) (exitCode int, ok bool) { func getCCacheError(compilerCmd *command, compilerCmdErr error) (ccacheErr userError, ok bool) { if en, ok := compilerCmdErr.(syscall.Errno); ok && en == syscall.ENOENT && - strings.Contains(compilerCmd.path, "ccache") { + strings.Contains(compilerCmd.Path, "ccache") { ccacheErr = newUserErrorf("ccache not found under %s. Please install it", - compilerCmd.path) + compilerCmd.Path) return ccacheErr, true } return ccacheErr, false diff --git a/compiler_wrapper/errors_test.go b/compiler_wrapper/errors_test.go index 29c941df..979f2d33 100644 --- a/compiler_wrapper/errors_test.go +++ b/compiler_wrapper/errors_test.go @@ -50,7 +50,7 @@ func TestSubprocessExitCodeError(t *testing.T) { } func TestSubprocessCCacheError(t *testing.T) { - _, err := wrapSubprocessErrorWithSourceLoc(&command{path: "/usr/bin/ccache"}, syscall.ENOENT) + _, err := wrapSubprocessErrorWithSourceLoc(&command{Path: "/usr/bin/ccache"}, syscall.ENOENT) if _, ok := err.(userError); !ok { t.Errorf("unexpected error type. Got: %T", err) } @@ -60,7 +60,7 @@ func TestSubprocessCCacheError(t *testing.T) { } func TestSubprocessGeneralError(t *testing.T) { - cmd := &command{path: "somepath"} + cmd := &command{Path: "somepath"} _, err := wrapSubprocessErrorWithSourceLoc(cmd, errors.New("someerror")) if err.Error() != fmt.Sprintf("errors_test.go:64: failed to execute %#v: someerror", cmd) { t.Errorf("Error message incorrect. Got: %s", err.Error()) diff --git a/compiler_wrapper/oldwrapper.go b/compiler_wrapper/oldwrapper.go index 514c413a..315e6ea8 100644 --- a/compiler_wrapper/oldwrapper.go +++ b/compiler_wrapper/oldwrapper.go @@ -25,11 +25,11 @@ func compareToOldWrapper(env env, cfg *config, inputCmd *command, newCmdResults newCmds := []*command{} for _, cmdResult := range newCmdResults { oldWrapperCfg.CmdResults = append(oldWrapperCfg.CmdResults, oldWrapperCmdResult{ - Stdout: cmdResult.stdout, - Stderr: cmdResult.stderr, - Exitcode: cmdResult.exitCode, + Stdout: cmdResult.Stdout, + Stderr: cmdResult.Stderr, + Exitcode: cmdResult.ExitCode, }) - newCmds = append(newCmds, cmdResult.cmd) + newCmds = append(newCmds, cmdResult.Cmd) } oldWrapperCfg.OverwriteConfig = cfg.overwriteOldWrapperCfg @@ -75,9 +75,9 @@ func parseOldWrapperCommands(stderr string) (cmds []*command, remainingStderr st envUpdate = nil } cmd := &command{ - path: args[0], - args: args[1:], - envUpdates: envUpdate, + Path: args[0], + Args: args[1:], + EnvUpdates: envUpdate, } cmds = append(cmds, cmd) } else { @@ -105,19 +105,19 @@ func diffCommands(oldCmds []*command, newCmds []*command) string { newCmd := newCmds[i] oldCmd := oldCmds[i] - if newCmd.path != oldCmd.path { + if newCmd.Path != oldCmd.Path { differences = append(differences, "path") } - if !reflect.DeepEqual(newCmd.args, oldCmd.args) { + if !reflect.DeepEqual(newCmd.Args, oldCmd.Args) { differences = append(differences, "args") } // Sort the environment as we don't care in which order // it was modified. - newEnvUpdates := newCmd.envUpdates + newEnvUpdates := newCmd.EnvUpdates sort.Strings(newEnvUpdates) - oldEnvUpdates := oldCmd.envUpdates + oldEnvUpdates := oldCmd.EnvUpdates sort.Strings(oldEnvUpdates) if !reflect.DeepEqual(newEnvUpdates, oldEnvUpdates) { @@ -191,7 +191,7 @@ func newOldWrapperConfig(env env, cfg *config, inputCmd *command) (*oldWrapperCo } return &oldWrapperConfig{ - CmdPath: inputCmd.path, + CmdPath: inputCmd.Path, OldWrapperContent: oldWrapperContent, RootRelPath: cfg.rootRelPath, CommonFlags: cfg.commonFlags, @@ -305,9 +305,9 @@ sys.exit(main()) // Note: Using a self executable wrapper does not work due to a race condition // on unix systems. See https://github.com/golang/go/issues/22315 oldWrapperCmd := &command{ - path: "/usr/bin/python2", - args: append([]string{"-S", mockFile.Name()}, inputCmd.args...), - envUpdates: inputCmd.envUpdates, + Path: "/usr/bin/python2", + Args: append([]string{"-S", mockFile.Name()}, inputCmd.Args...), + EnvUpdates: inputCmd.EnvUpdates, } return wrapSubprocessErrorWithSourceLoc(oldWrapperCmd, env.run(oldWrapperCmd, stdout, stderr)) } diff --git a/compiler_wrapper/oldwrapper_test.go b/compiler_wrapper/oldwrapper_test.go index f8432b11..665e48be 100644 --- a/compiler_wrapper/oldwrapper_test.go +++ b/compiler_wrapper/oldwrapper_test.go @@ -31,8 +31,8 @@ func TestCompareToOldWrapperCompilerCommand(t *testing.T) { writeMockWrapper(ctx, &mockWrapperConfig{ Cmds: []*mockWrapperCmd{ { - Path: cmd.path + pathSuffix, - Args: append(cmd.args, extraArgs...), + Path: cmd.Path + pathSuffix, + Args: append(cmd.Args, extraArgs...), ExitCode: exitCode, }, }, @@ -93,13 +93,13 @@ func TestCompareToOldWrapperNestedCommand(t *testing.T) { var wrapperCmd *mockWrapperCmd if isNestedCmd { wrapperCmd = &mockWrapperCmd{ - Path: cmd.path + pathSuffix, - Args: append(cmd.args, extraArgs...), + Path: cmd.Path + pathSuffix, + Args: append(cmd.Args, extraArgs...), } } else { wrapperCmd = &mockWrapperCmd{ - Path: cmd.path, - Args: cmd.args, + Path: cmd.Path, + Args: cmd.Args, } } wrapperCfg.Cmds = append(wrapperCfg.Cmds, wrapperCmd) diff --git a/compiler_wrapper/print_cmdline_flag_test.go b/compiler_wrapper/print_cmdline_flag_test.go index f3ccd723..e42a2b95 100644 --- a/compiler_wrapper/print_cmdline_flag_test.go +++ b/compiler_wrapper/print_cmdline_flag_test.go @@ -37,7 +37,7 @@ func TestPrintNestedCommand(t *testing.T) { func TestPrintCmdWd(t *testing.T) { withTestContext(t, func(ctx *testContext) { printCmd(ctx, &command{ - path: "/somepath", + Path: "/somepath", }) if ctx.stderrString() != fmt.Sprintf("cd '%s' && '/somepath'\n", ctx.tempDir) { t.Errorf("unexpected result. Got: %s", ctx.stderrString()) @@ -48,7 +48,7 @@ func TestPrintCmdWd(t *testing.T) { func TestPrintCmdAbsolutePath(t *testing.T) { withTestContext(t, func(ctx *testContext) { printCmd(ctx, &command{ - path: "somepath", + Path: "somepath", }) if ctx.stderrString() != fmt.Sprintf("cd '%s' && '%s/somepath'\n", ctx.tempDir, ctx.tempDir) { t.Errorf("unexpected result. Got: %s", ctx.stderrString()) @@ -59,8 +59,8 @@ func TestPrintCmdAbsolutePath(t *testing.T) { func TestPrintCmdEnvUpdates(t *testing.T) { withTestContext(t, func(ctx *testContext) { printCmd(ctx, &command{ - path: "/somepath", - envUpdates: []string{"a=b"}, + Path: "/somepath", + EnvUpdates: []string{"a=b"}, }) if ctx.stderrString() != fmt.Sprintf("cd '%s' && env 'a=b' '/somepath'\n", ctx.tempDir) { t.Errorf("unexpected result. Got: %s", ctx.stderrString()) @@ -71,8 +71,8 @@ func TestPrintCmdEnvUpdates(t *testing.T) { func TestPrintCmdArgs(t *testing.T) { withTestContext(t, func(ctx *testContext) { printCmd(ctx, &command{ - path: "/somepath", - args: []string{"-a"}, + Path: "/somepath", + Args: []string{"-a"}, }) if ctx.stderrString() != fmt.Sprintf("cd '%s' && '/somepath' '-a'\n", ctx.tempDir) { t.Errorf("unexpected result. Got: %s", ctx.stderrString()) diff --git a/compiler_wrapper/rusage_flag.go b/compiler_wrapper/rusage_flag.go index d336fc43..1cd56ae1 100644 --- a/compiler_wrapper/rusage_flag.go +++ b/compiler_wrapper/rusage_flag.go @@ -19,9 +19,9 @@ func logRusage(env env, logFileName string, compilerCmd *command) (exitCode int, return 0, err } compilerCmdWithoutRusage := &command{ - path: compilerCmd.path, - args: compilerCmd.args, - envUpdates: append(compilerCmd.envUpdates, "GETRUSAGE="), + Path: compilerCmd.Path, + Args: compilerCmd.Args, + EnvUpdates: append(compilerCmd.EnvUpdates, "GETRUSAGE="), } startTime := time.Now() exitCode, err = wrapSubprocessErrorWithSourceLoc(compilerCmdWithoutRusage, @@ -53,7 +53,7 @@ func logRusage(env env, logFileName string, compilerCmd *command) (exitCode int, if _, err := fmt.Fprintf(logFile, "%.5f : %.5f : %.5f : %d : %s : %s\n", float64(elapsedRealTime)/timeUnit, float64(elapsedUserTime)/timeUnit, float64(elapsedSysTime)/timeUnit, maxMemUsed, absCompilerPath, - strings.Join(append([]string{filepath.Base(absCompilerPath)}, compilerCmd.args...), " ")); err != nil { + strings.Join(append([]string{filepath.Base(absCompilerPath)}, compilerCmd.Args...), " ")); err != nil { _ = logFile.Close() return 0, wrapErrorwithSourceLocf(err, "error writing rusage logfile %s", logFileName) } diff --git a/compiler_wrapper/testutil_test.go b/compiler_wrapper/testutil_test.go index 6a9557ff..07d84b36 100644 --- a/compiler_wrapper/testutil_test.go +++ b/compiler_wrapper/testutil_test.go @@ -156,8 +156,8 @@ func (ctx *testContext) newCommand(path string, args ...string) *command { // Needed as we are resolving symlinks which stats the wrapper file. ctx.writeFile(path, "") return &command{ - path: path, - args: args, + Path: path, + Args: args, } } @@ -184,8 +184,8 @@ func (ctx *testContext) symlink(oldname string, newname string) { func verifyPath(cmd *command, expectedRegex string) error { compiledRegex := regexp.MustCompile(matchFullString(expectedRegex)) - if !compiledRegex.MatchString(cmd.path) { - return fmt.Errorf("path does not match %s. Actual %s", expectedRegex, cmd.path) + if !compiledRegex.MatchString(cmd.Path) { + return fmt.Errorf("path does not match %s. Actual %s", expectedRegex, cmd.Path) } return nil } @@ -193,14 +193,14 @@ func verifyPath(cmd *command, expectedRegex string) error { func verifyArgCount(cmd *command, expectedCount int, expectedRegex string) error { compiledRegex := regexp.MustCompile(matchFullString(expectedRegex)) count := 0 - for _, arg := range cmd.args { + for _, arg := range cmd.Args { if compiledRegex.MatchString(arg) { count++ } } if count != expectedCount { return fmt.Errorf("expected %d matches for arg %s. All args: %s", - expectedCount, expectedRegex, cmd.args) + expectedCount, expectedRegex, cmd.Args) } return nil } @@ -211,7 +211,7 @@ func verifyArgOrder(cmd *command, expectedRegexes ...string) error { compiledRegexes = append(compiledRegexes, regexp.MustCompile(matchFullString(regex))) } expectedArgIndex := 0 - for _, arg := range cmd.args { + for _, arg := range cmd.Args { if expectedArgIndex == len(compiledRegexes) { break } else if compiledRegexes[expectedArgIndex].MatchString(arg) { @@ -220,29 +220,29 @@ func verifyArgOrder(cmd *command, expectedRegexes ...string) error { } if expectedArgIndex != len(expectedRegexes) { return fmt.Errorf("expected args %s in order. All args: %s", - expectedRegexes, cmd.args) + expectedRegexes, cmd.Args) } return nil } func verifyEnvUpdate(cmd *command, expectedRegex string) error { compiledRegex := regexp.MustCompile(matchFullString(expectedRegex)) - for _, update := range cmd.envUpdates { + for _, update := range cmd.EnvUpdates { if compiledRegex.MatchString(update) { return nil } } return fmt.Errorf("expected at least one match for env update %s. All env updates: %s", - expectedRegex, cmd.envUpdates) + expectedRegex, cmd.EnvUpdates) } func verifyNoEnvUpdate(cmd *command, expectedRegex string) error { compiledRegex := regexp.MustCompile(matchFullString(expectedRegex)) - updates := cmd.envUpdates + updates := cmd.EnvUpdates for _, update := range updates { if compiledRegex.MatchString(update) { return fmt.Errorf("expected no match for env update %s. All env updates: %s", - expectedRegex, cmd.envUpdates) + expectedRegex, cmd.EnvUpdates) } } return nil @@ -283,7 +283,7 @@ func newExitCodeError(exitCode int) error { } func isCompareToOldWrapperCmd(cmd *command) bool { - for _, arg := range cmd.args { + for _, arg := range cmd.Args { if strings.Contains(arg, compareToOldWrapperFilePattern) { return true } diff --git a/compiler_wrapper/unsupported_flags.go b/compiler_wrapper/unsupported_flags.go index 3e3e8cb5..9712f9fe 100644 --- a/compiler_wrapper/unsupported_flags.go +++ b/compiler_wrapper/unsupported_flags.go @@ -1,7 +1,7 @@ package main func checkUnsupportedFlags(cmd *command) error { - for _, arg := range cmd.args { + for _, arg := range cmd.Args { if arg == "-fstack-check" { return newUserErrorf(`option %q is not supported; crbug/485492`, arg) } -- cgit v1.2.3