Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit e0939e5

Browse files
committed
build.rs: Parse the Linux version code better (closes #118)
Allows running on days without rustfmt.
1 parent 9a7e780 commit e0939e5

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

build.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ fn handle_kernel_version_cfg(bindings_path: &PathBuf) {
6262
let mut version = None;
6363
for line in f.lines() {
6464
let line = line.unwrap();
65-
if line.starts_with("pub const LINUX_VERSION_CODE") {
66-
let mut parts = line.split(" = ");
67-
parts.next();
68-
let raw_version = parts.next().unwrap();
69-
// Remove the trailing semi-colon
70-
version = Some(raw_version[..raw_version.len() - 1].parse::<u64>().unwrap());
71-
break;
65+
if let Some(type_and_value) = line.split("pub const LINUX_VERSION_CODE").nth(1) {
66+
if let Some(value) = type_and_value.split("=").nth(1) {
67+
let raw_version = value.split(";").next().unwrap();
68+
version = Some(raw_version.trim().parse::<u64>().unwrap());
69+
break;
70+
}
7271
}
7372
}
7473
let version = version.expect("Couldn't find kernel version");

0 commit comments

Comments
 (0)