summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Cole Faust <colefaust@google.com> 2023-10-24 10:21:49 -0700
committer Cole Faust <colefaust@google.com> 2023-10-24 10:24:05 -0700
commitb378c18ddf0c6fc42af61bc644cac8a044904714 (patch)
tree8eaa0ad4d1bdffe7f5531b94c9fbd89f04159a2c
parentc70be4b986b0d2ec52c6a899b3c6d7fb0015b9bf (diff)
Simplify commandString
Use the same logic for both go and non-go actions. This also has a slight performance improvement for go actions by allocating the slice in advance instead of using append() Test: Presubmits Change-Id: I92b60c547d8470816a67ac1ef6e334fd5f547701
-rw-r--r--bazel/aquery.go31
1 files changed, 13 insertions, 18 deletions
diff --git a/bazel/aquery.go b/bazel/aquery.go
index 27ccb20c8..35942bc32 100644
--- a/bazel/aquery.go
+++ b/bazel/aquery.go
@@ -443,26 +443,21 @@ func (a *aqueryArtifactHandler) depsetContentHashes(inputDepsetIds []uint32) ([]
// escapes the args received from aquery and creates a command string
func commandString(actionEntry *analysis_v2_proto.Action) string {
- switch actionEntry.Mnemonic {
- case "GoCompilePkg", "GoStdlib":
- argsEscaped := []string{}
- for _, arg := range actionEntry.Arguments {
- if arg == "" {
- // If this is an empty string, add ''
- // And not
- // 1. (literal empty)
- // 2. `''\'''\'''` (escaped version of '')
- //
- // If we had used (1), then this would appear as a whitespace when we strings.Join
- argsEscaped = append(argsEscaped, "''")
- } else {
- argsEscaped = append(argsEscaped, proptools.ShellEscapeIncludingSpaces(arg))
- }
+ argsEscaped := make([]string, len(actionEntry.Arguments))
+ for i, arg := range actionEntry.Arguments {
+ if arg == "" {
+ // If this is an empty string, add ''
+ // And not
+ // 1. (literal empty)
+ // 2. `''\'''\'''` (escaped version of '')
+ //
+ // If we had used (1), then this would appear as a whitespace when we strings.Join
+ argsEscaped[i] = "''"
+ } else {
+ argsEscaped[i] = proptools.ShellEscapeIncludingSpaces(arg)
}
- return strings.Join(argsEscaped, " ")
- default:
- return strings.Join(proptools.ShellEscapeListIncludingSpaces(actionEntry.Arguments), " ")
}
+ return strings.Join(argsEscaped, " ")
}
func (a *aqueryArtifactHandler) normalActionBuildStatement(actionEntry *analysis_v2_proto.Action) (*BuildStatement, error) {