Skip to content

Commit 9ccaf9f

Browse files
committed
Use correct target for tester and respect default targets
1 parent e1d59cd commit 9ccaf9f

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

Diff for: src/subcommand/tester.rs

+24-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{args::TesterArgs, builder::Builder, config, ErrorString};
1+
use crate::{cargo_config, args::TesterArgs, builder::Builder, config, ErrorString};
22
use std::{
33
fs,
44
io::{self, Write},
@@ -72,14 +72,8 @@ pub(crate) fn tester(args: TesterArgs) -> Result<(), ErrorString> {
7272
let kernel_target_dir = Path::new("target")
7373
.canonicalize()
7474
.expect("failed to canonicalize target dir"); // TODO
75-
let kernel_target_json = Path::new("x86_64-blog_os.json")
76-
.canonicalize()
77-
.expect("failed to canonicalize target.json"); // TODO
78-
let kernel_target_json_triple = kernel_target_json
79-
.file_stem()
80-
.expect("kernel target json has no valid file stem");
8175

82-
let out_dir = kernel_target_dir.join("integration-tests").join(&test_name);
76+
let out_dir = kernel_target_dir.join("bootimage").join("integration-tests").join(&test_name);
8377
fs::create_dir_all(&out_dir).expect("failed to create out dir");
8478

8579
let manifest_path = out_dir.join("Cargo.toml");
@@ -110,7 +104,9 @@ path = "{test_path}"
110104
cmd.arg("--manifest-path").arg(&manifest_path);
111105
cmd.arg("--target-dir").arg(&kernel_target_dir);
112106
cmd.env("SYSROOT_DIR", &kernel_target_dir.join("sysroot")); // for cargo-xbuild
113-
cmd.arg("--target").arg(&kernel_target_json); // TODO remove when default targets are canonicalized properly
107+
if let Some(target) = args.target.as_ref().or(config.default_target.as_ref()) {
108+
cmd.arg("--target").arg(target);
109+
}
114110
let output = cmd.output().expect("failed to run cargo xbuild");
115111
if !output.status.success() {
116112
io::stderr()
@@ -119,10 +115,25 @@ path = "{test_path}"
119115
process::exit(1);
120116
}
121117

122-
let executable = kernel_target_dir
123-
.join(&kernel_target_json_triple)
124-
.join("debug")
125-
.join(&test_name);
118+
let kernel_target_triple = {
119+
match args.target.or(config.default_target) {
120+
None => cargo_config::default_target_triple(kernel_root_path, true)?,
121+
Some(ref target) if target.ends_with(".json") => {
122+
Some(Path::new(target).file_stem().expect("kernel target json has no valid file stem").to_str().expect("invalid unicode").to_owned())
123+
}
124+
Some(triple) => Some(triple),
125+
}
126+
};
127+
128+
let executable = {
129+
let mut path = kernel_target_dir.clone();
130+
if let Some(triple) = kernel_target_triple {
131+
path.push(triple);
132+
}
133+
path.push("debug");
134+
path.push(&test_name);
135+
path
136+
};
126137
let bootimage_bin_path = out_dir.join(format!("bootimage-{}.bin", test_name));
127138

128139
builder.create_bootimage(&executable, &bootimage_bin_path, true)?;

0 commit comments

Comments
 (0)