Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- run: cargo build
- run: ./target/debug/catapult -S test_data/test_01 -B build -G Ninja -T test_data/toolchain_gcc.toml
- run: ./target/debug/catapult generate -S test_data/test_01 -B build -G Ninja -T test_data/toolchain_gcc.toml
- run: tree build
- run: cat build/build.ninja
- run: ninja -C build -v myexe mytest
Expand All @@ -66,15 +66,15 @@ jobs:
uses: actions/checkout@v4
- run: cargo build

- run: ./target/debug/catapult --source-dir test_data/test_01 --build-dir build_debug --generator Ninja --toolchain test_data/toolchain_clang.toml --profile Debug
- run: ./target/debug/catapult generate --source-dir test_data/test_01 --build-dir build_debug --generator Ninja --toolchain test_data/toolchain_clang.toml --profile Debug
- run: tree build_debug
- run: cat build_debug/build.ninja
- run: ninja -C build_debug -v myexe mytest
- run: tree build_debug
- run: ./build_debug/test_one/myexe abc def
- run: ./build_debug/my_depend/mytest

- run: ./target/debug/catapult --source-dir test_data/test_01 --build-dir build_release --generator Ninja --toolchain test_data/toolchain_clang.toml --profile Release
- run: ./target/debug/catapult generate --source-dir test_data/test_01 --build-dir build_release --generator Ninja --toolchain test_data/toolchain_clang.toml --profile Release
- run: tree build_release
- run: cat build_release/build.ninja
- run: ninja -C build_release -v myexe mytest
Expand All @@ -97,15 +97,15 @@ jobs:
uses: ./.github/install-emscripten
- run: cargo build

- run: ./target/debug/catapult --source-dir test_data/test_01 --build-dir build_debug --generator Ninja --toolchain test_data/toolchain_emscripten.toml --profile Debug
- run: ./target/debug/catapult generate --source-dir test_data/test_01 --build-dir build_debug --generator Ninja --toolchain test_data/toolchain_emscripten.toml --profile Debug
- run: tree build_debug
- run: cat build_debug/build.ninja
- run: ninja -C build_debug -v myexe mytest
- run: tree build_debug
- run: node ./build_debug/test_one/myexe abc def
- run: node ./build_debug/my_depend/mytest

- run: ./target/debug/catapult --source-dir test_data/test_01 --build-dir build_release --generator Ninja --toolchain test_data/toolchain_emscripten.toml --profile Release
- run: ./target/debug/catapult generate --source-dir test_data/test_01 --build-dir build_release --generator Ninja --toolchain test_data/toolchain_emscripten.toml --profile Release
- run: tree build_release
- run: cat build_release/build.ninja
- run: ninja -C build_release -v myexe mytest
Expand All @@ -123,7 +123,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- run: cargo build
- run: ./target/debug/catapult --source-dir test_data/test_01 --build-dir build --generator MSVC --toolchain test_data/toolchain_msvc.toml
- run: ./target/debug/catapult generate --source-dir test_data/test_01 --build-dir build --generator MSVC --toolchain test_data/toolchain_msvc.toml
- run: tree /f build

- shell: cmd
Expand Down Expand Up @@ -165,7 +165,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- run: cargo build
- run: ./target/debug/catapult --source-dir test_data/test_01 --build-dir build --generator Ninja --toolchain test_data/toolchain_clang_win.toml --profile Debug
- run: ./target/debug/catapult generate --source-dir test_data/test_01 --build-dir build --generator Ninja --toolchain test_data/toolchain_clang_win.toml --profile Debug
- run: tree /f build
- run: Get-Content build/build.ninja
- run: ninja -C build -v myexe mytest
Expand Down
109 changes: 97 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"

[[bin]]
name = "catapult"
path = "src/main.rs"
path = "src/bin/main.rs"

[lib]
name = "catapult"
Expand All @@ -18,10 +18,10 @@ name = "catapult"
allocative = "0.3.1"
anyhow = "1.0.65"
base64 = "0.21"
clap = { version = "4.5.42" }
dirs = "5.0.1"
env_logger = "0.10"
flate2 = "1.0"
getopts = "0.2"
log = "0.4"
reqwest = { version = "0.11", features = ["blocking", "json"] }
serde = "1.0"
Expand All @@ -33,3 +33,6 @@ uuid = { version = "1.4", features = [
"fast-rng", # Use a faster (but still sufficiently random) RNG
"macro-diagnostics", # Enable better diagnostics for compile-time UUIDs
] }

[lints.clippy]
uninlined_format_args = "allow"
86 changes: 17 additions & 69 deletions src/main.rs → src/bin/commands/generate.rs
Original file line number Diff line number Diff line change
@@ -1,76 +1,27 @@
use std::{
collections::BTreeMap,
env, //
collections::BTreeMap, //
env,
fs,
path,
process::ExitCode,
};

