From 1c491e70e02f255f0718f2f2e333b010d3aadaae Mon Sep 17 00:00:00 2001 From: Able Date: Wed, 28 Aug 2024 14:35:08 -0500 Subject: [PATCH] dev tool prototype --- .cargo/config.toml | 1 + Cargo.lock | 4 ++ Cargo.toml | 2 +- README.md | 3 ++ dev/Cargo.toml | 6 +++ dev/README.md | 6 +++ dev/src/main.rs | 98 ++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 dev/Cargo.toml create mode 100644 dev/README.md create mode 100644 dev/src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index bda5800..b335393 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,3 @@ [alias] repbuild = "run --manifest-path ./repbuild/Cargo.toml -r --" +dev = "run --manifest-path ./dev/Cargo.toml -r --" diff --git a/Cargo.lock b/Cargo.lock index cc15445..b75962c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -245,6 +245,10 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "dev" +version = "0.1.0" + [[package]] name = "embedded-graphics" version = "0.7.1" diff --git a/Cargo.toml b/Cargo.toml index 9d2b277..85e0ede 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] resolver = "2" -members = ["kernel", "repbuild"] +members = [ "dev","kernel", "repbuild"] diff --git a/README.md b/README.md index 5c07362..181fbb1 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,6 @@ For running AbleOS, `repbuild` uses QEMU. 1. Ensure you have qemu installed 2. `git submodule update --init` 3. `cargo repbuild run` + +# Developing +There is a new work in progress developer tool for hblang. \ No newline at end of file diff --git a/dev/Cargo.toml b/dev/Cargo.toml new file mode 100644 index 0000000..0cf2f73 --- /dev/null +++ b/dev/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "dev" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/dev/README.md b/dev/README.md new file mode 100644 index 0000000..0ccaea7 --- /dev/null +++ b/dev/README.md @@ -0,0 +1,6 @@ +# dev +`dev` is an ableOS specific tool meant to help the development of ableOS. + +At the current stage changes are not welcome. If you have feature suggestions ping me on discord `@abletheabove`. + +Run `cargo dev help` to see usage. \ No newline at end of file diff --git a/dev/src/main.rs b/dev/src/main.rs new file mode 100644 index 0000000..0be0157 --- /dev/null +++ b/dev/src/main.rs @@ -0,0 +1,98 @@ +use std::{fmt::format, io::Write}; + +pub enum Options { + Build, + Clean, + New, + Run, +} + +fn main() { + let mut args: Vec = std::env::args().collect(); + args.remove(0); + args.reverse(); + + let binding = args.pop().unwrap_or("help".to_string()); + let subcommand = binding.as_str(); + + match subcommand { + "build" => { + let name = &args[1]; + build(name.to_string()) + } + "new" => { + let binding = args.pop().unwrap(); + let dev_type = binding.as_str(); + let name = args.pop().unwrap(); + match dev_type { + "lib" | "library" => new(true, name), + "prog" | "program" => new(false, name), + _ => {} + }; + } + "run" => run(), + + "help" => { + // println!("This is the help message."); + // println!("A prototype build tool meant to help with ableOS software development."); + help() + } + _ => { + println!("Error"); + } + } +} + +pub fn new(library: bool, name: String) { + let (folder_hierarchy, entry_name) = match library { + true => ("libraries", "lib.hb"), + false => ("programs", "main.hb"), + }; + let project_folder_path_string = format!("sysdata/{folder_hierarchy}/{name}"); + + if std::path::Path::new(&project_folder_path_string).exists() { + panic!("Project already exists.") + } + + std::fs::create_dir(project_folder_path_string.clone()).unwrap(); + let readme_path_string = format!("{}/README.md", project_folder_path_string); + let mut readme_file = std::fs::File::create(readme_path_string.clone()).unwrap(); + + let readme_contents = format!("# {}", name); + readme_file.write_all(readme_contents.as_bytes()).unwrap(); + + let src_folder_path_string = format!("{}/src", project_folder_path_string); + std::fs::create_dir(src_folder_path_string.clone()).unwrap(); + + let full_path_string = format!("{src_folder_path_string}/{entry_name}"); + let mut file = std::fs::File::create(full_path_string.clone()).unwrap(); + let file_contents = if library { + "" + } else { + "main := fn(): int { + return 0 +}" + } + .to_string(); + file.write_all(file_contents.as_bytes()).unwrap(); + + println!("{}", full_path_string); +} + +fn run() { + println!("Running is not supported on a non-ableOS platform"); +} + +fn build(name: String) { + println!("building {}", name); +} + +fn help() { + println!( + "========== += Help = +========== +Subcommands +- new Usage: `cargo dev new library name` or `cargo dev new program name`" + ) +}