diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b0c57b5a2..d5aae99b2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ #### :nail_care: Polish +- Keep track of compiler info during build. https://github.com/rescript-lang/rescript/pull/7889 + #### :house: Internal # 12.0.0-beta.12 diff --git a/rewatch/src/build.rs b/rewatch/src/build.rs index 43fcdcdf23..eaad489da0 100644 --- a/rewatch/src/build.rs +++ b/rewatch/src/build.rs @@ -147,23 +147,30 @@ pub fn initialize_build( let compiler_check = verify_compiler_info(&packages, &compiler); - if !snapshot_output && show_progress { - println!( - "{}{} {}Built package tree in {:.2}s", - LINE_CLEAR, - style("[1/7]").bold().dim(), - TREE, - default_timing - .unwrap_or(timing_package_tree_elapsed) - .as_secs_f64() - ); - if let CompilerCheckResult::CleanedPackagesDueToCompiler = compiler_check { + if show_progress { + if snapshot_output { + if let CompilerCheckResult::CleanedPackagesDueToCompiler = compiler_check { + // Snapshot-friendly output (no progress prefixes or emojis) + println!("Cleaned previous build due to compiler update"); + } + } else { println!( - "{}{} {}Cleaned previous build due to compiler update", + "{}{} {}Built package tree in {:.2}s", LINE_CLEAR, style("[1/7]").bold().dim(), - SWEEP + TREE, + default_timing + .unwrap_or(timing_package_tree_elapsed) + .as_secs_f64() ); + if let CompilerCheckResult::CleanedPackagesDueToCompiler = compiler_check { + println!( + "{}{} {}Cleaned previous build due to compiler update", + LINE_CLEAR, + style("[1/7]").bold().dim(), + SWEEP + ); + } } } diff --git a/rewatch/src/build/compiler_info.rs b/rewatch/src/build/compiler_info.rs index d3576d531d..f19145dbf0 100644 --- a/rewatch/src/build/compiler_info.rs +++ b/rewatch/src/build/compiler_info.rs @@ -1,8 +1,8 @@ use crate::helpers; use super::build_types::{BuildState, CompilerInfo}; -use super::clean; use super::packages; +use super::{clean, logs}; use ahash::AHashMap; use rayon::prelude::*; use serde::{Deserialize, Serialize}; @@ -40,8 +40,9 @@ pub fn verify_compiler_info( .filter(|package| { let info_path = package.get_compiler_info_path(); let Ok(contents) = std::fs::read_to_string(&info_path) else { - // Can't read file → treat as mismatch so we clean and rewrite - return true; + // Can't read the compiler-info.json file, maybe there is no current build. + // We check if the ocaml build folder exists, if not, we assume the compiler is not installed + return logs::does_ocaml_build_compiler_log_exist(package); }; let parsed: Result = serde_json::from_str(&contents); diff --git a/rewatch/src/build/logs.rs b/rewatch/src/build/logs.rs index 0f92896ac3..bb8aaf9d08 100644 --- a/rewatch/src/build/logs.rs +++ b/rewatch/src/build/logs.rs @@ -24,6 +24,10 @@ fn get_log_file_path(package: &packages::Package, subfolder: Location) -> PathBu build_folder.join(".compiler.log") } +pub fn does_ocaml_build_compiler_log_exist(package: &packages::Package) -> bool { + get_log_file_path(package, Location::Ocaml).exists() +} + fn escape_colours(str: &str) -> String { let re = Regex::new(r"[\u001b\u009b]\[[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]") .expect("Could not create regex"); diff --git a/rewatch/tests/clean.sh b/rewatch/tests/clean.sh index f04aa14387..3d67e46275 100755 --- a/rewatch/tests/clean.sh +++ b/rewatch/tests/clean.sh @@ -116,4 +116,42 @@ else error "Expected 0 files in node_modules/rescript-nodejs/lib/ocaml after clean, got $compiler_assets" printf "%s\n" "$error_output" exit 1 -fi \ No newline at end of file +fi + +# If we clean a package, we should not see a "Cleaned previous build due to compiler update" message. +# Clean the whole repo and rebuild, then ensure the compiler-update clean message is absent +bold "Test: Clean repo then rebuild should not log compiler update clean" + +# Clean repo +error_output=$(rewatch clean 2>&1) +if [ $? -eq 0 ]; +then + success "Repo Cleaned" +else + error "Error Cleaning Repo" + printf "%s\n" "$error_output" >&2 + exit 1 +fi + +# Rebuild with snapshot output +snapshot_file=../tests/snapshots/clean-rebuild.txt +rewatch build --snapshot-output &> $snapshot_file +build_status=$? +normalize_paths $snapshot_file +if [ $build_status -eq 0 ]; +then + success "Repo Built" +else + error "Error Building Repo" + cat $snapshot_file >&2 + exit 1 +fi + +# Verify the undesired message is NOT present +if grep -q "Cleaned previous build due to compiler update" $snapshot_file; then + error "Unexpected compiler-update clean message present in rebuild logs" + cat $snapshot_file >&2 + exit 1 +else + success "No compiler-update clean message present after explicit clean" +fi diff --git a/rewatch/tests/snapshots/clean-rebuild.txt b/rewatch/tests/snapshots/clean-rebuild.txt new file mode 100644 index 0000000000..0913f6ac45 --- /dev/null +++ b/rewatch/tests/snapshots/clean-rebuild.txt @@ -0,0 +1,12 @@ +Cleaned 0/0 +Parsed 112 source files +Compiled 112 modules + +The field 'bs-dependencies' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version. +Use 'dependencies' instead. + +The field 'bs-dev-dependencies' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version. +Use 'dev-dependencies' instead. + +The field 'bsc-flags' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version. +Use 'compiler-flags' instead.