Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bazci: tweak how we find the testlogs dir for go_transition_test #76323

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions pkg/cmd/bazci/bazci.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/alessio/shellescape"
Expand Down Expand Up @@ -208,32 +207,28 @@ func getBuildInfo(args parsedArgs) (buildInfo, error) {
case "go_test":
ret.tests = append(ret.tests, fullTarget)
case "go_transition_test":
// Run cquery to get the hash of the config.
res, err := runBazelReturningStdout("cquery", fullTarget, "--output=label_kind")
// These tests have their own special testlogs directory.
// We can find it by finding the location of the binary
// and munging it a bit.
args := []string{fullTarget, "-c", compilationMode, "--run_under=realpath"}
args = append(args, configArgList()...)
runOutput, err := runBazelReturningStdout("run", args...)
if err != nil {
return buildInfo{}, err
}
configHash := strings.Fields(res)[3]
// The hash will start be surrounded with (), so trim those.
configHash = strings.TrimPrefix(configHash, "(")
configHash = strings.TrimSuffix(configHash, ")")
res, err = runBazelReturningStdout("config", configHash)
if err != nil {
return buildInfo{}, err
}
var testlogsDir string
for _, line := range strings.Split(res, "\n") {
if strings.Contains(line, "transition directory name fragment") {
fragmentLine := strings.Split(line, ":")
fragment := strings.TrimSpace(fragmentLine[1])
testlogsDir = filepath.Join(filepath.Dir(ret.testlogsDir)+"-"+fragment, filepath.Base(ret.testlogsDir))
break
var binLocation string
for _, line := range strings.Split(runOutput, "\n") {
if strings.HasPrefix(line, "/") {
// NB: We want the last line in the output that starts with /.
binLocation = strings.TrimSpace(line)
}
}
if testlogsDir == "" {
return buildInfo{}, errors.Newf("could not find transition directory name fragment for target %s", fullTarget)
}
ret.transitionTests[fullTarget] = testlogsDir
componentsBinLocation := strings.Split(binLocation, "/")
componentsTestlogs := strings.Split(testlogsDir, "/")
// The second to last component will be the one we need
// to replace (it's the output directory for the configuration).
componentsTestlogs[len(componentsTestlogs)-2] = componentsBinLocation[len(componentsTestlogs)-2]
ret.transitionTests[fullTarget] = strings.Join(componentsTestlogs, "/")
case "test_suite":
// Expand the list of tests from the test suite with another query.
allTests, err := runBazelReturningStdout("query", "tests("+fullTarget+")")
Expand Down