use getopts::Options;

use catapult::{generator::Generator, toolchain};

fn print_usage(program: &str, opts: Options) {
let brief = format!("Usage: {} FILE [options]", program);
print!("{}", opts.usage(&brief));
}

fn main() -> ExitCode {
env_logger::Builder::from_env(env_logger::Env::default().filter_or("CATAPULT_LOG", "off"))
.format_timestamp(None)
.init();

let args: Vec<String> = env::args().collect();
let program = args[0].clone();

const SOURCE_DIR: &str = "source-dir";
const BUILD_DIR: &str = "build-dir";
const GENERATOR: &str = "generator";
const TOOLCHAIN: &str = "toolchain";
const PROFILE: &str = "profile";
const PACKAGE_OPTION: &str = "package-option";
use clap::ArgMatches;

let mut opts = Options::new();
opts.optopt("S", SOURCE_DIR, "Specify the source directory", "<path-to-source>");
opts.optopt("B", BUILD_DIR, "Specify the build directory", "<path-to-build>");
opts.optopt("G", GENERATOR, "Specify a build system generator", "<generator-name>");
opts.optopt("T", TOOLCHAIN, "Specify a path to a toolchain file", "<path-to-toolchain-file>");
opts.optopt("P", PROFILE, "Specify the profile to build", "<profile-name>");
opts.optmulti("p", PACKAGE_OPTION, "Override a package option", "<package name>:<option>=<value>");
opts.optflag("h", "help", "print this help menu");
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => {
println!("Error: {}", f);
print_usage(&program, opts);
return ExitCode::FAILURE;
}
};
if matches.opt_present("h") {
print_usage(&program, opts);
return ExitCode::SUCCESS;
}
pub(crate) fn handle_generate_command(matches: &ArgMatches) -> ExitCode {
let src_dir = matches.get_one::<String>("source-dir").unwrap();
let build_dir = matches.get_one::<String>("build-dir").unwrap();
let generator_str = matches.get_one::<String>("generator").unwrap();
let toolchain_opt = matches.get_one::<String>("toolchain");
let profile_opt = matches.get_one::<String>("profile");
let package_opts_vec: Vec<&String> = matches
.get_many::<String>("package-option")
.unwrap_or_default()
.collect();

let mut all_required_opts_present = true;
let mut match_str = |opt: &str| -> String {
match matches.opt_str(opt) {
Some(x) => x,
None => {
println!("Error: Required option '--{}' missing", opt);
all_required_opts_present = false;
String::new()
}
}
};
let src_dir = match_str(SOURCE_DIR);
let build_dir = match_str(BUILD_DIR);
let generator_str = match_str(GENERATOR);
if !all_required_opts_present {
print_usage(&program, opts);
return ExitCode::FAILURE;
}

let toolchain_path = match matches.opt_str(TOOLCHAIN) {
let toolchain_path = match toolchain_opt {
Some(x) => path::PathBuf::from(x),
None => {
let cache_dir = match dirs::config_dir() {
Expand All @@ -96,9 +47,6 @@ fn main() -> ExitCode {
}
};

let profile_opt = matches.opt_str(PROFILE);

let package_opts_vec = matches.opt_strs(PACKAGE_OPTION);
type InnerMap = BTreeMap<String, String>;
let mut package_options = BTreeMap::<String, InnerMap>::new();
for pkg_opt in package_opts_vec {
Expand Down Expand Up @@ -129,7 +77,7 @@ fn main() -> ExitCode {
println!(" build-dir: {}", build_dir);
println!(" generator: {}", generator_str);
println!(" toolchain: {}", toolchain_path.display());
println!(" profile: {}", profile_opt.as_deref().unwrap_or_default());
println!(" profile: {}", profile_opt.unwrap_or(&String::new()));
println!("package-options: {}", {
let mut ret = String::new();
for (pkg_name, opts) in &package_options {
Expand Down Expand Up @@ -159,7 +107,7 @@ fn main() -> ExitCode {
};

// Check source dir exists before erroring on anything else
match env::set_current_dir(&src_dir) {
match env::set_current_dir(src_dir) {
Ok(x) => x,
Err(e) => {
println!("Error setting cwd: {} (path: {})", e, src_dir);
Expand Down Expand Up @@ -197,7 +145,7 @@ fn main() -> ExitCode {
println!("--profile is incompatible with MSVC generator");
return ExitCode::FAILURE;
};
match toolchain.profile.get(&prof) {
match toolchain.profile.get(prof) {
None => {
println!("Selected profile is not provided by toolchain");
return ExitCode::FAILURE;
Expand Down
2 changes: 2 additions & 0 deletions src/bin/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod generate;
pub mod new;
Loading
Loading