Skip to content

Commit 102699f

Browse files
authored
Improve --migrate feature (#678)
* Improve --migrate feature * Improve --migrate feature
1 parent f50920e commit 102699f

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

.bazelversion

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.3.1
1+
8.1.1

MODULE.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module(
88
bazel_dep(name = "gazelle", version = "0.38.0", repo_name = "bazel_gazelle")
99
bazel_dep(name = "platforms", version = "0.0.10")
1010
bazel_dep(name = "rules_go", version = "0.50.0", repo_name = "io_bazel_rules_go")
11-
bazel_dep(name = "rules_pkg", version = "0.10.1")
11+
bazel_dep(name = "rules_pkg", version = "1.0.1")
1212
bazel_dep(name = "aspect_rules_js", version = "2.0.1")
1313

1414
go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")

core/core.go

+14-13
Original file line numberDiff line numberDiff line change
@@ -1023,34 +1023,34 @@ func testWithBazelAtCommit(bazelCommit string, args []string, bazeliskHome strin
10231023
func migrate(bazelPath string, baseArgs []string, flags []string, config config.Config) {
10241024
var startupOptions = parseStartupOptions(baseArgs)
10251025

1026-
// 1. Try with all the flags.
1027-
args := insertArgs(baseArgs, flags)
1028-
fmt.Printf("\n\n--- Running Bazel with all incompatible flags\n\n")
1026+
// 1. Try without any incompatible flags, as a sanity check.
1027+
args := baseArgs
1028+
fmt.Printf("\n\n--- Running Bazel with no incompatible flags\n\n")
10291029
shutdownIfNeeded(bazelPath, startupOptions, config)
10301030
cleanIfNeeded(bazelPath, startupOptions, config)
10311031
fmt.Printf("bazel %s\n", strings.Join(args, " "))
10321032
exitCode, err := runBazel(bazelPath, args, nil, config)
10331033
if err != nil {
10341034
log.Fatalf("could not run Bazel: %v", err)
10351035
}
1036-
if exitCode == 0 {
1037-
fmt.Printf("Success: No migration needed.\n")
1038-
os.Exit(0)
1036+
if exitCode != 0 {
1037+
fmt.Printf("Failure: Command failed, even without incompatible flags.\n")
1038+
os.Exit(exitCode)
10391039
}
10401040

1041-
// 2. Try with no flags, as a sanity check.
1042-
args = baseArgs
1043-
fmt.Printf("\n\n--- Running Bazel with no incompatible flags\n\n")
1041+
// 2. Try with all the flags.
1042+
args = insertArgs(baseArgs, flags)
1043+
fmt.Printf("\n\n--- Running Bazel with all incompatible flags\n\n")
10441044
shutdownIfNeeded(bazelPath, startupOptions, config)
10451045
cleanIfNeeded(bazelPath, startupOptions, config)
10461046
fmt.Printf("bazel %s\n", strings.Join(args, " "))
10471047
exitCode, err = runBazel(bazelPath, args, nil, config)
10481048
if err != nil {
10491049
log.Fatalf("could not run Bazel: %v", err)
10501050
}
1051-
if exitCode != 0 {
1052-
fmt.Printf("Failure: Command failed, even without incompatible flags.\n")
1053-
os.Exit(exitCode)
1051+
if exitCode == 0 {
1052+
fmt.Printf("Success: No migration needed.\n")
1053+
os.Exit(0)
10541054
}
10551055

10561056
// 3. Try with each flag separately.
@@ -1087,7 +1087,8 @@ func migrate(bazelPath string, baseArgs []string, flags []string, config config.
10871087
fmt.Printf("Migration is needed for the following flags:\n")
10881088
print(failList)
10891089

1090-
os.Exit(1)
1090+
// Return an unique exit code for incompatible flag test failure
1091+
os.Exit(73)
10911092
}
10921093

10931094
func dirForURL(url string) string {

0 commit comments

Comments
 (0)