mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-19 04:26:39 +00:00
Implement the next OSDK
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
79bdbbe4f9
commit
e4c2151566
169
osdk/src/cli.rs
169
osdk/src/cli.rs
@ -10,37 +10,40 @@ use crate::{
|
||||
execute_build_command, execute_debug_command, execute_forwarded_command,
|
||||
execute_new_command, execute_run_command, execute_test_command,
|
||||
},
|
||||
config_manager::{
|
||||
action::{BootProtocol, Bootloader},
|
||||
manifest::ProjectType,
|
||||
BuildConfig, DebugConfig, RunConfig, TestConfig,
|
||||
config::{
|
||||
manifest::{ProjectType, TomlManifest},
|
||||
scheme::{BootMethod, BootProtocol},
|
||||
Config,
|
||||
},
|
||||
};
|
||||
|
||||
pub fn main() {
|
||||
let osdk_subcommand = match Cli::parse() {
|
||||
let (osdk_subcommand, common_args) = match Cli::parse() {
|
||||
Cli {
|
||||
cargo_subcommand: CargoSubcommand::Osdk(osdk_subcommand),
|
||||
} => osdk_subcommand,
|
||||
common_args,
|
||||
} => (osdk_subcommand, common_args),
|
||||
};
|
||||
|
||||
let load_config = || {
|
||||
let manifest = TomlManifest::load(&common_args.build_args.features);
|
||||
let scheme = manifest.get_scheme(common_args.scheme.as_ref());
|
||||
Config::new(scheme, &common_args)
|
||||
};
|
||||
|
||||
match &osdk_subcommand {
|
||||
OsdkSubcommand::New(args) => execute_new_command(args),
|
||||
OsdkSubcommand::Build(build_args) => {
|
||||
let build_config = BuildConfig::parse(build_args);
|
||||
execute_build_command(&build_config);
|
||||
execute_build_command(&load_config(), build_args);
|
||||
}
|
||||
OsdkSubcommand::Run(run_args) => {
|
||||
let run_config = RunConfig::parse(run_args);
|
||||
execute_run_command(&run_config);
|
||||
execute_run_command(&load_config(), &run_args.gdb_server_args);
|
||||
}
|
||||
OsdkSubcommand::Debug(debug_args) => {
|
||||
let debug_config = DebugConfig::parse(debug_args);
|
||||
execute_debug_command(&debug_config);
|
||||
execute_debug_command(&load_config().run.build.profile, debug_args);
|
||||
}
|
||||
OsdkSubcommand::Test(test_args) => {
|
||||
let test_config = TestConfig::parse(test_args);
|
||||
execute_test_command(&test_config);
|
||||
execute_test_command(&load_config(), test_args);
|
||||
}
|
||||
OsdkSubcommand::Check(args) => execute_forwarded_command("check", &args.args),
|
||||
OsdkSubcommand::Clippy(args) => execute_forwarded_command("clippy", &args.args),
|
||||
@ -54,6 +57,8 @@ pub fn main() {
|
||||
pub struct Cli {
|
||||
#[clap(subcommand)]
|
||||
cargo_subcommand: CargoSubcommand,
|
||||
#[command(flatten)]
|
||||
common_args: CommonArgs,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
@ -136,18 +141,23 @@ impl NewArgs {
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct BuildArgs {
|
||||
#[command(flatten)]
|
||||
pub cargo_args: CargoArgs,
|
||||
#[command(flatten)]
|
||||
pub osdk_args: OsdkArgs,
|
||||
#[arg(
|
||||
long = "for-test",
|
||||
help = "Build for running unit tests",
|
||||
default_value_t
|
||||
)]
|
||||
pub for_test: bool,
|
||||
#[arg(
|
||||
long = "output",
|
||||
short = 'o',
|
||||
help = "Output directory for all generated artifacts",
|
||||
value_name = "DIR"
|
||||
)]
|
||||
pub output: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct RunArgs {
|
||||
#[command(flatten)]
|
||||
pub cargo_args: CargoArgs,
|
||||
#[command(flatten)]
|
||||
pub osdk_args: OsdkArgs,
|
||||
#[command(flatten)]
|
||||
pub gdb_server_args: GdbServerArgs,
|
||||
}
|
||||
@ -181,10 +191,6 @@ pub struct GdbServerArgs {
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct DebugArgs {
|
||||
#[command(flatten)]
|
||||
pub cargo_args: CargoArgs,
|
||||
#[command(flatten)]
|
||||
pub osdk_args: OsdkArgs,
|
||||
#[arg(
|
||||
long,
|
||||
help = "Specify the address of the remote target",
|
||||
@ -195,15 +201,11 @@ pub struct DebugArgs {
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct TestArgs {
|
||||
#[command(flatten)]
|
||||
pub cargo_args: CargoArgs,
|
||||
#[arg(
|
||||
name = "TESTNAME",
|
||||
help = "Only run tests containing this string in their names"
|
||||
)]
|
||||
pub test_name: Option<String>,
|
||||
#[command(flatten)]
|
||||
pub osdk_args: OsdkArgs,
|
||||
}
|
||||
|
||||
#[derive(Debug, Args, Default, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
||||
@ -211,79 +213,120 @@ pub struct CargoArgs {
|
||||
#[arg(
|
||||
long,
|
||||
help = "The Cargo build profile (built-in candidates are 'dev', 'release', 'test' and 'bench')",
|
||||
default_value = "dev",
|
||||
conflicts_with = "release"
|
||||
conflicts_with = "release",
|
||||
global = true
|
||||
)]
|
||||
pub profile: String,
|
||||
pub profile: Option<String>,
|
||||
#[arg(
|
||||
long,
|
||||
help = "Build artifacts in release mode",
|
||||
conflicts_with = "profile"
|
||||
conflicts_with = "profile",
|
||||
global = true
|
||||
)]
|
||||
pub release: bool,
|
||||
#[arg(long, value_name = "FEATURES", help = "List of features to activate", value_delimiter = ',', num_args = 1..)]
|
||||
#[arg(
|
||||
long,
|
||||
value_name = "FEATURES",
|
||||
help = "List of features to activate",
|
||||
value_delimiter = ',',
|
||||
num_args = 1..,
|
||||
global = true,
|
||||
)]
|
||||
pub features: Vec<String>,
|
||||
}
|
||||
|
||||
impl CargoArgs {
|
||||
pub fn profile(&self) -> Option<String> {
|
||||
if self.release {
|
||||
Some("release".to_owned())
|
||||
} else {
|
||||
self.profile.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
pub struct OsdkArgs {
|
||||
#[arg(long, value_name = "ARCH", help = "The architecture to build for")]
|
||||
pub arch: Option<Arch>,
|
||||
pub struct CommonArgs {
|
||||
#[command(flatten)]
|
||||
pub build_args: CargoArgs,
|
||||
#[arg(
|
||||
long = "schema",
|
||||
help = "Select the specific configuration schema provided in the OSDK manifest",
|
||||
value_name = "SCHEMA"
|
||||
long = "linux-x86-legacy-boot",
|
||||
help = "Enable legacy 32-bit boot support for the Linux x86 boot protocol",
|
||||
global = true
|
||||
)]
|
||||
pub schema: Option<String>,
|
||||
pub linux_x86_legacy_boot: bool,
|
||||
#[arg(
|
||||
long = "kcmd_args+",
|
||||
long = "target-arch",
|
||||
value_name = "ARCH",
|
||||
help = "The architecture to build for",
|
||||
global = true
|
||||
)]
|
||||
pub target_arch: Option<Arch>,
|
||||
#[arg(
|
||||
long = "scheme",
|
||||
help = "Select the specific configuration scheme provided in the OSDK manifest",
|
||||
value_name = "SCHEME",
|
||||
global = true
|
||||
)]
|
||||
pub scheme: Option<String>,
|
||||
#[arg(
|
||||
long = "kcmd-args",
|
||||
require_equals = true,
|
||||
help = "Extra or overriding command line arguments for guest kernel",
|
||||
value_name = "ARGS"
|
||||
value_name = "ARGS",
|
||||
global = true
|
||||
)]
|
||||
pub kcmd_args: Vec<String>,
|
||||
#[arg(
|
||||
long = "init_args+",
|
||||
long = "init-args",
|
||||
require_equals = true,
|
||||
help = "Extra command line arguments for init process",
|
||||
value_name = "ARGS"
|
||||
value_name = "ARGS",
|
||||
global = true
|
||||
)]
|
||||
pub init_args: Vec<String>,
|
||||
#[arg(long, help = "Path of initramfs", value_name = "PATH")]
|
||||
#[arg(long, help = "Path of initramfs", value_name = "PATH", global = true)]
|
||||
pub initramfs: Option<PathBuf>,
|
||||
#[arg(long = "ovmf", help = "Path of OVMF", value_name = "PATH")]
|
||||
pub ovmf: Option<PathBuf>,
|
||||
#[arg(long = "opensbi", help = "Path of OpenSBI", value_name = "PATH")]
|
||||
pub opensbi: Option<PathBuf>,
|
||||
#[arg(
|
||||
long = "bootloader",
|
||||
long = "boot-method",
|
||||
help = "Loader for booting the kernel",
|
||||
value_name = "BOOTLOADER"
|
||||
value_name = "BOOTMETHOD",
|
||||
global = true
|
||||
)]
|
||||
pub bootloader: Option<Bootloader>,
|
||||
pub boot_method: Option<BootMethod>,
|
||||
#[arg(
|
||||
long = "display-grub-menu",
|
||||
help = "Display the GRUB menu if booting with GRUB",
|
||||
global = true
|
||||
)]
|
||||
pub display_grub_menu: bool,
|
||||
#[arg(
|
||||
long = "grub-mkrescue",
|
||||
help = "Path of grub-mkrescue",
|
||||
value_name = "PATH"
|
||||
value_name = "PATH",
|
||||
global = true
|
||||
)]
|
||||
pub grub_mkrescue: Option<PathBuf>,
|
||||
#[arg(
|
||||
long = "boot_protocol",
|
||||
long = "grub-boot-protocol",
|
||||
help = "Protocol for booting the kernel",
|
||||
value_name = "BOOT_PROTOCOL"
|
||||
value_name = "BOOT_PROTOCOL",
|
||||
global = true
|
||||
)]
|
||||
pub boot_protocol: Option<BootProtocol>,
|
||||
pub grub_boot_protocol: Option<BootProtocol>,
|
||||
#[arg(
|
||||
long = "qemu_exe",
|
||||
long = "qemu-exe",
|
||||
help = "The QEMU executable file",
|
||||
value_name = "FILE"
|
||||
value_name = "FILE",
|
||||
global = true
|
||||
)]
|
||||
pub qemu_exe: Option<PathBuf>,
|
||||
#[arg(
|
||||
long = "qemu_args+",
|
||||
long = "qemu-args",
|
||||
require_equals = true,
|
||||
help = "Extra arguments or overriding arguments for running QEMU",
|
||||
value_name = "ARGS"
|
||||
value_name = "ARGS",
|
||||
global = true
|
||||
)]
|
||||
pub qemu_args_add: Vec<String>,
|
||||
pub qemu_args: Vec<String>,
|
||||
}
|
||||
|
Reference in New Issue
Block a user