Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 65a03a8

Browse filesBrowse files
committed
Use new kernel_package_for_bin method for cargo bootimage
The `cargo bootimage` command only deals with binaries, so we don't need to try to derive the manifest path for test or doctest executables.
1 parent eada9f5 commit 65a03a8
Copy full SHA for 65a03a8

File tree

Expand file treeCollapse file tree

1 file changed

+17
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+17
-2
lines changed

‎src/bin/cargo-bootimage.rs

Copy file name to clipboardExpand all lines: src/bin/cargo-bootimage.rs
+17-2Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{anyhow, Result};
1+
use anyhow::{anyhow, Context, Result};
22
use bootimage::{
33
args::{BuildArgs, BuildCommand},
44
builder::Builder,
@@ -60,8 +60,23 @@ fn build(args: BuildArgs) -> Result<()> {
6060
.to_str()
6161
.ok_or_else(|| anyhow!("executable file stem not valid utf8"))?;
6262

63+
// We don't have access to a CARGO_MANIFEST_DIR environment variable
64+
// here because `cargo bootimage` is started directly by the user. We
65+
// therefore have to find out the path to the Cargo.toml of the
66+
// executables ourselves. For workspace projects, this can be a
67+
// different Cargo.toml than the Cargo.toml in the current directory.
68+
//
69+
// To retrieve the correct Cargo.toml path, we look for the binary name
70+
// in the `cargo metadata` output and then get the manifest path from
71+
// the corresponding package.
72+
let kernel_package = builder
73+
.kernel_package_for_bin(bin_name)
74+
.context("Failed to run cargo metadata to find out kernel manifest path")?
75+
.ok_or_else(|| anyhow!("Failed to find kernel binary in cargo metadata output"))?;
76+
let kernel_manifest_path = &kernel_package.manifest_path.to_owned();
77+
6378
let bootimage_path = out_dir.join(format!("bootimage-{}.bin", bin_name));
64-
builder.create_bootimage(bin_name, &executable, &bootimage_path, quiet)?;
79+
builder.create_bootimage(kernel_manifest_path, &executable, &bootimage_path, quiet)?;
6580
if !args.quiet() {
6681
println!(
6782
"Created bootimage for `{}` at `{}`",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.