-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work around bazel7 incompatible targets issue (#82)
* Add version range checker * Use version range checker in existing code * Filter incompatible targets from query spec This works around bazelbuild/bazel#21010 We only do this extra filtering when we detect we're running with a Bazel which suffers from this bug.
- Loading branch information
1 parent
f255eef
commit 4bb8af0
Showing
12 changed files
with
279 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "versions", | ||
srcs = ["versions.go"], | ||
importpath = "github.com/bazel-contrib/target-determinator/common/versions", | ||
visibility = ["//visibility:public"], | ||
deps = ["@com_github_hashicorp_go_version//:go-version"], | ||
) | ||
|
||
go_test( | ||
name = "versions_test", | ||
srcs = ["versions_test.go"], | ||
embed = [":versions"], | ||
deps = [ | ||
"@com_github_hashicorp_go_version//:go-version", | ||
"@com_github_stretchr_testify//require", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package versions | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/go-version" | ||
) | ||
|
||
func ReleaseIsInRange(releaseString string, min *version.Version, max *version.Version) (*bool, string) { | ||
releasePrefix := "release " | ||
if !strings.HasPrefix(releaseString, releasePrefix) { | ||
return nil, "Bazel wasn't a released version" | ||
} | ||
|
||
bazelVersion, err := version.NewVersion(releaseString[len(releasePrefix):]) | ||
if err != nil { | ||
return nil, fmt.Sprintf("Failed to parse Bazel version %q", releaseString) | ||
} | ||
if min != nil && !bazelVersion.GreaterThanOrEqual(min) { | ||
return ptr(false), fmt.Sprintf("Bazel version %s was less than minimum %s", bazelVersion, min.String()) | ||
} | ||
if max != nil && !max.GreaterThan(bazelVersion) { | ||
return ptr(false), fmt.Sprintf("Bazel version %s was not less than maximum %s", bazelVersion, max.String()) | ||
} | ||
return ptr(true), "" | ||
} | ||
|
||
func ptr[V any](v V) *V { | ||
return &v | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package versions | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/go-version" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestReleaseIsInRange(t *testing.T) { | ||
for name, tc := range map[string]struct { | ||
bazelReleaseString string | ||
min string | ||
max string | ||
wantResult *bool | ||
wantExplanation string | ||
}{ | ||
"in_range": { | ||
bazelReleaseString: "release 7.0.0", | ||
min: "6.4.0", | ||
max: "8.0.0", | ||
wantResult: ptr(true), | ||
wantExplanation: "", | ||
}, | ||
"at_max": { | ||
bazelReleaseString: "release 7.0.0", | ||
min: "6.4.0", | ||
max: "7.0.0", | ||
wantResult: ptr(false), | ||
wantExplanation: "Bazel version 7.0.0 was not less than maximum 7.0.0", | ||
}, | ||
"at_min": { | ||
bazelReleaseString: "release 7.0.0", | ||
min: "7.0.0", | ||
max: "8.0.0", | ||
wantResult: ptr(true), | ||
wantExplanation: "", | ||
}, | ||
"above_max": { | ||
bazelReleaseString: "release 7.0.0", | ||
min: "6.4.0", | ||
max: "6.5.0", | ||
wantResult: ptr(false), | ||
wantExplanation: "Bazel version 7.0.0 was not less than maximum 6.5.0", | ||
}, | ||
"below_min": { | ||
bazelReleaseString: "release 6.4.0", | ||
min: "7.0.0", | ||
max: "7.1.0", | ||
wantResult: ptr(false), | ||
wantExplanation: "Bazel version 6.4.0 was less than minimum 7.0.0", | ||
}, | ||
"no_release_prefix": { | ||
bazelReleaseString: "7.0.0", | ||
min: "6.4.0", | ||
max: "8.0.0", | ||
wantResult: nil, | ||
wantExplanation: "Bazel wasn't a released version", | ||
}, | ||
"no_version": { | ||
bazelReleaseString: "release beep", | ||
min: "6.4.0", | ||
max: "8.0.0", | ||
wantResult: nil, | ||
wantExplanation: "Failed to parse Bazel version \"release beep\"", | ||
}, | ||
"prerelease_in_range": { | ||
bazelReleaseString: "release 8.0.0-pre.20240101.1", | ||
min: "7.0.0", | ||
max: "8.0.0", | ||
wantResult: ptr(true), | ||
wantExplanation: "", | ||
}, | ||
"prerelease_below_range": { | ||
bazelReleaseString: "release 8.0.0-pre.20240101.1", | ||
min: "8.0.0", | ||
max: "8.1.0", | ||
wantResult: ptr(false), | ||
wantExplanation: "Bazel version 8.0.0-pre.20240101.1 was less than minimum 8.0.0", | ||
}, | ||
"prerelease_above_range": { | ||
bazelReleaseString: "release 8.0.0-pre.20240101.1", | ||
min: "7.0.0", | ||
max: "7.1.0", | ||
wantResult: ptr(false), | ||
wantExplanation: "Bazel version 8.0.0-pre.20240101.1 was not less than maximum 7.1.0", | ||
}, | ||
"above_only_min": { | ||
bazelReleaseString: "release 7.0.0", | ||
min: "6.4.0", | ||
max: "", | ||
wantResult: ptr(true), | ||
wantExplanation: "", | ||
}, | ||
"at_only_min": { | ||
bazelReleaseString: "release 6.4.0", | ||
min: "6.4.0", | ||
max: "", | ||
wantResult: ptr(true), | ||
wantExplanation: "", | ||
}, | ||
"below_only_max": { | ||
bazelReleaseString: "release 6.4.0", | ||
min: "", | ||
max: "7.0.0", | ||
wantResult: ptr(true), | ||
wantExplanation: "", | ||
}, | ||
"at_only_max": { | ||
bazelReleaseString: "release 7.0.0", | ||
min: "", | ||
max: "7.0.0", | ||
wantResult: ptr(false), | ||
wantExplanation: "Bazel version 7.0.0 was not less than maximum 7.0.0", | ||
}, | ||
} { | ||
t.Run(name, func(t *testing.T) { | ||
var min *version.Version | ||
if tc.min != "" { | ||
min = version.Must(version.NewVersion(tc.min)) | ||
} | ||
var max *version.Version | ||
if tc.max != "" { | ||
max = version.Must(version.NewVersion(tc.max)) | ||
} | ||
result, explanation := ReleaseIsInRange(tc.bazelReleaseString, min, max) | ||
if tc.wantResult == nil { | ||
require.Nil(t, result) | ||
} else { | ||
require.NotNil(t, result) | ||
require.Equal(t, *tc.wantResult, *result) | ||
} | ||
require.Equal(t, tc.wantExplanation, explanation) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.