Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: moon check single package(and it's deps) #416

Merged
merged 5 commits into from
Oct 28, 2024
Merged
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
1 change: 1 addition & 0 deletions crates/moon/src/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ fn run_build_internal(
verbose: cli.verbose,
build_graph: cli.build_graph,
test_opt: None,
check_opt: None,
fmt_opt: None,
args: vec![],
output_json: false,
Expand Down
1 change: 1 addition & 0 deletions crates/moon/src/cli/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ fn run_bundle_internal(
sort_input,
run_mode,
test_opt: None,
check_opt: None,
fmt_opt: None,
args: vec![],
verbose: cli.verbose,
Expand Down
36 changes: 33 additions & 3 deletions crates/moon/src/cli/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ use moonbuild::watcher_is_running;
use moonbuild::{entry, MOON_PID_NAME};
use mooncake::pkg::sync::auto_sync;
use moonutil::cli::UniversalFlags;
use moonutil::common::lower_surface_targets;
use moonutil::common::FileLock;
use moonutil::common::MoonbuildOpt;
use moonutil::common::RunMode;
use moonutil::common::WATCH_MODE_DIR;
use moonutil::common::{lower_surface_targets, CheckOpt};
use moonutil::dirs::mk_arch_mode_dir;
use moonutil::dirs::PackageDirs;
use moonutil::mooncakes::sync::AutoSyncFlags;
use moonutil::mooncakes::RegistryConfig;
use n2::trace;
use std::path::Path;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::thread;

Expand All @@ -56,6 +56,17 @@ pub struct CheckSubcommand {
/// Monitor the file system and automatically check files
#[clap(long, short)]
pub watch: bool,

/// The package(and it's deps) to check
pub package_path: Option<PathBuf>,
Young-Flash marked this conversation as resolved.
Show resolved Hide resolved

/// The patch file to check, Only valid when checking specified package.
#[clap(long, requires = "package_path")]
pub patch_file: Option<PathBuf>,

/// Whether to skip the mi generation, Only valid when checking specified package.
#[clap(long, requires = "package_path")]
pub no_mi: bool,
}

pub fn run_check(cli: &UniversalFlags, cmd: &CheckSubcommand) -> anyhow::Result<i32> {
Expand Down Expand Up @@ -152,19 +163,38 @@ fn run_check_internal(
verbose: cli.verbose,
output_json: cmd.output_json,
build_graph: cli.build_graph,
check_opt: Some(CheckOpt {
package_path: cmd.package_path.clone(),
patch_file: cmd.patch_file.clone(),
no_mi: cmd.no_mi,
}),
test_opt: None,
fmt_opt: None,
args: vec![],
no_parallelize: false,
};

let module = scan_with_pre_build(
let mut module = scan_with_pre_build(
false,
&moonc_opt,
&moonbuild_opt,
&resolved_env,
&dir_sync_result,
)?;

if let Some(CheckOpt {
package_path: Some(pkg_path),
patch_file: pp,
no_mi: nm,
}) = moonbuild_opt.check_opt.as_ref()
{
let pkg_by_path = module.get_package_by_path_mut(&moonbuild_opt.source_dir.join(pkg_path));
if let Some(specified_pkg) = pkg_by_path {
specified_pkg.no_mi = *nm;
specified_pkg.patch_file = pp.clone();
}
};

moonc_opt.build_opt.warn_lists = module
.get_all_packages()
.iter()
Expand Down
1 change: 1 addition & 0 deletions crates/moon/src/cli/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pub fn run_doc(cli: UniversalFlags, cmd: DocSubcommand) -> anyhow::Result<i32> {
sort_input: true,
run_mode,
test_opt: None,
check_opt: None,
fmt_opt: None,
args: vec![],
verbose: cli.verbose,
Expand Down
1 change: 1 addition & 0 deletions crates/moon/src/cli/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub fn run_fmt(cli: &UniversalFlags, cmd: FmtSubcommand) -> anyhow::Result<i32>
}),
build_graph: cli.build_graph,
test_opt: None,
check_opt: None,
args: vec![],
verbose: cli.verbose,
quiet: cli.quiet,
Expand Down
1 change: 1 addition & 0 deletions crates/moon/src/cli/generate_test_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ pub fn generate_test_driver(
test_failure_json: false,
display_backend_hint: None,
}),
check_opt: None,
fmt_opt: None,
sort_input,
run_mode,
Expand Down
1 change: 1 addition & 0 deletions crates/moon/src/cli/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub fn run_info(cli: UniversalFlags, cmd: InfoSubcommand) -> anyhow::Result<i32>
sort_input: false,
run_mode: RunMode::Check,
test_opt: None,
check_opt: None,
fmt_opt: None,
args: vec![],
verbose: cli.verbose,
Expand Down
1 change: 1 addition & 0 deletions crates/moon/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ pub fn run_run_internal(cli: &UniversalFlags, cmd: RunSubcommand) -> anyhow::Res
verbose: cli.verbose,
build_graph: cli.build_graph,
test_opt: None,
check_opt: None,
fmt_opt: None,
output_json: false,
no_parallelize: false,
Expand Down
1 change: 1 addition & 0 deletions crates/moon/src/cli/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ fn run_test_internal(
test_failure_json: cmd.test_failure_json,
display_backend_hint,
}),
check_opt: None,
sort_input,
run_mode,
quiet: true,
Expand Down
151 changes: 150 additions & 1 deletion crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4687,7 +4687,7 @@ fn debug_flag_test() {
expect![[r#"
error: the argument '--release' cannot be used with '--debug'

Usage: moon check --release
Usage: moon check --release [PACKAGE_PATH]

For more information, try '--help'.
"#]],
Expand Down Expand Up @@ -7415,3 +7415,152 @@ fn test_native_backend_cc_flags() {
"#]],
);
}

#[test]
fn test_moon_check_filter_package() {
let dir = TestDir::new("test_check_filter.in");

check(
get_stdout(&dir, ["check", "A", "--dry-run", "--sort-input"]),
expect![[r#"
moonc check ./A/hello.mbt ./A/test.mbt -o ./target/wasm-gc/release/check/A/A.mi -pkg username/hello/A -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/A:./A -target wasm-gc
moonc check ./A/hello_test.mbt -o ./target/wasm-gc/release/check/A/A.blackbox_test.mi -pkg username/hello/A_blackbox_test -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/A/A.mi:A -pkg-sources username/hello/A_blackbox_test:./A -target wasm-gc -blackbox-test
moonc check ./A/hello.mbt ./A/test.mbt ./A/hello_wbtest.mbt -o ./target/wasm-gc/release/check/A/A.whitebox_test.mi -pkg username/hello/A -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/A:./A -target wasm-gc -whitebox-test
"#]],
);

check(
get_stdout(&dir, ["check", "main", "--dry-run", "--sort-input"]),
expect![[r#"
moonc check ./lib2/lib.mbt -o ./target/wasm-gc/release/check/lib2/lib2.mi -pkg username/hello/lib2 -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib2:./lib2 -target wasm-gc
moonc check ./lib/hello.mbt -o ./target/wasm-gc/release/check/lib/lib.mi -pkg username/hello/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/lib2/lib2.mi:lib2 -pkg-sources username/hello/lib:./lib -target wasm-gc
moonc check ./main/main.mbt -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 -pkg-sources username/hello/main:./main -target wasm-gc
"#]],
);

check(
get_stdout(&dir, ["check", "lib", "--dry-run", "--sort-input"]),
expect![[r#"
moonc check ./lib2/lib.mbt -o ./target/wasm-gc/release/check/lib2/lib2.mi -pkg username/hello/lib2 -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib2:./lib2 -target wasm-gc
moonc check ./lib/hello.mbt -o ./target/wasm-gc/release/check/lib/lib.mi -pkg username/hello/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/lib2/lib2.mi:lib2 -pkg-sources username/hello/lib:./lib -target wasm-gc
"#]],
);
}

#[test]
fn test_moon_check_package_with_patch() {
let dir = TestDir::new("test_check_filter.in");

// A has no deps
check(
get_stdout(
&dir,
[
"check",
"A",
"--patch-file",
"/path/to/patch.json",
"--dry-run",
"--sort-input",
],
),
expect![[r#"
moonc check -patch-file /path/to/patch.json ./A/hello.mbt ./A/test.mbt -o ./target/wasm-gc/release/check/A/A.mi -pkg username/hello/A -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/A:./A -target wasm-gc
moonc check ./A/hello_test.mbt -o ./target/wasm-gc/release/check/A/A.blackbox_test.mi -pkg username/hello/A_blackbox_test -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/A/A.mi:A -pkg-sources username/hello/A_blackbox_test:./A -target wasm-gc -blackbox-test
moonc check ./A/hello.mbt ./A/test.mbt ./A/hello_wbtest.mbt -o ./target/wasm-gc/release/check/A/A.whitebox_test.mi -pkg username/hello/A -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/A:./A -target wasm-gc -whitebox-test
"#]],
);
check(
get_stdout(
&dir,
[
"check",
"A",
"--patch-file",
"/path/to/patch_wbtest.json",
"--dry-run",
"--sort-input",
],
),
expect![[r#"
moonc check ./A/hello.mbt ./A/test.mbt -o ./target/wasm-gc/release/check/A/A.mi -pkg username/hello/A -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/A:./A -target wasm-gc
moonc check ./A/hello_test.mbt -o ./target/wasm-gc/release/check/A/A.blackbox_test.mi -pkg username/hello/A_blackbox_test -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/A/A.mi:A -pkg-sources username/hello/A_blackbox_test:./A -target wasm-gc -blackbox-test
moonc check -patch-file /path/to/patch_wbtest.json ./A/hello.mbt ./A/test.mbt ./A/hello_wbtest.mbt -o ./target/wasm-gc/release/check/A/A.whitebox_test.mi -pkg username/hello/A -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/A:./A -target wasm-gc -whitebox-test
"#]],
);
check(
get_stdout(
&dir,
[
"check",
"A",
"--patch-file",
"/path/to/patch_test.json",
"--dry-run",
"--sort-input",
],
),
expect![[r#"
moonc check ./A/hello.mbt ./A/test.mbt -o ./target/wasm-gc/release/check/A/A.mi -pkg username/hello/A -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/A:./A -target wasm-gc
moonc check -patch-file /path/to/patch_test.json ./A/hello_test.mbt -o ./target/wasm-gc/release/check/A/A.blackbox_test.mi -pkg username/hello/A_blackbox_test -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/A/A.mi:A -pkg-sources username/hello/A_blackbox_test:./A -target wasm-gc -blackbox-test
moonc check ./A/hello.mbt ./A/test.mbt ./A/hello_wbtest.mbt -o ./target/wasm-gc/release/check/A/A.whitebox_test.mi -pkg username/hello/A -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/A:./A -target wasm-gc -whitebox-test
"#]],
);

// lib has dep lib2
check(
get_stdout(
&dir,
[
"check",
"lib",
"--patch-file",
"/path/to/patch.json",
"--dry-run",
"--sort-input",
],
),
expect![[r#"
moonc check ./lib2/lib.mbt -o ./target/wasm-gc/release/check/lib2/lib2.mi -pkg username/hello/lib2 -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib2:./lib2 -target wasm-gc
moonc check -patch-file /path/to/patch.json ./lib/hello.mbt -o ./target/wasm-gc/release/check/lib/lib.mi -pkg username/hello/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/lib2/lib2.mi:lib2 -pkg-sources username/hello/lib:./lib -target wasm-gc
"#]],
);
check(
get_stdout(
&dir,
[
"check",
"lib",
"--patch-file",
"/path/to/patch_test.json",
"--dry-run",
"--sort-input",
],
),
expect![[r#"
moonc check ./lib2/lib.mbt -o ./target/wasm-gc/release/check/lib2/lib2.mi -pkg username/hello/lib2 -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib2:./lib2 -target wasm-gc
moonc check ./lib/hello.mbt -o ./target/wasm-gc/release/check/lib/lib.mi -pkg username/hello/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/lib2/lib2.mi:lib2 -pkg-sources username/hello/lib:./lib -target wasm-gc
"#]],
);

// main has dep lib
check(
get_stdout(
&dir,
[
"check",
"main",
"--patch-file",
"/path/to/patch.json",
"--no-mi",
"--dry-run",
"--sort-input",
],
),
expect![[r#"
moonc check ./lib2/lib.mbt -o ./target/wasm-gc/release/check/lib2/lib2.mi -pkg username/hello/lib2 -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -pkg-sources username/hello/lib2:./lib2 -target wasm-gc
moonc check ./lib/hello.mbt -o ./target/wasm-gc/release/check/lib/lib.mi -pkg username/hello/lib -std-path $MOON_HOME/lib/core/target/wasm-gc/release/bundle -i ./target/wasm-gc/release/check/lib2/lib2.mi:lib2 -pkg-sources username/hello/lib:./lib -target wasm-gc
moonc check -patch-file /path/to/patch.json -no-mi ./main/main.mbt -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 -pkg-sources username/hello/main:./main -target wasm-gc
"#]],
);
}
11 changes: 11 additions & 0 deletions crates/moon/tests/test_cases/test_check_filter.in/A/hello.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub fn hello() -> String {
"Hello, world!"
}

test "A" {
println("test A")
}

test "B" {
println("test B")
}
11 changes: 11 additions & 0 deletions crates/moon/tests/test_cases/test_check_filter.in/A/hello_test.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test "hello_0" {
println("test hello_0")
}

test "hello_1" {
println("test hello_1")
}

test "hello_2" {
println("test hello_2")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test "hello_0" {
println("test hello_0")
}

test "hello_1" {
println("test hello_1")
}

test "hello_2" {
println("test hello_2")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
7 changes: 7 additions & 0 deletions crates/moon/tests/test_cases/test_check_filter.in/A/test.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test "C" {
println("test C")
}

test "D" {
println("test D")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub fn hello() -> String {
"Hello, world!"
}

test "A" {
println("test A")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"import": [
"username/hello/lib2"
]
}
14 changes: 14 additions & 0 deletions crates/moon/tests/test_cases/test_check_filter.in/lib2/lib.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
test {
println(2)
}

test {
inspect!(1)
inspect!(1 + 2)
inspect!("hello")
inspect!([1, 2, 3])
}

test {
inspect!(2)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main {
println(@lib.hello())
}
Loading
Loading