Skip to content

Commit

Permalink
Merge pull request #495 from moonbitlang/warn_list_in_cli
Browse files Browse the repository at this point in the history
feat: allow config warn list by passing cli args
  • Loading branch information
Young-Flash authored Nov 27, 2024
2 parents 5a3b8a3 + f6eaefe commit fd61ae8
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 17 deletions.
10 changes: 10 additions & 0 deletions crates/moon/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// Alert list config
#[clap(long, allow_hyphen_values = true)]
pub alert_list: Option<String>,
}

impl BuildFlags {
Expand Down Expand Up @@ -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 {
Expand Down
38 changes: 38 additions & 0 deletions crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
Expand Down Expand Up @@ -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]
Expand Down
9 changes: 1 addition & 8 deletions crates/moonbuild/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions crates/moonrun/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ struct Commandline {
path: Option<PathBuf>,

/// Additional arguments
#[clap(allow_hyphen_values = true)]
args: Vec<String>,

/// Don't print stack trace
Expand Down
11 changes: 2 additions & 9 deletions crates/moonrun/src/sys_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = std::env::args()
// path of moonrun and the path of the wasm file
.take(2)
.chain(args.iter().cloned())
.collect();

let cli_args: Vec<String> = 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();
Expand Down
4 changes: 4 additions & 0 deletions crates/moonutil/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ pub struct BuildPackageFlags {
// treat all warnings as errors
pub deny_warn: bool,
pub target_backend: TargetBackend,
pub warn_list: Option<String>,
pub alert_list: Option<String>,
}

impl BuildPackageFlags {
Expand All @@ -304,6 +306,8 @@ impl BuildPackageFlags {
enable_coverage: false,
deny_warn: false,
target_backend: TargetBackend::default(),
warn_list: None,
alert_list: None,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/moonutil/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub struct Package {
pub artifact: PathBuf,

pub link: Option<Link>,

// moon.mod.json + moon.pkg.json + cli passing value
pub warn_list: Option<String>,
pub alert_list: Option<String>,

Expand Down
6 changes: 6 additions & 0 deletions crates/moonutil/src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions docs/manual-zh/src/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>` — Warn list config
* `--alert-list <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

Expand Down Expand Up @@ -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>` — Warn list config
* `--alert-list <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
Expand Down Expand Up @@ -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>` — Warn list config
* `--alert-list <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

Expand Down Expand Up @@ -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>` — Warn list config
* `--alert-list <ALERT_LIST>` — Alert list config
* `-p`, `--package <PACKAGE>` — Run test in the specified package
* `-f`, `--file <FILE>` — Run test in the specified file. Only valid when `--package` is also specified
* `-i`, `--index <INDEX>` — Run only the index-th test in the file. Only valid when `--file` is also specified
Expand Down
8 changes: 8 additions & 0 deletions docs/manual/src/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>` — Warn list config
* `--alert-list <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

Expand Down Expand Up @@ -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>` — Warn list config
* `--alert-list <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
Expand Down Expand Up @@ -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>` — Warn list config
* `--alert-list <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

Expand Down Expand Up @@ -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>` — Warn list config
* `--alert-list <ALERT_LIST>` — Alert list config
* `-p`, `--package <PACKAGE>` — Run test in the specified package
* `-f`, `--file <FILE>` — Run test in the specified file. Only valid when `--package` is also specified
* `-i`, `--index <INDEX>` — Run only the index-th test in the file. Only valid when `--file` is also specified
Expand Down

0 comments on commit fd61ae8

Please sign in to comment.