From af72c697a9e10f8f03da8822a56fdc3878f75883 Mon Sep 17 00:00:00 2001 From: Young-Flash Date: Wed, 27 Nov 2024 10:05:26 +0800 Subject: [PATCH 1/2] feat: allow config warn list by passing cli args --- crates/moon/src/cli.rs | 10 ++++++++ crates/moon/tests/test_cases/mod.rs | 38 +++++++++++++++++++++++++++++ crates/moonutil/src/common.rs | 4 +++ crates/moonutil/src/package.rs | 2 ++ crates/moonutil/src/scan.rs | 6 +++++ docs/manual-zh/src/commands.md | 8 ++++++ docs/manual/src/commands.md | 8 ++++++ 7 files changed, 76 insertions(+) diff --git a/crates/moon/src/cli.rs b/crates/moon/src/cli.rs index c1391387..325a703e 100644 --- a/crates/moon/src/cli.rs +++ b/crates/moon/src/cli.rs @@ -179,6 +179,14 @@ pub struct BuildFlags { /// Don't render diagnostics from moonc (don't pass '-error-format json' to moonc) #[clap(long)] pub no_render: bool, + + /// Warn list config + #[clap(long, allow_hyphen_values = true)] + pub warn_list: Option, + + /// Alert list config + #[clap(long, allow_hyphen_values = true)] + pub alert_list: Option, } impl BuildFlags { @@ -230,6 +238,8 @@ pub fn get_compiler_flags(src_dir: &Path, build_flags: &BuildFlags) -> anyhow::R enable_coverage, deny_warn: false, target_backend, + warn_list: build_flags.warn_list.clone(), + alert_list: build_flags.alert_list.clone(), }; let link_opt = LinkCoreFlags { diff --git a/crates/moon/tests/test_cases/mod.rs b/crates/moon/tests/test_cases/mod.rs index c5537218..f2ef3e31 100644 --- a/crates/moon/tests/test_cases/mod.rs +++ b/crates/moon/tests/test_cases/mod.rs @@ -3575,6 +3575,25 @@ fn test_warn_list_dry_run() { moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/release/build/lib/lib.core ./target/wasm-gc/release/build/lib1/lib1.core ./target/wasm-gc/release/build/main/main.core -main username/hello/main -o ./target/wasm-gc/release/build/main/main.wasm -pkg-config-path ./main/moon.pkg.json -pkg-sources username/hello/lib:./lib -pkg-sources username/hello/lib1:./lib1 -pkg-sources username/hello/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target wasm-gc "#]], ); + check( + get_stdout( + &dir, + [ + "build", + "--warn-list", + "-29", + "--sort-input", + "--no-render", + "--dry-run", + ], + ), + expect![[r#" + moonc build-package ./lib/hello.mbt -w -2-29 -o ./target/wasm-gc/release/build/lib/lib.core -pkg username/hello/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib:./lib -target wasm-gc + moonc build-package ./lib1/hello.mbt -w -1-29 -o ./target/wasm-gc/release/build/lib1/lib1.core -pkg username/hello/lib1 -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib1:./lib1 -target wasm-gc + moonc build-package ./main/main.mbt -w -1-2-29 -o ./target/wasm-gc/release/build/main/main.core -pkg username/hello/main -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/build/lib/lib.mi:lib -i ./target/wasm-gc/release/build/lib1/lib1.mi:lib1 -pkg-sources username/hello/main:./main -target wasm-gc + moonc link-core $MOON_HOME/lib/core/target/wasm-gc/release/bundle/core.core ./target/wasm-gc/release/build/lib/lib.core ./target/wasm-gc/release/build/lib1/lib1.core ./target/wasm-gc/release/build/main/main.core -main username/hello/main -o ./target/wasm-gc/release/build/main/main.wasm -pkg-config-path ./main/moon.pkg.json -pkg-sources username/hello/lib:./lib -pkg-sources username/hello/lib1:./lib1 -pkg-sources username/hello/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target wasm-gc + "#]], + ); check( get_stdout(&dir, ["test", "--sort-input"]), @@ -3605,6 +3624,25 @@ fn test_warn_list_dry_run() { moonc check ./lib/hello_test.mbt -w -2 -o ./target/wasm-gc/release/check/lib/lib.blackbox_test.mi -pkg username/hello/lib_blackbox_test -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/lib/lib.mi:lib -pkg-sources username/hello/lib_blackbox_test:./lib -target wasm-gc -blackbox-test "#]], ); + check( + get_stdout( + &dir, + [ + "check", + "--warn-list", + "-29", + "--sort-input", + "--no-render", + "--dry-run", + ], + ), + expect![[r#" + moonc check ./lib/hello.mbt -w -2-29 -o ./target/wasm-gc/release/check/lib/lib.mi -pkg username/hello/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib:./lib -target wasm-gc + moonc check ./lib1/hello.mbt -w -1-29 -o ./target/wasm-gc/release/check/lib1/lib1.mi -pkg username/hello/lib1 -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib1:./lib1 -target wasm-gc + moonc check ./main/main.mbt -w -1-2-29 -o ./target/wasm-gc/release/check/main/main.mi -pkg username/hello/main -is-main -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/lib/lib.mi:lib -i ./target/wasm-gc/release/check/lib1/lib1.mi:lib1 -pkg-sources username/hello/main:./main -target wasm-gc + moonc check ./lib/hello_test.mbt -w -2-29 -o ./target/wasm-gc/release/check/lib/lib.blackbox_test.mi -pkg username/hello/lib_blackbox_test -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/lib/lib.mi:lib -pkg-sources username/hello/lib_blackbox_test:./lib -target wasm-gc -blackbox-test + "#]], + ); } #[test] diff --git a/crates/moonutil/src/common.rs b/crates/moonutil/src/common.rs index 15f0970d..14f36440 100644 --- a/crates/moonutil/src/common.rs +++ b/crates/moonutil/src/common.rs @@ -294,6 +294,8 @@ pub struct BuildPackageFlags { // treat all warnings as errors pub deny_warn: bool, pub target_backend: TargetBackend, + pub warn_list: Option, + pub alert_list: Option, } impl BuildPackageFlags { @@ -304,6 +306,8 @@ impl BuildPackageFlags { enable_coverage: false, deny_warn: false, target_backend: TargetBackend::default(), + warn_list: None, + alert_list: None, } } } diff --git a/crates/moonutil/src/package.rs b/crates/moonutil/src/package.rs index 2ca13c95..0b4c7fbe 100644 --- a/crates/moonutil/src/package.rs +++ b/crates/moonutil/src/package.rs @@ -61,6 +61,8 @@ pub struct Package { pub artifact: PathBuf, pub link: Option, + + // moon.mod.json + moon.pkg.json + cli passing value pub warn_list: Option, pub alert_list: Option, diff --git a/crates/moonutil/src/scan.rs b/crates/moonutil/src/scan.rs index eebfa300..52a5e312 100644 --- a/crates/moonutil/src/scan.rs +++ b/crates/moonutil/src/scan.rs @@ -288,12 +288,18 @@ fn scan_one_package( .as_ref() .map_or(pkg.warn_list.clone(), |x| { Some(x.clone() + &pkg.warn_list.unwrap_or_default()) + }) + .map_or(moonc_opt.build_opt.warn_list.clone(), |x| { + Some(x.clone() + &moonc_opt.build_opt.warn_list.clone().unwrap_or_default()) }); let alert_list = mod_desc .alert_list .as_ref() .map_or(pkg.alert_list.clone(), |x| { Some(x.clone() + &pkg.alert_list.unwrap_or_default()) + }) + .map_or(moonc_opt.build_opt.alert_list.clone(), |x| { + Some(x.clone() + &moonc_opt.build_opt.alert_list.clone().unwrap_or_default()) }); let artifact: PathBuf = target_dir.into(); diff --git a/docs/manual-zh/src/commands.md b/docs/manual-zh/src/commands.md index f37e1ead..459a270a 100644 --- a/docs/manual-zh/src/commands.md +++ b/docs/manual-zh/src/commands.md @@ -108,6 +108,8 @@ Build the current package * `--output-wat` — Output WAT instead of WASM * `-d`, `--deny-warn` — Treat all warnings as errors * `--no-render` — Don't render diagnostics from moonc (don't pass '-error-format json' to moonc) +* `--warn-list ` — Warn list config +* `--alert-list ` — Alert list config * `--frozen` — Do not sync dependencies, assuming local dependencies are up-to-date * `-w`, `--watch` — Monitor the file system and automatically build artifacts @@ -139,6 +141,8 @@ Check the current package, but don't build object files * `--output-wat` — Output WAT instead of WASM * `-d`, `--deny-warn` — Treat all warnings as errors * `--no-render` — Don't render diagnostics from moonc (don't pass '-error-format json' to moonc) +* `--warn-list ` — Warn list config +* `--alert-list ` — Alert list config * `--output-json` — Output in json format * `--frozen` — Do not sync dependencies, assuming local dependencies are up-to-date * `-w`, `--watch` — Monitor the file system and automatically check files @@ -174,6 +178,8 @@ Run a main package * `--output-wat` — Output WAT instead of WASM * `-d`, `--deny-warn` — Treat all warnings as errors * `--no-render` — Don't render diagnostics from moonc (don't pass '-error-format json' to moonc) +* `--warn-list ` — Warn list config +* `--alert-list ` — Alert list config * `--frozen` — Do not sync dependencies, assuming local dependencies are up-to-date * `--build-only` — Only build, do not run the code @@ -201,6 +207,8 @@ Test the current package * `--output-wat` — Output WAT instead of WASM * `-d`, `--deny-warn` — Treat all warnings as errors * `--no-render` — Don't render diagnostics from moonc (don't pass '-error-format json' to moonc) +* `--warn-list ` — Warn list config +* `--alert-list ` — Alert list config * `-p`, `--package ` — Run test in the specified package * `-f`, `--file ` — Run test in the specified file. Only valid when `--package` is also specified * `-i`, `--index ` — Run only the index-th test in the file. Only valid when `--file` is also specified diff --git a/docs/manual/src/commands.md b/docs/manual/src/commands.md index f37e1ead..459a270a 100644 --- a/docs/manual/src/commands.md +++ b/docs/manual/src/commands.md @@ -108,6 +108,8 @@ Build the current package * `--output-wat` — Output WAT instead of WASM * `-d`, `--deny-warn` — Treat all warnings as errors * `--no-render` — Don't render diagnostics from moonc (don't pass '-error-format json' to moonc) +* `--warn-list ` — Warn list config +* `--alert-list ` — Alert list config * `--frozen` — Do not sync dependencies, assuming local dependencies are up-to-date * `-w`, `--watch` — Monitor the file system and automatically build artifacts @@ -139,6 +141,8 @@ Check the current package, but don't build object files * `--output-wat` — Output WAT instead of WASM * `-d`, `--deny-warn` — Treat all warnings as errors * `--no-render` — Don't render diagnostics from moonc (don't pass '-error-format json' to moonc) +* `--warn-list ` — Warn list config +* `--alert-list ` — Alert list config * `--output-json` — Output in json format * `--frozen` — Do not sync dependencies, assuming local dependencies are up-to-date * `-w`, `--watch` — Monitor the file system and automatically check files @@ -174,6 +178,8 @@ Run a main package * `--output-wat` — Output WAT instead of WASM * `-d`, `--deny-warn` — Treat all warnings as errors * `--no-render` — Don't render diagnostics from moonc (don't pass '-error-format json' to moonc) +* `--warn-list ` — Warn list config +* `--alert-list ` — Alert list config * `--frozen` — Do not sync dependencies, assuming local dependencies are up-to-date * `--build-only` — Only build, do not run the code @@ -201,6 +207,8 @@ Test the current package * `--output-wat` — Output WAT instead of WASM * `-d`, `--deny-warn` — Treat all warnings as errors * `--no-render` — Don't render diagnostics from moonc (don't pass '-error-format json' to moonc) +* `--warn-list ` — Warn list config +* `--alert-list ` — Alert list config * `-p`, `--package ` — Run test in the specified package * `-f`, `--file ` — Run test in the specified file. Only valid when `--package` is also specified * `-i`, `--index ` — Run only the index-th test in the file. Only valid when `--file` is also specified From f6eaefeca14b273b504d45f9be5978e758ab936e Mon Sep 17 00:00:00 2001 From: Young-Flash Date: Wed, 27 Nov 2024 10:05:58 +0800 Subject: [PATCH 2/2] tweak cli args passing --- crates/moonbuild/src/build.rs | 9 +-------- crates/moonrun/src/main.rs | 1 + crates/moonrun/src/sys_api.rs | 11 ++--------- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/crates/moonbuild/src/build.rs b/crates/moonbuild/src/build.rs index 971e3e16..f2b6a3c1 100644 --- a/crates/moonbuild/src/build.rs +++ b/crates/moonbuild/src/build.rs @@ -56,14 +56,7 @@ fn run(command: &str, path: &Path, args: &[String], verbose: bool) -> anyhow::Re } let mut execution = Command::new(command) .arg(path) - .args(match command { - "moonrun" => { - let mut v = vec!["--".to_string()]; - v.extend(args.iter().cloned()); - v - } - _ => args.to_vec(), - }) + .args(args) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) .spawn() diff --git a/crates/moonrun/src/main.rs b/crates/moonrun/src/main.rs index 5d69680f..22556759 100644 --- a/crates/moonrun/src/main.rs +++ b/crates/moonrun/src/main.rs @@ -504,6 +504,7 @@ struct Commandline { path: Option, /// Additional arguments + #[clap(allow_hyphen_values = true)] args: Vec, /// Don't print stack trace diff --git a/crates/moonrun/src/sys_api.rs b/crates/moonrun/src/sys_api.rs index 4791f185..0ada646c 100644 --- a/crates/moonrun/src/sys_api.rs +++ b/crates/moonrun/src/sys_api.rs @@ -44,17 +44,10 @@ const INIT_SYS_API: &str = r#" "#; fn construct_args_list<'s>( - args: &[String], + _args: &[String], scope: &mut v8::HandleScope<'s>, ) -> v8::Local<'s, v8::Array> { - // align with node's behavior - // use this concat instead of std::env::args(), to ignore the possible -- - let cli_args: Vec = std::env::args() - // path of moonrun and the path of the wasm file - .take(2) - .chain(args.iter().cloned()) - .collect(); - + let cli_args: Vec = std::env::args().collect(); let arr = v8::Array::new(scope, cli_args.len() as i32); for (i, arg) in cli_args.iter().enumerate() { let arg = v8::String::new(scope, arg).unwrap();