diff --git a/.cargo/config.toml b/.cargo/config.toml index bda58004..b3353930 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 cc154456..b75962c2 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 9d2b277e..85e0ede6 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 5c07362b..181fbb13 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 00000000..0cf2f73c --- /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 00000000..0ccaea72 --- /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 00000000..0be01577 --- /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`" + ) +}