Refactor CI and OSDK tests, add OSDK publish workflow

This commit is contained in:
Zhang Junyang
2024-02-26 11:08:42 +08:00
committed by Tate, Hongliang Tian
parent eb42383532
commit 6694f08eac
40 changed files with 441 additions and 318 deletions

View File

@ -49,7 +49,7 @@ pub fn make_install_bzimage(
setup_install_dir.join("bin").join("linux-bzimage-setup")
};
// Make the `bzImage`-compatible kernel image and place it in the boot directory.
let install_path = install_dir.as_ref().join(&target_name);
let install_path = install_dir.as_ref().join(target_name);
info!("Building bzImage");
println!("install_path: {:?}", install_path);
make_bzimage(&install_path, image_type, &aster_elf.path, &setup_bin);

View File

@ -25,7 +25,7 @@ pub fn create_bootdev_image(
// Clear or make the iso dir.
if iso_root.exists() {
fs::remove_dir_all(&iso_root).unwrap();
fs::remove_dir_all(iso_root).unwrap();
}
fs::create_dir_all(iso_root.join("boot").join("grub")).unwrap();
@ -41,12 +41,12 @@ pub fn create_bootdev_image(
// Make the kernel image and place it in the boot directory.
match protocol {
BootProtocol::LinuxLegacy32 | BootProtocol::LinuxEfiHandover64 => {
make_install_bzimage(&iso_root.join("boot"), &target_dir, aster_bin, protocol);
make_install_bzimage(iso_root.join("boot"), &target_dir, aster_bin, protocol);
}
BootProtocol::Multiboot | BootProtocol::Multiboot2 => {
// Copy the kernel image to the boot directory.
let target_path = iso_root.join("boot").join(&target_name);
fs::copy(&aster_bin.path, &target_path).unwrap();
fs::copy(&aster_bin.path, target_path).unwrap();
}
};
@ -63,7 +63,7 @@ pub fn create_bootdev_image(
protocol,
);
let grub_cfg_path = iso_root.join("boot").join("grub").join("grub.cfg");
fs::write(&grub_cfg_path, grub_cfg).unwrap();
fs::write(grub_cfg_path, grub_cfg).unwrap();
// Make the boot device CDROM image using `grub-mkrescue`.
let iso_path = &target_dir.as_ref().join(target_name.to_string() + ".iso");
@ -109,11 +109,11 @@ fn generate_grub_cfg(
let grub_cfg = grub_cfg.replace("#KERNEL_COMMAND_LINE#", kcmdline);
// Replace the grub commands according to the protocol selected.
let aster_bin_path_on_device = PathBuf::from("/boot")
.join(&target_name)
.join(target_name)
.into_os_string()
.into_string()
.unwrap();
let grub_cfg = match protocol {
match protocol {
BootProtocol::Multiboot => grub_cfg
.replace("#GRUB_CMD_KERNEL#", "multiboot")
.replace("#KERNEL#", &aster_bin_path_on_device)
@ -147,9 +147,7 @@ fn generate_grub_cfg(
"".to_owned()
},
),
};
grub_cfg
}
}
fn get_grub_mkrescue_version(grub_mkrescue: &PathBuf) -> String {

View File

@ -29,9 +29,9 @@ pub fn execute_build_command(config: &BuildConfig) {
std::fs::create_dir_all(&osdk_target_directory).unwrap();
}
let target_info = get_current_crate_info();
let bundle_path = osdk_target_directory.join(&target_info.name);
let bundle_path = osdk_target_directory.join(target_info.name);
let _bundle = create_base_and_build(&bundle_path, &osdk_target_directory, &config);
let _bundle = create_base_and_build(bundle_path, &osdk_target_directory, config);
}
pub fn create_base_and_build(
@ -43,12 +43,12 @@ pub fn create_base_and_build(
new_base_crate(
&base_crate_path,
&get_current_crate_info().name,
&get_current_crate_info().path,
get_current_crate_info().path,
);
let original_dir = std::env::current_dir().unwrap();
std::env::set_current_dir(&base_crate_path).unwrap();
let bundle = do_build(&bundle_path, &osdk_target_directory, &config);
std::env::set_current_dir(&original_dir).unwrap();
let bundle = do_build(&bundle_path, &osdk_target_directory, config);
std::env::set_current_dir(original_dir).unwrap();
bundle
}
@ -92,7 +92,7 @@ pub fn do_build(
&osdk_target_directory,
&aster_elf,
config.manifest.initramfs.as_ref(),
&config,
config,
);
bundle.add_vm_image(&bootdev_image);
}
@ -105,6 +105,7 @@ fn build_kernel_elf(args: &CargoArgs) -> AsterBin {
let target_json_path = PathBuf::from_str("x86_64-custom.json").unwrap();
let mut command = cargo();
command.env_remove("RUSTUP_TOOLCHAIN");
command.arg("build").arg("--target").arg(&target_json_path);
command.args(COMMON_CARGO_ARGS);
command.arg("--profile=".to_string() + &args.profile);
@ -114,8 +115,8 @@ fn build_kernel_elf(args: &CargoArgs) -> AsterBin {
process::exit(Errno::ExecuteCommand as _);
}
let aster_bin_path = PathBuf::from(target_directory)
.join(target_json_path.file_stem().unwrap().to_str().unwrap());
let aster_bin_path =
target_directory.join(target_json_path.file_stem().unwrap().to_str().unwrap());
let aster_bin_path = if args.profile == "dev" {
aster_bin_path.join("debug")
} else {

View File

@ -77,7 +77,7 @@ fn create_osdk_manifest(cargo_metadata: &serde_json::Value) {
// The apt OVMF repo installs to `/usr/share/OVMF`
fs::write(
osdk_manifest_path,
r#"
r#"\
[boot]
ovmf = "/usr/share/OVMF"
[qemu]

View File

@ -18,10 +18,10 @@ pub fn execute_run_command(config: &RunConfig) {
// TODO: Check if the bundle is already built and compatible with the run configuration.
let bundle = create_base_and_build(
&default_bundle_directory,
default_bundle_directory,
&osdk_target_directory,
&required_build_config,
);
bundle.run(&config);
bundle.run(config);
}

View File

@ -19,7 +19,7 @@ pub fn execute_test_command(config: &TestConfig) {
let ktest_test_whitelist = match &config.test_name {
Some(name) => format!(r#"Some(&["{}"])"#, name),
None => format!(r#"None"#),
None => r#"None"#.to_string(),
};
let mut ktest_crate_whitelist = vec![current_crate.name];
@ -54,12 +54,12 @@ pub static KTEST_CRATE_WHITELIST: Option<&[&str]> = Some(&{:#?});
// Add `--cfg ktest` to RUSTFLAGS
std::env::set_var("RUSTFLAGS", "--cfg ktest");
let bundle = do_build(
&default_bundle_directory,
default_bundle_directory,
&osdk_target_directory,
&required_build_config,
);
std::env::remove_var("RUSTFLAGS");
std::env::set_current_dir(&original_dir).unwrap();
std::env::set_current_dir(original_dir).unwrap();
let required_run_config = RunConfig {
manifest: required_build_config.manifest.clone(),