Skip to content

Commit 873351c

Browse files
committed
Check that the kernel Cargo.toml depends on the bootloader
If not it is likely the wrong Cargo.toml.
1 parent 9a8ace7 commit 873351c

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

build.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -231,23 +231,37 @@ mod binary {
231231
.parse::<Value>()
232232
.expect("failed to parse kernel's Cargo.toml");
233233

234-
let config_table = manifest
235-
.get("package")
236-
.and_then(|table| table.get("metadata"))
237-
.and_then(|table| table.get("bootloader"))
238-
.cloned()
239-
.unwrap_or_else(|| toml::Value::Table(toml::map::Map::new()));
234+
if manifest
235+
.get("dependencies")
236+
.and_then(|d| d.get("bootloader"))
237+
.is_some()
238+
{
239+
// it seems to be the correct Cargo.toml
240+
let config_table = manifest
241+
.get("package")
242+
.and_then(|table| table.get("metadata"))
243+
.and_then(|table| table.get("bootloader"))
244+
.cloned()
245+
.unwrap_or_else(|| toml::Value::Table(toml::map::Map::new()));
240246

241-
config_table
242-
.try_into::<Config>()
243-
.map(|c| format!("{:?}", c))
244-
.unwrap_or_else(|err| {
245-
format!(
246-
"compile_error!(\"failed to parse bootloader config in {}:\n\n{}\")",
247-
path,
248-
err.to_string().escape_default(),
249-
)
250-
})
247+
config_table
248+
.try_into::<Config>()
249+
.map(|c| format!("{:?}", c))
250+
.unwrap_or_else(|err| {
251+
format!(
252+
"compile_error!(\"failed to parse bootloader config in {}:\n\n{}\")",
253+
path,
254+
err.to_string().escape_default(),
255+
)
256+
})
257+
} else {
258+
format!(
259+
"compile_error!(\"no bootloader dependency in {}\n\n The \
260+
`--kernel-manifest` path should point to the `Cargo.toml` \
261+
of the kernel.\")",
262+
path,
263+
)
264+
}
251265
}
252266
};
253267

0 commit comments

Comments
 (0)