Skip to content

Commit

Permalink
Merge pull request #301 from moonbitlang/add-raw-target-dir
Browse files Browse the repository at this point in the history
internal: add raw_target_dir in MoonbuildOpt
  • Loading branch information
lijunchen authored Sep 13, 2024
2 parents 53896c2 + 9a57730 commit 0dc4699
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 19 deletions.
11 changes: 8 additions & 3 deletions crates/moon/src/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn run_build_internal(
cli.quiet,
)?;

let original_target_dir = target_dir;
let raw_target_dir = target_dir;
let mut moonc_opt = super::get_compiler_flags(source_dir, &cmd.build_flags)?;
moonc_opt.build_opt.deny_warn = cmd.build_flags.deny_warn;
let run_mode = RunMode::Build;
Expand All @@ -125,13 +125,18 @@ fn run_build_internal(

let moonbuild_opt = MoonbuildOpt {
source_dir: source_dir.to_path_buf(),
raw_target_dir: raw_target_dir.to_path_buf(),
target_dir,
sort_input,
run_mode,
quiet: cli.quiet,
verbose: cli.verbose,
build_graph: cli.build_graph,
..Default::default()
test_opt: None,
fmt_opt: None,
args: vec![],
output_json: false,
no_parallelize: false,
};

let module = moonutil::scan::scan(
Expand Down Expand Up @@ -168,7 +173,7 @@ fn run_build_internal(
&moonbuild_opt,
&reg_cfg,
&module,
original_target_dir,
raw_target_dir,
)
} else {
entry::run_build(&moonc_opt, &moonbuild_opt, &module)
Expand Down
11 changes: 10 additions & 1 deletion crates/moon/src/cli/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,24 @@ fn run_bundle_internal(
let run_mode = RunMode::Bundle;
let sort_input = cmd.build_flags.sort_input;

let raw_target_dir = target_dir.to_path_buf();
let target_dir = mk_arch_mode_dir(source_dir, target_dir, &moonc_opt, run_mode)?;
let _lock = FileLock::lock(&target_dir)?;

let moonbuild_opt = MoonbuildOpt {
source_dir: source_dir.to_path_buf(),
raw_target_dir,
target_dir,
sort_input,
run_mode,
..Default::default()
test_opt: None,
fmt_opt: None,
args: vec![],
verbose: cli.verbose,
quiet: cli.quiet,
output_json: false,
no_parallelize: false,
build_graph: false,
};
let module = moonutil::scan::scan(
false,
Expand Down
10 changes: 7 additions & 3 deletions crates/moon/src/cli/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn run_check_internal(
cli.quiet,
)?;

let original_target_dir = target_dir;
let raw_target_dir = target_dir;
let mut moonc_opt = get_compiler_flags(source_dir, &cmd.build_flags)?;
moonc_opt.build_opt.deny_warn = cmd.build_flags.deny_warn;
let run_mode = RunMode::Check;
Expand All @@ -143,14 +143,18 @@ fn run_check_internal(

let moonbuild_opt = MoonbuildOpt {
source_dir: source_dir.to_path_buf(),
raw_target_dir: raw_target_dir.to_path_buf(),
target_dir: target_dir.clone(),
sort_input,
run_mode,
quiet: cli.quiet,
verbose: cli.verbose,
output_json: cmd.output_json,
build_graph: cli.build_graph,
..Default::default()
test_opt: None,
fmt_opt: None,
args: vec![],
no_parallelize: false,
};

let module = moonutil::scan::scan(
Expand Down Expand Up @@ -187,7 +191,7 @@ fn run_check_internal(
&moonbuild_opt,
&reg_cfg,
&module,
original_target_dir,
raw_target_dir,
)
} else {
let pid_path = target_dir.join(MOON_PID_NAME);
Expand Down
11 changes: 10 additions & 1 deletion crates/moon/src/cli/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,22 @@ pub fn run_doc(cli: UniversalFlags, cmd: DocSubcommand) -> anyhow::Result<i32> {
)?;

let run_mode = RunMode::Check;
let raw_target_dir = target_dir.to_path_buf();
let target_dir = mk_arch_mode_dir(&source_dir, &target_dir, &moonc_opt, run_mode)?;
let moonbuild_opt = MoonbuildOpt {
source_dir: source_dir.clone(),
raw_target_dir,
target_dir,
sort_input: true,
run_mode,
..Default::default()
test_opt: None,
fmt_opt: None,
args: vec![],
verbose: cli.verbose,
quiet: cli.quiet,
output_json: false,
no_parallelize: false,
build_graph: false,
};

let module = moonutil::scan::scan(
Expand Down
9 changes: 8 additions & 1 deletion crates/moon/src/cli/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub fn run_fmt(cli: &UniversalFlags, cmd: FmtSubcommand) -> anyhow::Result<i32>

let moonc_opt = MooncOpt::default();
let run_mode = RunMode::Format;
let raw_target_dir = target_dir.to_path_buf();
let target_dir = mk_arch_mode_dir(&source_dir, &target_dir, &moonc_opt, run_mode)?;
let _lock = FileLock::lock(&target_dir)?;

Expand All @@ -59,12 +60,18 @@ pub fn run_fmt(cli: &UniversalFlags, cmd: FmtSubcommand) -> anyhow::Result<i32>

let moonbuild_opt = MoonbuildOpt {
source_dir,
raw_target_dir,
target_dir: target_dir.clone(),
sort_input: cmd.sort_input,
run_mode,
fmt_opt: Some(FmtOpt { check: cmd.check }),
build_graph: cli.build_graph,
..Default::default()
test_opt: None,
args: vec![],
verbose: cli.verbose,
quiet: cli.quiet,
output_json: false,
no_parallelize: false,
};

let module = moonutil::scan::scan(
Expand Down
9 changes: 8 additions & 1 deletion crates/moon/src/cli/generate_test_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ pub fn generate_test_driver(
&RegistryConfig::load(),
cli.quiet,
)?;
let raw_target_dir = target_dir.to_path_buf();

let moonbuild_opt = MoonbuildOpt {
source_dir,
raw_target_dir,
target_dir: target_dir.clone(),
test_opt: Some(TestOpt {
filter_package: filter_package.clone(),
Expand All @@ -145,7 +147,12 @@ pub fn generate_test_driver(
fmt_opt: None,
sort_input,
run_mode,
..Default::default()
args: vec![],
verbose: cli.verbose,
quiet: cli.quiet,
output_json: false,
no_parallelize: false,
build_graph: false,
};

let module = moonutil::scan::scan(
Expand Down
17 changes: 11 additions & 6 deletions crates/moon/src/cli/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub fn run_info(cli: UniversalFlags, cmd: InfoSubcommand) -> anyhow::Result<i32>
})?;
let module_name = &mod_desc.name;
let mut moonc_opt = MooncOpt::default();
let raw_target_dir = target_dir.to_path_buf();
let target_dir = mk_arch_mode_dir(
source_dir.as_path(),
target_dir.as_path(),
Expand All @@ -82,10 +83,18 @@ pub fn run_info(cli: UniversalFlags, cmd: InfoSubcommand) -> anyhow::Result<i32>
}
let moonbuild_opt = MoonbuildOpt {
source_dir: source_dir.clone(),
raw_target_dir,
target_dir: target_dir.clone(),
sort_input: false,
run_mode: RunMode::Check,
..Default::default()
test_opt: None,
fmt_opt: None,
args: vec![],
verbose: cli.verbose,
quiet: cli.quiet,
output_json: false,
no_parallelize: false,
build_graph: false,
};

let module = moonutil::scan::scan(
Expand All @@ -107,11 +116,7 @@ pub fn run_info(cli: UniversalFlags, cmd: InfoSubcommand) -> anyhow::Result<i32>
&resolved_env,
&dir_sync_result,
&moonc_opt,
&MoonbuildOpt {
source_dir: source_dir.clone(),
target_dir,
..Default::default()
},
&moonbuild_opt,
)?;

let runtime = tokio::runtime::Runtime::new()?;
Expand Down
7 changes: 6 additions & 1 deletion crates/moon/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ pub fn run_run_internal(cli: &UniversalFlags, cmd: RunSubcommand) -> anyhow::Res

let mut moonc_opt = super::get_compiler_flags(&source_dir, &cmd.build_flags)?;
let run_mode = RunMode::Run;
let raw_target_dir = target_dir.to_path_buf();
let target_dir = mk_arch_mode_dir(&source_dir, &target_dir, &moonc_opt, run_mode)?;
let _lock = FileLock::lock(&target_dir)?;

Expand Down Expand Up @@ -260,14 +261,18 @@ pub fn run_run_internal(cli: &UniversalFlags, cmd: RunSubcommand) -> anyhow::Res
}
let moonbuild_opt = MoonbuildOpt {
source_dir,
raw_target_dir,
target_dir,
sort_input,
run_mode,
args: cmd.args.clone(),
quiet: true,
verbose: cli.verbose,
build_graph: cli.build_graph,
..Default::default()
test_opt: None,
fmt_opt: None,
output_json: false,
no_parallelize: false,
};

let module = moonutil::scan::scan(
Expand Down
6 changes: 5 additions & 1 deletion crates/moon/src/cli/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ fn run_test_internal(
moonc_opt.link_opt.debug_flag = !cmd.release;

let run_mode = RunMode::Test;
let raw_target_dir = target_dir.to_path_buf();
let target_dir = mk_arch_mode_dir(source_dir, target_dir, &moonc_opt, run_mode)?;
let _lock = FileLock::lock(&target_dir)?;

Expand All @@ -180,6 +181,7 @@ fn run_test_internal(
let filter_index = cmd.index;
let moonbuild_opt = MoonbuildOpt {
source_dir: source_dir.to_path_buf(),
raw_target_dir,
target_dir: target_dir.clone(),
test_opt: Some(TestOpt {
filter_package: filter_package.clone(),
Expand All @@ -195,7 +197,9 @@ fn run_test_internal(
verbose: cli.verbose,
no_parallelize: cmd.no_parallelize,
build_graph: cli.build_graph,
..Default::default()
fmt_opt: None,
args: vec![],
output_json: false,
};

let mut module = moonutil::scan::scan(
Expand Down
3 changes: 2 additions & 1 deletion crates/moonutil/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,10 @@ impl LinkCoreFlags {
}
}

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone)]
pub struct MoonbuildOpt {
pub source_dir: PathBuf,
pub raw_target_dir: PathBuf,
pub target_dir: PathBuf,
pub test_opt: Option<TestOpt>,
pub sort_input: bool,
Expand Down

0 comments on commit 0dc4699

Please sign in to comment.