Skip to content

Commit 34e09a8

Browse files
authored
Merge pull request RustPython#4176 from youknowone/lalrpop
temporary fix of lalrpop build
2 parents 683e5af + 5c29c27 commit 34e09a8

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

compiler/parser/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ repository = "https://github.com/RustPython/RustPython"
88
license = "MIT"
99
edition = "2021"
1010

11+
[features]
12+
default = ["lalrpop"] # removing this causes potential build failure
13+
1114
[build-dependencies]
1215
anyhow = "1.0.45"
1316
lalrpop = { version = "0.19.8", optional = true }

compiler/parser/build.rs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,26 @@ fn main() -> anyhow::Result<()> {
1616
Ok(())
1717
}
1818

19-
fn requires_lalrpop(source: &str, target: &str) -> bool {
19+
fn requires_lalrpop(source: &str, target: &str) -> Option<String> {
2020
let target = if let Ok(target) = File::open(target) {
2121
target
2222
} else {
23-
println!("cargo:warning=python.rs doesn't exist. regenerate.");
24-
return true;
23+
return Some("python.rs doesn't exist. regenerate.".to_owned());
2524
};
2625

2726
let sha_prefix = "// sha3: ";
28-
let sha3_line = BufReader::with_capacity(128, target)
29-
.lines()
30-
.find_map(|line| {
31-
let line = line.unwrap();
32-
line.starts_with(sha_prefix).then_some(line)
33-
})
34-
.expect("no sha3 line?");
27+
let sha3_line = if let Some(sha3_line) =
28+
BufReader::with_capacity(128, target)
29+
.lines()
30+
.find_map(|line| {
31+
let line = line.unwrap();
32+
line.starts_with(sha_prefix).then_some(line)
33+
}) {
34+
sha3_line
35+
} else {
36+
// no sha3 line - maybe old version of lalrpop installed
37+
return Some("python.rs doesn't include sha3 hash. regenerate.".to_owned());
38+
};
3539
let expected_sha3_str = sha3_line.strip_prefix(sha_prefix).unwrap();
3640

3741
let actual_sha3 = {
@@ -55,29 +59,35 @@ fn requires_lalrpop(source: &str, target: &str) -> bool {
5559
};
5660
let eq = sha_equal(expected_sha3_str, &actual_sha3);
5761
if !eq {
58-
println!("cargo:warning=python.rs hash expected: {expected_sha3_str}");
5962
let mut actual_sha3_str = String::new();
6063
for byte in actual_sha3 {
6164
write!(actual_sha3_str, "{byte:02x}").unwrap();
6265
}
63-
println!("cargo:warning=python.rs hash actual: {actual_sha3_str}");
66+
return Some(format!(
67+
"python.rs hash expected: {expected_sha3_str} but actual: {actual_sha3_str}"
68+
));
6469
}
65-
!eq
70+
None
6671
}
6772

6873
fn try_lalrpop(source: &str, target: &str) -> anyhow::Result<()> {
69-
if !requires_lalrpop(source, target) {
74+
let _message = if let Some(msg) = requires_lalrpop(source, target) {
75+
msg
76+
} else {
7077
return Ok(());
71-
}
78+
};
7279

7380
#[cfg(feature = "lalrpop")]
74-
{
75-
lalrpop::process_root().expect("running lalrpop failed");
76-
Ok(())
77-
}
81+
lalrpop::process_root().unwrap_or_else(|e| {
82+
println!("cargo:warning={_message}");
83+
panic!("running lalrpop failed. {e:?}");
84+
});
7885

7986
#[cfg(not(feature = "lalrpop"))]
80-
panic!("try: cargo build --manifest-path=compiler/parser/Cargo.toml --features=lalrpop");
87+
{
88+
println!("cargo:warning=try: cargo build --manifest-path=compiler/parser/Cargo.toml --features=lalrpop");
89+
}
90+
Ok(())
8191
}
8292

8393
fn sha_equal(expected_sha3_str: &str, actual_sha3: &[u8; 32]) -> bool {

0 commit comments

Comments
 (0)