Apply the new format policy

This commit is contained in:
Zhang Junyang
2024-02-26 10:24:59 +08:00
committed by Tate, Hongliang Tian
parent 60e996ea2f
commit 3494bc45af
20 changed files with 117 additions and 101 deletions

View File

@ -1,17 +1,19 @@
// SPDX-License-Identifier: MPL-2.0
use linux_bzimage_builder::{make_bzimage, BzImageType, legacy32_rust_target_json};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::{
fs::OpenOptions,
io::{Seek, SeekFrom, Write},
path::{Path, PathBuf},
process::Command,
};
use crate::bin::{AsterBin, AsterBinType, AsterBzImageMeta, AsterElfMeta};
use crate::config_manager::boot::BootProtocol;
use crate::utils::get_current_crate_info;
use linux_bzimage_builder::{legacy32_rust_target_json, make_bzimage, BzImageType};
use crate::{
bin::{AsterBin, AsterBinType, AsterBzImageMeta, AsterElfMeta},
config_manager::boot::BootProtocol,
utils::get_current_crate_info,
};
pub fn make_install_bzimage(
install_dir: impl AsRef<Path>,

View File

@ -1,14 +1,17 @@
// SPDX-License-Identifier: MPL-2.0
use std::fs;
use std::path::{Path, PathBuf};
use crate::bin::AsterBin;
use crate::config_manager::{boot::BootProtocol, BuildConfig};
use crate::utils::get_current_crate_info;
use crate::vm_image::{AsterGrubIsoImageMeta, AsterVmImage, AsterVmImageType};
use std::{
fs,
path::{Path, PathBuf},
};
use super::bin::make_install_bzimage;
use crate::{
bin::AsterBin,
config_manager::{boot::BootProtocol, BuildConfig},
utils::get_current_crate_info,
vm_image::{AsterGrubIsoImageMeta, AsterVmImage, AsterVmImageType},
};
pub fn create_bootdev_image(
target_dir: impl AsRef<Path>,
@ -38,12 +41,7 @@ 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.

View File

@ -3,21 +3,25 @@
mod bin;
mod grub;
use std::path::{Path, PathBuf};
use std::process;
use std::str::FromStr;
use std::{
path::{Path, PathBuf},
process,
str::FromStr,
};
use bin::strip_elf_for_qemu;
use crate::base_crate::new_base_crate;
use crate::bin::{AsterBin, AsterBinType, AsterElfMeta};
use crate::bundle::{Bundle, BundleManifest};
use crate::cli::CargoArgs;
use crate::config_manager::{qemu::QemuMachine, BuildConfig};
use crate::utils::{get_current_crate_info, get_target_directory};
use crate::{error::Errno, error_msg};
use super::utils::{cargo, COMMON_CARGO_ARGS, DEFAULT_TARGET_RELPATH};
use crate::{
base_crate::new_base_crate,
bin::{AsterBin, AsterBinType, AsterElfMeta},
bundle::{Bundle, BundleManifest},
cli::CargoArgs,
config_manager::{qemu::QemuMachine, BuildConfig},
error::Errno,
error_msg,
utils::{get_current_crate_info, get_target_directory},
};
pub fn execute_build_command(config: &BuildConfig) {
let osdk_target_directory = get_target_directory().join(DEFAULT_TARGET_RELPATH);

View File

@ -2,14 +2,8 @@
use std::process;
use crate::commands::utils::create_target_json;
use crate::error::Errno;
use crate::error_msg;
use super::utils::{cargo, COMMON_CARGO_ARGS};
use crate::{
commands::utils::create_target_json, error::Errno, error_msg, utils::get_cargo_metadata,
};
use crate::{commands::utils::create_target_json, error::Errno, error_msg};
pub fn execute_check_command() {
let target_json_path = create_target_json();

View File

@ -3,9 +3,7 @@
use std::process;
use super::utils::{cargo, COMMON_CARGO_ARGS};
use crate::{
error_msg, commands::utils::create_target_json, error::Errno, error_msg, utils::get_cargo_metadata,
};
use crate::{commands::utils::create_target_json, error::Errno, error_msg};
pub fn execute_clippy_command() {
let target_json_path = create_target_json();

View File

@ -11,6 +11,6 @@ mod test;
mod utils;
pub use self::{
check::execute_check_command, clippy::execute_clippy_command, new::execute_new_command,
run::execute_run_command, test::execute_test_command,
build::execute_build_command, check::execute_check_command, clippy::execute_clippy_command,
new::execute_new_command, run::execute_run_command, test::execute_test_command,
};

View File

@ -1,14 +1,19 @@
// SPDX-License-Identifier: MPL-2.0
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::{fs, process};
use std::ffi::OsStr;
use std::{
ffi::OsStr,
fs,
path::{Path, PathBuf},
process,
str::FromStr,
};
use crate::cli::NewArgs;
use crate::error::Errno;
use crate::error_msg;
use crate::utils::{cargo_new_lib, get_cargo_metadata, ASTER_FRAME_DEP, KTEST_DEP};
use crate::{
cli::NewArgs,
error::Errno,
error_msg,
utils::{cargo_new_lib, get_cargo_metadata, ASTER_FRAME_DEP, KTEST_DEP},
};
pub fn execute_new_command(args: &NewArgs) {
cargo_new_lib(&args.crate_name);
@ -51,7 +56,7 @@ fn add_manifest_dependencies(cargo_metadata: &serde_json::Value, crate_name: &st
let exclude = toml::Table::from_str(r#"exclude = ["target/osdk/base"]"#).unwrap();
manifest.insert("workspace".to_string(), toml::Value::Table(exclude));
}
let content = toml::to_string(&manifest).unwrap();
fs::write(mainfest_path, content).unwrap();
}
@ -70,7 +75,9 @@ fn create_osdk_manifest(cargo_metadata: &serde_json::Value) {
// Create `OSDK.toml` for the workspace
// FIXME: we need ovmf for grub-efi, the user may not have it.
// The apt OVMF repo installs to `/usr/share/OVMF`
fs::write(osdk_manifest_path, r#"
fs::write(
osdk_manifest_path,
r#"
[boot]
ovmf = "/usr/share/OVMF"
[qemu]
@ -85,7 +92,9 @@ args = [
"-display none",
"-device isa-debug-exit,iobase=0xf4,iosize=0x04",
]
"#).unwrap();
"#,
)
.unwrap();
}
/// Write the default content of `src/kernel.rs`, with contents in provided template.

View File

@ -1,10 +1,10 @@
// SPDX-License-Identifier: MPL-2.0
use crate::config_manager::{BuildConfig, RunConfig};
use crate::utils::{get_current_crate_info, get_target_directory};
use super::build::create_base_and_build;
use super::utils::DEFAULT_TARGET_RELPATH;
use super::{build::create_base_and_build, utils::DEFAULT_TARGET_RELPATH};
use crate::{
config_manager::{BuildConfig, RunConfig},
utils::{get_current_crate_info, get_target_directory},
};
pub fn execute_run_command(config: &RunConfig) {
let osdk_target_directory = get_target_directory().join(DEFAULT_TARGET_RELPATH);

View File

@ -2,12 +2,12 @@
use std::fs;
use crate::base_crate::new_base_crate;
use crate::config_manager::{BuildConfig, RunConfig, TestConfig};
use crate::utils::{get_current_crate_info, get_target_directory};
use super::build::do_build;
use super::utils::DEFAULT_TARGET_RELPATH;
use super::{build::do_build, utils::DEFAULT_TARGET_RELPATH};
use crate::{
base_crate::new_base_crate,
config_manager::{BuildConfig, RunConfig, TestConfig},
utils::{get_current_crate_info, get_target_directory},
};
pub fn execute_test_command(config: &TestConfig) {
let current_crate = get_current_crate_info();

View File

@ -1,10 +1,6 @@
// SPDX-License-Identifier: MPL-2.0
use std::{
fs,
path::{Path, PathBuf},
process::Command,
};
use std::{fs, path::PathBuf, process::Command};
use crate::utils::get_target_directory;