Skip to content

Commit

Permalink
Users can set BAZELISK_SHUTDOWN to run bazel shutdown during testing …
Browse files Browse the repository at this point in the history
…incompatible flags (bazelbuild#85)
  • Loading branch information
meteorcloudy authored and philwo committed Aug 7, 2019
1 parent a0e9888 commit 90925cd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ show you which flags can safely enabled, and which flags require a migration.
You can set `BAZELISK_GITHUB_TOKEN` to set a GitHub access token to use for API
requests to avoid rate limiting when on shared networks.

You can set `BAZELISK_SHUTDOWN` to run `shutdown` between builds when
migrating if you suspect this affects your results.

You can set `BAZELISK_CLEAN` to run `clean --expunge` between builds when
migrating if you suspect this affects your results.

Expand Down
29 changes: 26 additions & 3 deletions bazelisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,33 @@ func insertArgs(baseArgs []string, newArgs []string) []string {
return result
}

func shutdownIfNeeded(bazelPath string) {
bazeliskClean := os.Getenv("BAZELISK_SHUTDOWN")
if len(bazeliskClean) == 0 {
return
}

fmt.Printf("bazel shutdown\n")
exitCode, err := runBazel(bazelPath, []string{"shutdown"})
fmt.Printf("\n")
if err != nil {
log.Fatalf("failed to run bazel shutdown: %v", err)
}
if exitCode != 0 {
fmt.Printf("Failure: shutdown command failed.\n")
os.Exit(exitCode)
}
}

func cleanIfNeeded(bazelPath string) {
bazeliskClean := os.Getenv("BAZELISK_CLEAN")
if len(bazeliskClean) == 0 {
return
}

fmt.Printf("bazel clean --expunge\n")
exitCode, err := runBazel(bazelPath, []string{"clean", "--expunge"})
fmt.Printf("\n")
if err != nil {
log.Fatalf("failed to run clean: %v", err)
}
Expand All @@ -562,8 +582,9 @@ func migrate(bazelPath string, baseArgs []string, newArgs []string) {
// 1. Try with all the flags.
args := insertArgs(baseArgs, newArgs)
fmt.Printf("\n\n--- Running Bazel with all incompatible flags\n\n")
fmt.Printf("bazel %s\n", strings.Join(args, " "))
shutdownIfNeeded(bazelPath)
cleanIfNeeded(bazelPath)
fmt.Printf("bazel %s\n", strings.Join(args, " "))
exitCode, err := runBazel(bazelPath, args)
if err != nil {
log.Fatalf("could not run Bazel: %v", err)
Expand All @@ -576,8 +597,9 @@ func migrate(bazelPath string, baseArgs []string, newArgs []string) {
// 2. Try with no flags, as a sanity check.
args = baseArgs
fmt.Printf("\n\n--- Running Bazel with no incompatible flags\n\n")
fmt.Printf("bazel %s\n", strings.Join(args, " "))
shutdownIfNeeded(bazelPath)
cleanIfNeeded(bazelPath)
fmt.Printf("bazel %s\n", strings.Join(args, " "))
exitCode, err = runBazel(bazelPath, args)
if err != nil {
log.Fatalf("could not run Bazel: %v", err)
Expand All @@ -593,8 +615,9 @@ func migrate(bazelPath string, baseArgs []string, newArgs []string) {
for _, arg := range newArgs {
args = insertArgs(baseArgs, []string{arg})
fmt.Printf("\n\n--- Running Bazel with %s\n\n", arg)
fmt.Printf("bazel %s\n", strings.Join(args, " "))
shutdownIfNeeded(bazelPath)
cleanIfNeeded(bazelPath)
fmt.Printf("bazel %s\n", strings.Join(args, " "))
exitCode, err = runBazel(bazelPath, args)
if err != nil {
log.Fatalf("could not run Bazel: %v", err)
Expand Down

0 comments on commit 90925cd

Please sign in to comment.