Skip to content

Commit

Permalink
Address more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jul 27, 2024
1 parent 6678250 commit 2136c07
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
4 changes: 2 additions & 2 deletions go/private/actions/compilepkg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def _run_nogo(
go.actions.run(
inputs = inputs,
outputs = outputs,
mnemonic = "GoNogo",
mnemonic = "RunNogo",
executable = go.toolchain._builder,
arguments = [args],
env = go.env_for_path_mapping,
Expand All @@ -282,7 +282,7 @@ def _run_nogo(
go.actions.run(
inputs = [out_log],
outputs = [out_validation],
mnemonic = "GoNogoValidation",
mnemonic = "ValidateNogo",
executable = go.toolchain._builder,
arguments = [validation_args],
execution_requirements = SUPPORTS_PATH_MAPPING_REQUIREMENT,
Expand Down
31 changes: 11 additions & 20 deletions go/tools/builders/nogo.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,33 +137,24 @@ func runNogo(workDir string, nogoPath string, srcs []string, facts []archive, pa
return fmt.Errorf("error creating nogo log file: %v", err)
}
defer outLog.Close()
err := cmd.Run()
err = cmd.Run()
if err == nil {
return nil
}
if exitErr, ok := err.(*exec.ExitError); ok {
if !exitErr.Exited() {
cmdLine := strings.Join(args, " ")
return fmt.Errorf("nogo command '%s' exited unexpectedly: %s", cmdLine, exitErr.String())
}
prettyOut := relativizePaths(out.Bytes())
if exitErr.ExitCode() != 2 {
return errors.New(string(prettyOut))
}
if !exitErr.Exited() {
cmdLine := strings.Join(args, " ")
return fmt.Errorf("nogo command '%s' exited unexpectedly: %s", cmdLine, exitErr.String())
}
prettyOut := relativizePaths(out.Bytes())
if exitErr.ExitCode() != 2 {
return errors.New(string(prettyOut))
}
// Do not fail the action if nogo has findings so that facts are
// still available for downstream targets.
_, err := outLog.Write(prettyOut)
if err != nil {
return fmt.Errorf("error writing nogo log file: %v", err)
}
} else {
return errors.New(string(prettyOut))
}
} else {
if out.Len() != 0 {
fmt.Fprintln(os.Stderr, out.String())
}
return fmt.Errorf("error running nogo: %v", err)
if err != nil {
return fmt.Errorf("error writing nogo log file: %v", err)
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion go/tools/builders/nogo_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func nogoValidation(args []string) error {
logFile := args[1]
// Always create the output file, but fail if the log file is non-empty, to
// avoid a "action failed to create outputs" error.
if err := os.WriteFile(validationOutput, []byte{}, 0644); err != nil {
if err := os.Symlink(logFile, validationOutput); err != nil {
return err
}

Expand Down

0 comments on commit 2136c07

Please sign in to comment.