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

@ -130,10 +130,11 @@ pub fn call_aster_main() -> ! {
}
fn run_ktests(test_whitelist: Option<&[&str]>, crate_whitelist: Option<&[&str]>) -> ! {
use crate::arch::qemu::{exit_qemu, QemuExitCode};
use alloc::{boxed::Box, string::ToString};
use core::any::Any;
use crate::arch::qemu::{exit_qemu, QemuExitCode};
let fn_catch_unwind = &(unwinding::panic::catch_unwind::<(), fn()>
as fn(fn()) -> Result<(), Box<(dyn Any + Send + 'static)>>);

View File

@ -7,8 +7,9 @@ pub type Result<T> = core::result::Result<T, crate::error::Error>;
pub(crate) use alloc::{boxed::Box, sync::Arc, vec::Vec};
pub(crate) use core::any::Any;
pub use crate::vm::{Paddr, Vaddr};
pub use crate::early_print as print;
pub use crate::early_println as println;
pub use aster_main::aster_main;
pub use crate::{
early_print as print, early_println as println,
vm::{Paddr, Vaddr},
};

View File

@ -3,7 +3,7 @@
//! Test runner enabling control over the tests.
//!
use alloc::{string::String, vec::Vec, collections::BTreeSet};
use alloc::{collections::BTreeSet, string::String, vec::Vec};
use core::format_args;
use owo_colors::OwoColorize;

View File

@ -4,13 +4,9 @@
//! It will depend on the kernel crate.
//!
use std::path::Path;
use std::process::Command;
use std::str::FromStr;
use std::{fs, process};
use std::{fs, path::Path, process, process::Command, str::FromStr};
use crate::error::Errno;
use crate::error_msg;
use crate::{error::Errno, error_msg};
pub fn new_base_crate(
base_crate_path: impl AsRef<Path>,

View File

@ -1,17 +1,22 @@
// SPDX-License-Identifier: MPL-2.0
use std::path::{Path, PathBuf};
use std::process::Command;
use crate::bin::AsterBin;
use crate::cli::CargoArgs;
use crate::config_manager::{
boot::Boot,
qemu::{Qemu, QemuMachine},
RunConfig,
use std::{
path::{Path, PathBuf},
process::Command,
};
use crate::{
bin::AsterBin,
cli::CargoArgs,
config_manager::{
boot::Boot,
qemu::{Qemu, QemuMachine},
RunConfig,
},
error::Errno,
error_msg,
vm_image::AsterVmImage,
};
use crate::vm_image::AsterVmImage;
use crate::{error::Errno, error_msg};
/// The osdk bundle artifact that stores as `bundle` directory.
///

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;

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: MPL-2.0
use std::path::{Path, PathBuf};
use std::process;
use std::{
path::{Path, PathBuf},
process,
};
use regex::Regex;
use serde::Deserialize;

View File

@ -9,7 +9,7 @@ use crate::{
cli::CargoArgs,
config_manager::{
get_feature_strings,
manifest::{OsdkManifest, TomlManifest, FEATURE_REGEX},
manifest::{OsdkManifest, TomlManifest, SELECT_REGEX},
},
test::utils::{assert_success, cargo_osdk, create_workspace},
};

View File

@ -1,6 +1,10 @@
// SPDX-License-Identifier: MPL-2.0
use std::{ffi::OsStr, path::{Path, PathBuf}, process::Command};
use std::{
ffi::OsStr,
path::{Path, PathBuf},
process::Command,
};
use crate::{error::Errno, error_msg};

View File

@ -1,6 +1,9 @@
// SPDX-License-Identifier: MPL-2.0
use std::{collections::HashMap, fs::File, io::Read, ops::Add, path::PathBuf, process::Command, str::FromStr};
use std::{
collections::HashMap, fs::File, io::Read, ops::Add, path::PathBuf, process::Command,
str::FromStr,
};
use json::JsonValue;
use proc_macro2::{Group, TokenStream};
@ -88,7 +91,11 @@ pub fn component_generate() -> Vec<ComponentInfo> {
};
let component_info = ComponentInfo {
name: package["name"].as_str().unwrap().to_string(),
path: PathBuf::from(&workspace_root).join(path).to_str().unwrap().to_string(),
path: PathBuf::from(&workspace_root)
.join(path)
.to_str()
.unwrap()
.to_string(),
priority: *mapping
.get(&package["name"].as_str().unwrap().to_string())
.unwrap(),

View File

@ -38,7 +38,7 @@ for CRATE in $EXCLUDED_CRATES; do
# is not currently in use or under development.
case "$CRATE" in
*cargo-component*)
continue
continue
;;
esac
@ -52,4 +52,3 @@ for CRATE in $EXCLUDED_CRATES; do
echo "Directory for crate $CRATE does not exist"
fi
done