Skip to content

Commit

Permalink
Allow ci_runner to install kythe (#6479)
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerwilliams authored May 1, 2024
1 parent 036c12c commit c8fc7dd
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions enterprise/server/cmd/ci_runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ const (
repoUserEnvVarName = "REPO_USER"
repoTokenEnvVarName = "REPO_TOKEN"

// Only set if --install_kythe is true.
kytheDirEnvVarName = "KYTHE_DIR"
kytheDirName = "kythe-v0.0.67"
kytheArchiveURL = "https://storage.googleapis.com/buildbuddy-tools/archives/kythe-v0.0.67.tar.gz"

// Exit code placeholder used when a command doesn't return an exit code on its own.
noExitCode = -1
failedExitCodeName = "Failed"
Expand Down Expand Up @@ -160,6 +165,7 @@ var (
bazelStartupFlags = flag.String("bazel_startup_flags", "", "Startup flags to pass to bazel. The value can include spaces and will be properly tokenized.")
extraBazelArgs = flag.String("extra_bazel_args", "", "Extra flags to pass to the bazel command. The value can include spaces and will be properly tokenized.")
debug = flag.Bool("debug", false, "Print additional debug information in the action logs.")
installKythe = flag.Bool("install_kythe", false, "If true, install kythe in the workspace root and set the KYTHE_DIR env var to the installed location")

// Test-only flags
fallbackToCleanCheckout = flag.Bool("fallback_to_clean_checkout", true, "Fallback to cloning the repo from scratch if sync fails (for testing purposes only).")
Expand Down Expand Up @@ -244,6 +250,25 @@ func provisionArtifactsDir(ws *workspace, bazelCommandIndex int) error {
return nil
}

func provisionKythe(ctx context.Context, ws *workspace) error {
kytheRootPath := filepath.Join(ws.rootDir, kytheDirName)
if _, err := os.Stat(kytheRootPath); err == nil {
return nil // dir already exists; we're done.
}
if err := os.MkdirAll(kytheRootPath, 0755); err != nil {
return err
}
cmd := fmt.Sprintf(`curl -sL "%s" | tar -xz -C %s --strip-components 1`, kytheArchiveURL, kytheRootPath)
args := []string{"-c", cmd}
if err := runCommand(ctx, "bash", args, nil /*=env*/, "" /*=dir*/, ws.log); err != nil {
return err
}
if err := os.Setenv(kytheDirEnvVarName, kytheRootPath); err != nil {
return err
}
return nil
}

type buildEventReporter struct {
isWorkflow bool
apiKey string
Expand Down Expand Up @@ -922,6 +947,12 @@ func (ar *actionRunner) Run(ctx context.Context, ws *workspace) error {
}
}()

if *installKythe {
if err := provisionKythe(ctx, ws); err != nil {
return err
}
}

for i, bazelCmd := range action.BazelCommands {
cmdStartTime := time.Now()

Expand Down

0 comments on commit c8fc7dd

Please sign in to comment.