diff options
| author | Spandan Das <spandandas@google.com> | 2023-06-16 23:35:55 +0000 |
|---|---|---|
| committer | Spandan Das <spandandas@google.com> | 2023-06-23 04:25:32 +0000 |
| commit | da724863da3c3f82edacbcaa00d2441d5c8506fa (patch) | |
| tree | 60e1c48774ed77da6ca11e20c55e7af1a28e57cd /bazel | |
| parent | 3b7411adc792c912855cd8cab67152ad5b7f81cd (diff) | |
Respect '' received from aquery
GoCompilePkg action's aquery results contains ''. e.g (the interesting
ones)
```
/bin/bulder ... -embedroot '' -gcflags '' -asmflags ''
```
strings.Join would cause it to appear as a whitespace and cause issues.
(in ninja without this CL)
```
/bin/builder ... -embedroot -gcflags -asmflags
```
Convert the empty literal to '' before strings.Join
To limit inadvertent side-effects, this limits it to GoCompilePkg mnemonic
Test: TH
Change-Id: I67161c194dabac6f857ff49b85d4b2471970a9b2
Diffstat (limited to 'bazel')
| -rw-r--r-- | bazel/aquery.go | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/bazel/aquery.go b/bazel/aquery.go index 4d39e8f55..95e52ae73 100644 --- a/bazel/aquery.go +++ b/bazel/aquery.go @@ -453,8 +453,32 @@ func (a *aqueryArtifactHandler) depsetContentHashes(inputDepsetIds []uint32) ([] return hashes, nil } +// escapes the args received from aquery and creates a command string +func commandString(actionEntry *analysis_v2_proto.Action) string { + switch actionEntry.Mnemonic { + case "GoCompilePkg": + 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)) + } + } + return strings.Join(argsEscaped, " ") + default: + return strings.Join(proptools.ShellEscapeListIncludingSpaces(actionEntry.Arguments), " ") + } +} + func (a *aqueryArtifactHandler) normalActionBuildStatement(actionEntry *analysis_v2_proto.Action) (*BuildStatement, error) { - command := strings.Join(proptools.ShellEscapeListIncludingSpaces(actionEntry.Arguments), " ") + command := commandString(actionEntry) inputDepsetHashes, err := a.depsetContentHashes(actionEntry.InputDepSetIds) if err != nil { return nil, err |
