mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-08 12:56:48 +00:00
Multiple ways to specify OSDK new's type
This commit is contained in:
parent
dcab4e1039
commit
3dce753c86
@ -13,7 +13,7 @@ Creating a new kernel project is simple.
|
||||
You only need to execute the following command:
|
||||
|
||||
```bash
|
||||
cargo osdk new --type kernel myos
|
||||
cargo osdk new --kernel myos
|
||||
```
|
||||
|
||||
## Creating a new library project
|
||||
|
@ -8,7 +8,7 @@ Suppose you have created a new kernel project named `myos`
|
||||
and you are in the project directory:
|
||||
|
||||
```bash
|
||||
cargo osdk new --type kernel myos && cd myos
|
||||
cargo osdk new --kernel myos && cd myos
|
||||
```
|
||||
|
||||
## Build the project
|
||||
|
@ -24,7 +24,7 @@ Then, add the following content to `Cargo.toml`:
|
||||
The two projects can be created using the following commands:
|
||||
|
||||
```bash
|
||||
cargo osdk new --type kernel myos
|
||||
cargo osdk new --kernel myos
|
||||
cargo osdk new mymodule
|
||||
```
|
||||
|
||||
|
@ -17,7 +17,7 @@ cargo osdk new [OPTIONS] <name>
|
||||
|
||||
## Options
|
||||
|
||||
`--type kernel`:
|
||||
`--kernel`:
|
||||
Use the kernel template.
|
||||
If this option is not set,
|
||||
the library template will be used by default.
|
||||
@ -27,7 +27,7 @@ the library template will be used by default.
|
||||
- Create a new kernel named `myos`:
|
||||
|
||||
```bash
|
||||
cargo osdk new --type kernel myos
|
||||
cargo osdk new --kernel myos
|
||||
```
|
||||
|
||||
- Create a new library named `mymodule`:
|
||||
|
@ -56,7 +56,7 @@ Here we provide a simple demo to demonstrate how to create and run a simple kern
|
||||
|
||||
With `cargo-osdk`, a kernel project can be created by one command
|
||||
```bash
|
||||
cargo osdk new --type kernel my-first-os
|
||||
cargo osdk new --kernel my-first-os
|
||||
```
|
||||
|
||||
Then, you can run the kernel with
|
||||
|
@ -97,16 +97,43 @@ pub struct ForwardedArguments {
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct NewArgs {
|
||||
#[arg(
|
||||
id = "type",
|
||||
long = "type",
|
||||
short = 't',
|
||||
default_value = "library",
|
||||
help = "The type of the project to create"
|
||||
help = "The type of the project to create",
|
||||
conflicts_with_all = ["kernel", "library"],
|
||||
)]
|
||||
pub type_: ProjectType,
|
||||
#[arg(
|
||||
long,
|
||||
help = "Create a kernel package",
|
||||
conflicts_with_all = ["library", "type"],
|
||||
)]
|
||||
pub kernel: bool,
|
||||
#[arg(
|
||||
long,
|
||||
alias = "lib",
|
||||
help = "Create a library package",
|
||||
conflicts_with_all = ["kernel", "type"],
|
||||
)]
|
||||
pub library: bool,
|
||||
#[arg(name = "name", required = true)]
|
||||
pub crate_name: String,
|
||||
}
|
||||
|
||||
impl NewArgs {
|
||||
pub fn project_type(&self) -> ProjectType {
|
||||
if self.kernel {
|
||||
ProjectType::Kernel
|
||||
} else if self.library {
|
||||
ProjectType::Library
|
||||
} else {
|
||||
self.type_
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct BuildArgs {
|
||||
#[command(flatten)]
|
||||
|
@ -14,9 +14,9 @@ pub fn execute_new_command(args: &NewArgs) {
|
||||
cargo_new_lib(&args.crate_name);
|
||||
let cargo_metadata = get_cargo_metadata(Some(&args.crate_name), None::<&[&str]>).unwrap();
|
||||
add_manifest_dependencies(&cargo_metadata, &args.crate_name);
|
||||
create_osdk_manifest(&cargo_metadata, &args.type_);
|
||||
create_osdk_manifest(&cargo_metadata, &args.project_type());
|
||||
exclude_osdk_base(&cargo_metadata);
|
||||
write_src_template(&cargo_metadata, &args.crate_name, &args.type_);
|
||||
write_src_template(&cargo_metadata, &args.crate_name, &args.project_type());
|
||||
add_rust_toolchain(&cargo_metadata);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ pub struct Project {
|
||||
pub type_: ProjectType,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ValueEnum, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ValueEnum, PartialEq, Eq)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum ProjectType {
|
||||
Kernel,
|
||||
|
@ -1,6 +1,9 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use std::{fs::remove_dir_all, path::Path};
|
||||
use std::{
|
||||
fs::remove_dir_all,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use crate::util::*;
|
||||
|
||||
@ -14,10 +17,20 @@ fn create_kernel_in_workspace() {
|
||||
remove_dir_all(WORKSPACE_NAME).unwrap();
|
||||
}
|
||||
create_workspace(WORKSPACE_NAME, &[KERNEL_NAME]);
|
||||
let mut cargo_osdk = cargo_osdk(["new", "--type", "kernel", KERNEL_NAME]);
|
||||
cargo_osdk.current_dir(WORKSPACE_NAME);
|
||||
let output = cargo_osdk.output().unwrap();
|
||||
let kernel_path = PathBuf::from(WORKSPACE_NAME).join(KERNEL_NAME);
|
||||
|
||||
let mut cmd = cargo_osdk(["new", "--kernel", KERNEL_NAME]);
|
||||
cmd.current_dir(WORKSPACE_NAME);
|
||||
let output = cmd.output().unwrap();
|
||||
assert_success(&output);
|
||||
remove_dir_all(&kernel_path).unwrap();
|
||||
|
||||
let mut cmd = cargo_osdk(["new", "-t", "kernel", KERNEL_NAME]);
|
||||
cmd.current_dir(WORKSPACE_NAME);
|
||||
let output = cmd.output().unwrap();
|
||||
assert_success(&output);
|
||||
remove_dir_all(&kernel_path).unwrap();
|
||||
|
||||
remove_dir_all(WORKSPACE_NAME).unwrap();
|
||||
}
|
||||
|
||||
@ -51,7 +64,7 @@ fn create_two_crates_in_workspace() {
|
||||
|
||||
add_member_to_workspace(WORKSPACE_NAME, KERNEL_NAME);
|
||||
// Create kernel crate
|
||||
let mut command = cargo_osdk(["new", "--type", "kernel", KERNEL_NAME]);
|
||||
let mut command = cargo_osdk(["new", "--kernel", KERNEL_NAME]);
|
||||
command.current_dir(WORKSPACE_NAME);
|
||||
let output = command.output().unwrap();
|
||||
assert_success(&output);
|
||||
|
@ -15,7 +15,7 @@ fn create_a_kernel_project() {
|
||||
fs::remove_dir_all(&kernel_path).unwrap();
|
||||
}
|
||||
|
||||
cargo_osdk(&["new", "--type", "kernel", kernel])
|
||||
cargo_osdk(&["new", "--kernel", kernel])
|
||||
.current_dir(workdir)
|
||||
.unwrap();
|
||||
|
||||
|
@ -15,7 +15,7 @@ fn create_and_run_kernel() {
|
||||
fs::remove_dir_all(&os_dir).unwrap();
|
||||
}
|
||||
|
||||
let mut command = cargo_osdk(&["new", "--type", "kernel", os_name]);
|
||||
let mut command = cargo_osdk(&["new", "--kernel", os_name]);
|
||||
command.current_dir(work_dir);
|
||||
command.ok().unwrap();
|
||||
|
||||
|
@ -29,9 +29,7 @@ fn work_in_workspace() {
|
||||
// Create a kernel project and a library project
|
||||
let kernel = "myos";
|
||||
let module = "mymodule";
|
||||
cargo_osdk(&["new", "--type", "kernel", kernel])
|
||||
.ok()
|
||||
.unwrap();
|
||||
cargo_osdk(&["new", "--kernel", kernel]).ok().unwrap();
|
||||
cargo_osdk(&["new", module]).ok().unwrap();
|
||||
|
||||
// Add a test function to mymodule/src/lib.rs
|
||||
|
Loading…
x
Reference in New Issue
Block a user