From ba87d4ae3ec586dd650ad227d2d7273465d29bc6 Mon Sep 17 00:00:00 2001 From: Young-Flash Date: Wed, 25 Dec 2024 15:11:56 +0800 Subject: [PATCH] internal: support --enable-value-tracing for build-package --- crates/moon/src/cli.rs | 5 ++++ crates/moon/src/cli/run.rs | 38 ++++++++++++++++----------- crates/moonbuild/src/gen/gen_build.rs | 3 +++ crates/moonutil/src/common.rs | 2 ++ crates/moonutil/src/package.rs | 2 ++ crates/moonutil/src/scan.rs | 1 + 6 files changed, 35 insertions(+), 16 deletions(-) diff --git a/crates/moon/src/cli.rs b/crates/moon/src/cli.rs index 6eb52e4a..ba17ab79 100644 --- a/crates/moon/src/cli.rs +++ b/crates/moon/src/cli.rs @@ -198,6 +198,10 @@ pub struct BuildFlags { /// Alert list config #[clap(long, allow_hyphen_values = true)] pub alert_list: Option, + + /// Enable value tracing + #[clap(long, hide = true)] + pub enable_value_tracing: bool, } impl BuildFlags { @@ -262,6 +266,7 @@ pub fn get_compiler_flags(src_dir: &Path, build_flags: &BuildFlags) -> anyhow::R target_backend, warn_list: build_flags.warn_list.clone(), alert_list: build_flags.alert_list.clone(), + enable_value_tracing: build_flags.enable_value_tracing, }; let link_opt = LinkCoreFlags { diff --git a/crates/moon/src/cli/run.rs b/crates/moon/src/cli/run.rs index 397f4e03..d166f22c 100644 --- a/crates/moon/src/cli/run.rs +++ b/crates/moon/src/cli/run.rs @@ -110,22 +110,25 @@ fn run_single_mbt_file(cli: &UniversalFlags, cmd: RunSubcommand) -> anyhow::Resu output_artifact_path.join(format!("{}.{}", file_name, target_backend.to_extension())); let pkg_name = "moon/run/single"; - let build_package_command = [ - "build-package", - &mbt_file_path.display().to_string(), - "-o", - output_core_path, - "-std-path", - core_bundle_path.to_str().unwrap(), - "-is-main", - "-pkg", - pkg_name, - "-g", - "-O0", - "-source-map", - "-target", - target_backend.to_flag(), + let mut build_package_command = vec![ + "build-package".to_string(), + mbt_file_path.display().to_string(), + "-o".to_string(), + output_core_path.to_string(), + "-std-path".to_string(), + core_bundle_path.to_str().unwrap().to_string(), + "-is-main".to_string(), + "-pkg".to_string(), + pkg_name.to_string(), + "-g".to_string(), + "-O0".to_string(), + "-source-map".to_string(), + "-target".to_string(), + target_backend.to_flag().to_string(), ]; + if cmd.build_flags.enable_value_tracing { + build_package_command.push("-enable-value-tracing".to_string()); + } let link_core_command = [ "link-core", &moonutil::moon_dir::core_core(target_backend) @@ -167,7 +170,7 @@ fn run_single_mbt_file(cli: &UniversalFlags, cmd: RunSubcommand) -> anyhow::Resu } let moonc_build_package = std::process::Command::new("moonc") - .args(build_package_command) + .args(&build_package_command) .stdout(std::process::Stdio::inherit()) .stderr(std::process::Stdio::inherit()) .spawn()? @@ -295,6 +298,9 @@ pub fn run_run_internal(cli: &UniversalFlags, cmd: RunSubcommand) -> anyhow::Res &dir_sync_result, )?; + let pkg = module.get_package_by_path_mut(&package).unwrap(); + pkg.enable_value_tracing = cmd.build_flags.enable_value_tracing; + moonutil::common::set_native_backend_link_flags( run_mode, cmd.build_flags.release, diff --git a/crates/moonbuild/src/gen/gen_build.rs b/crates/moonbuild/src/gen/gen_build.rs index 3c57fb5f..4a263ce0 100644 --- a/crates/moonbuild/src/gen/gen_build.rs +++ b/crates/moonbuild/src/gen/gen_build.rs @@ -45,6 +45,7 @@ pub struct BuildDepItem { pub alert_list: Option, pub is_main: bool, pub is_third_party: bool, + pub enable_value_tracing: bool, } type BuildLinkDepItem = moonutil::package::LinkDepItem; @@ -118,6 +119,7 @@ pub fn gen_build_build_item( alert_list: pkg.alert_list.clone(), is_main: pkg.is_main, is_third_party: pkg.is_third_party, + enable_value_tracing: pkg.enable_value_tracing, }) } @@ -246,6 +248,7 @@ pub fn gen_build_command( let command = CommandBuilder::new("moonc") .arg("build-package") + .arg_with_cond(item.enable_value_tracing, "-enable-value-tracing") .args_with_cond(moonc_opt.render, vec!["-error-format", "json"]) .args_with_cond( moonc_opt.build_opt.deny_warn, diff --git a/crates/moonutil/src/common.rs b/crates/moonutil/src/common.rs index 1925f561..d87f1664 100644 --- a/crates/moonutil/src/common.rs +++ b/crates/moonutil/src/common.rs @@ -316,6 +316,7 @@ pub struct BuildPackageFlags { pub target_backend: TargetBackend, pub warn_list: Option, pub alert_list: Option, + pub enable_value_tracing: bool, } impl BuildPackageFlags { @@ -329,6 +330,7 @@ impl BuildPackageFlags { target_backend: TargetBackend::default(), warn_list: None, alert_list: None, + enable_value_tracing: false, } } } diff --git a/crates/moonutil/src/package.rs b/crates/moonutil/src/package.rs index f9ff4351..00963f76 100644 --- a/crates/moonutil/src/package.rs +++ b/crates/moonutil/src/package.rs @@ -79,6 +79,8 @@ pub struct Package { pub bin_name: Option, pub bin_target: TargetBackend, + + pub enable_value_tracing: bool, } impl Package { diff --git a/crates/moonutil/src/scan.rs b/crates/moonutil/src/scan.rs index b0cca6c8..9c0fbcc5 100644 --- a/crates/moonutil/src/scan.rs +++ b/crates/moonutil/src/scan.rs @@ -371,6 +371,7 @@ fn scan_one_package( .filter(|_| pkg.is_main && !is_third_party), bin_name: pkg.bin_name, bin_target: pkg.bin_target, + enable_value_tracing: false, }; if doc_mode { // -o