-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fef1af
commit 7530835
Showing
5 changed files
with
76 additions
and
13 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
load("//:version.bzl", "VERSION") | ||
load("//rust:defs.bzl", "rust_test") | ||
|
||
rust_test( | ||
name = "bzl_version_test", | ||
srcs = ["bzl_version_test.rs"], | ||
data = [ | ||
"//:MODULE.bazel", | ||
], | ||
edition = "2021", | ||
env = { | ||
"MODULE_BAZEL": "$(rlocationpath //:MODULE.bazel)", | ||
"VERSION": VERSION, | ||
}, | ||
deps = [ | ||
"//tools/runfiles", | ||
], | ||
) |
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,40 @@ | ||
//! A test to ensure the rules_rust bzlmod versions match the standard versions. | ||
use runfiles::Runfiles; | ||
|
||
fn parse_module_bazel_version(text: &str) -> String { | ||
let mut found_module = false; | ||
for line in text.split('\n') { | ||
if found_module { | ||
assert!(!line.ends_with(')'), "Failed to parse version"); | ||
if let Some((param, value)) = line.rsplit_once(" = ") { | ||
if param.trim() == "version" { | ||
return value.trim().trim_matches(',').trim_matches('"').to_owned(); | ||
} | ||
} | ||
} else if line.starts_with("module(") { | ||
found_module = true; | ||
continue; | ||
} | ||
} | ||
panic!("Failed to find MODULE.bazel version"); | ||
} | ||
|
||
/// If this test fails it means `//:version.bzl` and `//:MODULE.bazel` need to | ||
/// be synced up. `//:version.bzl` should contain the source of truth. | ||
#[test] | ||
fn module_bzl_has_correct_version() { | ||
let version = std::env::var("VERSION").unwrap(); | ||
let module_bazel_text = { | ||
let r = Runfiles::create().unwrap(); | ||
let path = r.rlocation(std::env::var("MODULE_BAZEL").unwrap()); | ||
std::fs::read_to_string(path).unwrap() | ||
}; | ||
|
||
let module_bazel_version = parse_module_bazel_version(&module_bazel_text); | ||
|
||
assert_eq!( | ||
version, module_bazel_version, | ||
"//:version.bzl and //:MODULE.bazel versions are out of sync" | ||
); | ||
} |