forked from AbleOS/ableos
fix warning
This commit is contained in:
parent
77189e9e3c
commit
8e09af7f15
|
@ -10,217 +10,213 @@ use std::{fs, process::Command};
|
||||||
use colored::*;
|
use colored::*;
|
||||||
|
|
||||||
struct Options {
|
struct Options {
|
||||||
pub subcommand: Subcommand,
|
pub subcommand: Subcommand,
|
||||||
pub arguments: Vec<String>,
|
pub arguments: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Subcommand {
|
enum Subcommand {
|
||||||
Doc,
|
Doc,
|
||||||
Help,
|
Help,
|
||||||
Run,
|
Run,
|
||||||
Empty,
|
Empty,
|
||||||
/// Run all tests for all architectures
|
/// Run all tests for all architectures
|
||||||
Test,
|
Test,
|
||||||
Unknown(String),
|
Unknown(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Subcommand {
|
impl Subcommand {
|
||||||
fn from_str<S: AsRef<str>>(str: S) -> Subcommand {
|
fn from_str<S: AsRef<str>>(str: S) -> Subcommand {
|
||||||
match str.as_ref() {
|
match str.as_ref() {
|
||||||
"doc" => Subcommand::Doc,
|
"doc" => Subcommand::Doc,
|
||||||
"help" => Subcommand::Help,
|
"help" => Subcommand::Help,
|
||||||
"run" => Subcommand::Run,
|
"run" => Subcommand::Run,
|
||||||
"test" => Subcommand::Test,
|
"test" => Subcommand::Test,
|
||||||
"" => Subcommand::Empty,
|
"" => Subcommand::Empty,
|
||||||
unknown => Subcommand::Unknown(unknown.to_string()),
|
unknown => Subcommand::Unknown(unknown.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MachineType {
|
enum MachineType {
|
||||||
X86_64,
|
X86_64,
|
||||||
RiscV64,
|
RiscV64,
|
||||||
AArch64,
|
AArch64,
|
||||||
Unknown(String),
|
Unknown(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let options = options();
|
let options = options();
|
||||||
|
|
||||||
match options.subcommand {
|
match options.subcommand {
|
||||||
Subcommand::Test => {
|
Subcommand::Test => {
|
||||||
Command::new("cargo")
|
Command::new("cargo")
|
||||||
.args(["test", "--target=json_targets/x86_64-ableos.json"])
|
.args(["test", "--target=json_targets/x86_64-ableos.json"])
|
||||||
.current_dir(fs::canonicalize("./ableos").unwrap())
|
.current_dir(fs::canonicalize("./ableos").unwrap())
|
||||||
.status()
|
.status()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// panic!("Test Infrastructure missing");
|
// panic!("Test Infrastructure missing");
|
||||||
}
|
}
|
||||||
Subcommand::Doc => {
|
Subcommand::Doc => {
|
||||||
let machine_text = options
|
let machine_text = options.arguments.get(0).cloned().unwrap_or_default();
|
||||||
.arguments
|
|
||||||
.get(0)
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or_else(|| String::new());
|
|
||||||
|
|
||||||
match machine(machine_text) {
|
match machine(machine_text) {
|
||||||
MachineType::X86_64 => {
|
MachineType::X86_64 => {
|
||||||
Command::new("cargo")
|
Command::new("cargo")
|
||||||
.args(["doc", "--open"])
|
.args(["doc", "--open"])
|
||||||
.current_dir(fs::canonicalize("./ableos").unwrap())
|
.current_dir(fs::canonicalize("./ableos").unwrap())
|
||||||
.status()
|
.status()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
|
||||||
MachineType::RiscV64 => {
|
|
||||||
Command::new("cargo")
|
|
||||||
.args(["doc", "--open", "--target=riscv64gc-unknown-none-elf"])
|
|
||||||
.current_dir(fs::canonicalize("./ableos").unwrap())
|
|
||||||
.status()
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
MachineType::AArch64 => {
|
|
||||||
Command::new("cargo")
|
|
||||||
.args(["doc", "--open", "--target=json_targets/aarch64-ableos.json"])
|
|
||||||
.current_dir(fs::canonicalize("./ableos").unwrap())
|
|
||||||
.status()
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
MachineType::Unknown(unknown) => {
|
|
||||||
eprintln!(
|
|
||||||
"{}: unknown machine type `{}`",
|
|
||||||
"error".red().bold(),
|
|
||||||
unknown.bold(),
|
|
||||||
);
|
|
||||||
eprintln!("expected one of x86_64, riscv64 or aarch64");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
MachineType::RiscV64 => {
|
||||||
Subcommand::Help => help(),
|
Command::new("cargo")
|
||||||
Subcommand::Run => {
|
.args(["doc", "--open", "--target=riscv64gc-unknown-none-elf"])
|
||||||
let machine_text = options.arguments.get(0).cloned().unwrap_or_default();
|
.current_dir(fs::canonicalize("./ableos").unwrap())
|
||||||
let debug = options.arguments.get(1).cloned().unwrap_or_default();
|
.status()
|
||||||
let debug = matches!(debug.as_str(), "--debug" | "--dbg" | "-d");
|
.unwrap();
|
||||||
|
|
||||||
match machine(machine_text) {
|
|
||||||
MachineType::X86_64 if debug => {
|
|
||||||
Command::new("cargo")
|
|
||||||
.args(["run", "--", "-S", "-gdb", "tcp:9000"])
|
|
||||||
.current_dir(fs::canonicalize("./ableos").unwrap())
|
|
||||||
.status()
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
MachineType::X86_64 => {
|
|
||||||
Command::new("cargo")
|
|
||||||
.args(["run", "--release"])
|
|
||||||
.current_dir(fs::canonicalize("./ableos").unwrap())
|
|
||||||
.status()
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
MachineType::RiscV64 if debug => {
|
|
||||||
eprintln!(
|
|
||||||
"{}: debug is not implemented for riscv64",
|
|
||||||
"error".red().bold()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
MachineType::RiscV64 => {
|
|
||||||
Command::new("cargo")
|
|
||||||
.args(["build", "--release", "--target=riscv64gc-unknown-none-elf"])
|
|
||||||
.current_dir(fs::canonicalize("./ableos").unwrap())
|
|
||||||
.status()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
Command::new("qemu-system-riscv64")
|
|
||||||
.args(["-machine", "virt"])
|
|
||||||
.args(["-cpu", "rv64"])
|
|
||||||
.args(["-smp", "8"])
|
|
||||||
.args(["-m", "128M"])
|
|
||||||
.arg("-bios")
|
|
||||||
.arg("src/arch/riscv/firmwear/opensbi-riscv64-generic-fw_jump.bin")
|
|
||||||
.arg("-kernel")
|
|
||||||
.arg("target/riscv64gc-unknown-none-elf/release/ableos")
|
|
||||||
.current_dir(fs::canonicalize("./ableos").unwrap())
|
|
||||||
.status()
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
MachineType::AArch64 if debug => {
|
|
||||||
eprintln!(
|
|
||||||
"{}: debug is not implemented for aarch64",
|
|
||||||
"error".red().bold()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
MachineType::AArch64 => {
|
|
||||||
Command::new("cargo")
|
|
||||||
.args([
|
|
||||||
"build",
|
|
||||||
"--release",
|
|
||||||
"--target=json_targets/aarch64-ableos.json",
|
|
||||||
])
|
|
||||||
.current_dir(fs::canonicalize("./ableos").unwrap())
|
|
||||||
.status()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
Command::new("qemu-system-aarch64")
|
|
||||||
.args(["-machine", "virt"])
|
|
||||||
.args(["-m", "1024M"])
|
|
||||||
.args(["-cpu", "cortex-a53"])
|
|
||||||
.args(["-kernel", "target/aarch64-ableos/release/ableos"])
|
|
||||||
.args(["-device", "virtio-keyboard"])
|
|
||||||
.current_dir(fs::canonicalize("./ableos").unwrap())
|
|
||||||
.status()
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
MachineType::Unknown(unknown) => {
|
|
||||||
eprintln!(
|
|
||||||
"{}: unknown machine type `{}`",
|
|
||||||
"error".red().bold(),
|
|
||||||
unknown.bold(),
|
|
||||||
);
|
|
||||||
eprintln!("expected one of x86_64, riscv64 or aarch64");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
MachineType::AArch64 => {
|
||||||
Subcommand::Empty => {
|
Command::new("cargo")
|
||||||
eprintln!("{}: no subcommand passed", "error".red().bold());
|
.args(["doc", "--open", "--target=json_targets/aarch64-ableos.json"])
|
||||||
help();
|
.current_dir(fs::canonicalize("./ableos").unwrap())
|
||||||
}
|
.status()
|
||||||
Subcommand::Unknown(unknown) => {
|
.unwrap();
|
||||||
eprintln!(
|
}
|
||||||
"{}: unknown subcommand `{}`",
|
MachineType::Unknown(unknown) => {
|
||||||
"error".red().bold(),
|
eprintln!(
|
||||||
unknown.bold()
|
"{}: unknown machine type `{}`",
|
||||||
);
|
"error".red().bold(),
|
||||||
help();
|
unknown.bold(),
|
||||||
}
|
);
|
||||||
}
|
eprintln!("expected one of x86_64, riscv64 or aarch64");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Subcommand::Help => help(),
|
||||||
|
Subcommand::Run => {
|
||||||
|
let machine_text = options.arguments.get(0).cloned().unwrap_or_default();
|
||||||
|
let debug = options.arguments.get(1).cloned().unwrap_or_default();
|
||||||
|
let debug = matches!(debug.as_str(), "--debug" | "--dbg" | "-d");
|
||||||
|
|
||||||
|
match machine(machine_text) {
|
||||||
|
MachineType::X86_64 if debug => {
|
||||||
|
Command::new("cargo")
|
||||||
|
.args(["run", "--", "-S", "-gdb", "tcp:9000"])
|
||||||
|
.current_dir(fs::canonicalize("./ableos").unwrap())
|
||||||
|
.status()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
MachineType::X86_64 => {
|
||||||
|
Command::new("cargo")
|
||||||
|
.args(["run", "--release"])
|
||||||
|
.current_dir(fs::canonicalize("./ableos").unwrap())
|
||||||
|
.status()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
MachineType::RiscV64 if debug => {
|
||||||
|
eprintln!(
|
||||||
|
"{}: debug is not implemented for riscv64",
|
||||||
|
"error".red().bold()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
MachineType::RiscV64 => {
|
||||||
|
Command::new("cargo")
|
||||||
|
.args(["build", "--release", "--target=riscv64gc-unknown-none-elf"])
|
||||||
|
.current_dir(fs::canonicalize("./ableos").unwrap())
|
||||||
|
.status()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
Command::new("qemu-system-riscv64")
|
||||||
|
.args(["-machine", "virt"])
|
||||||
|
.args(["-cpu", "rv64"])
|
||||||
|
.args(["-smp", "8"])
|
||||||
|
.args(["-m", "128M"])
|
||||||
|
.arg("-bios")
|
||||||
|
.arg("src/arch/riscv/firmwear/opensbi-riscv64-generic-fw_jump.bin")
|
||||||
|
.arg("-kernel")
|
||||||
|
.arg("target/riscv64gc-unknown-none-elf/release/ableos")
|
||||||
|
.current_dir(fs::canonicalize("./ableos").unwrap())
|
||||||
|
.status()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
MachineType::AArch64 if debug => {
|
||||||
|
eprintln!(
|
||||||
|
"{}: debug is not implemented for aarch64",
|
||||||
|
"error".red().bold()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
MachineType::AArch64 => {
|
||||||
|
Command::new("cargo")
|
||||||
|
.args([
|
||||||
|
"build",
|
||||||
|
"--release",
|
||||||
|
"--target=json_targets/aarch64-ableos.json",
|
||||||
|
])
|
||||||
|
.current_dir(fs::canonicalize("./ableos").unwrap())
|
||||||
|
.status()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
Command::new("qemu-system-aarch64")
|
||||||
|
.args(["-machine", "virt"])
|
||||||
|
.args(["-m", "1024M"])
|
||||||
|
.args(["-cpu", "cortex-a53"])
|
||||||
|
.args(["-kernel", "target/aarch64-ableos/release/ableos"])
|
||||||
|
.args(["-device", "virtio-keyboard"])
|
||||||
|
.current_dir(fs::canonicalize("./ableos").unwrap())
|
||||||
|
.status()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
MachineType::Unknown(unknown) => {
|
||||||
|
eprintln!(
|
||||||
|
"{}: unknown machine type `{}`",
|
||||||
|
"error".red().bold(),
|
||||||
|
unknown.bold(),
|
||||||
|
);
|
||||||
|
eprintln!("expected one of x86_64, riscv64 or aarch64");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Subcommand::Empty => {
|
||||||
|
eprintln!("{}: no subcommand passed", "error".red().bold());
|
||||||
|
help();
|
||||||
|
}
|
||||||
|
Subcommand::Unknown(unknown) => {
|
||||||
|
eprintln!(
|
||||||
|
"{}: unknown subcommand `{}`",
|
||||||
|
"error".red().bold(),
|
||||||
|
unknown.bold()
|
||||||
|
);
|
||||||
|
help();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn options() -> Options {
|
fn options() -> Options {
|
||||||
let subcommand = std::env::args().nth(1).unwrap_or_default();
|
let subcommand = std::env::args().nth(1).unwrap_or_default();
|
||||||
let arguments = std::env::args().skip(2).collect();
|
let arguments = std::env::args().skip(2).collect();
|
||||||
|
|
||||||
Options {
|
Options {
|
||||||
subcommand: Subcommand::from_str(subcommand),
|
subcommand: Subcommand::from_str(subcommand),
|
||||||
arguments,
|
arguments,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn machine<S: AsRef<str>>(text: S) -> MachineType {
|
fn machine<S: AsRef<str>>(text: S) -> MachineType {
|
||||||
match text.as_ref() {
|
match text.as_ref() {
|
||||||
"x86" | "x86_64" => MachineType::X86_64,
|
"x86" | "x86_64" => MachineType::X86_64,
|
||||||
"riscv" | "riscv64" => MachineType::RiscV64,
|
"riscv" | "riscv64" => MachineType::RiscV64,
|
||||||
"arm" | "arm64" | "aarch64" => MachineType::AArch64,
|
"arm" | "arm64" | "aarch64" => MachineType::AArch64,
|
||||||
"" => {
|
"" => {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"{}: no machine type passed, defaulting to x86_64",
|
"{}: no machine type passed, defaulting to x86_64",
|
||||||
"warning".yellow().bold()
|
"warning".yellow().bold()
|
||||||
);
|
);
|
||||||
MachineType::X86_64
|
MachineType::X86_64
|
||||||
}
|
}
|
||||||
unknown => MachineType::Unknown(unknown.to_string()),
|
unknown => MachineType::Unknown(unknown.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn help() {
|
fn help() {
|
||||||
todo!("`help`")
|
todo!("`help`")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue