Skip to content

Commit 74d2492

Browse files
authored
Verify if a package was compiled during the mismatch check. (#7912)
* Verify if a package was compiled during the mismatch check. * Add test to assert the log message is no longer there. * Add changelog entry
1 parent b43ed01 commit 74d2492

File tree

6 files changed

+81
-17
lines changed

6 files changed

+81
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#### :nail_care: Polish
2626

27+
- Keep track of compiler info during build. https://github.com/rescript-lang/rescript/pull/7889
28+
2729
#### :house: Internal
2830

2931
# 12.0.0-beta.12

rewatch/src/build.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,30 @@ pub fn initialize_build(
147147

148148
let compiler_check = verify_compiler_info(&packages, &compiler);
149149

150-
if !snapshot_output && show_progress {
151-
println!(
152-
"{}{} {}Built package tree in {:.2}s",
153-
LINE_CLEAR,
154-
style("[1/7]").bold().dim(),
155-
TREE,
156-
default_timing
157-
.unwrap_or(timing_package_tree_elapsed)
158-
.as_secs_f64()
159-
);
160-
if let CompilerCheckResult::CleanedPackagesDueToCompiler = compiler_check {
150+
if show_progress {
151+
if snapshot_output {
152+
if let CompilerCheckResult::CleanedPackagesDueToCompiler = compiler_check {
153+
// Snapshot-friendly output (no progress prefixes or emojis)
154+
println!("Cleaned previous build due to compiler update");
155+
}
156+
} else {
161157
println!(
162-
"{}{} {}Cleaned previous build due to compiler update",
158+
"{}{} {}Built package tree in {:.2}s",
163159
LINE_CLEAR,
164160
style("[1/7]").bold().dim(),
165-
SWEEP
161+
TREE,
162+
default_timing
163+
.unwrap_or(timing_package_tree_elapsed)
164+
.as_secs_f64()
166165
);
166+
if let CompilerCheckResult::CleanedPackagesDueToCompiler = compiler_check {
167+
println!(
168+
"{}{} {}Cleaned previous build due to compiler update",
169+
LINE_CLEAR,
170+
style("[1/7]").bold().dim(),
171+
SWEEP
172+
);
173+
}
167174
}
168175
}
169176

rewatch/src/build/compiler_info.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::helpers;
22

33
use super::build_types::{BuildState, CompilerInfo};
4-
use super::clean;
54
use super::packages;
5+
use super::{clean, logs};
66
use ahash::AHashMap;
77
use rayon::prelude::*;
88
use serde::{Deserialize, Serialize};
@@ -40,8 +40,9 @@ pub fn verify_compiler_info(
4040
.filter(|package| {
4141
let info_path = package.get_compiler_info_path();
4242
let Ok(contents) = std::fs::read_to_string(&info_path) else {
43-
// Can't read file → treat as mismatch so we clean and rewrite
44-
return true;
43+
// Can't read the compiler-info.json file, maybe there is no current build.
44+
// We check if the ocaml build folder exists, if not, we assume the compiler is not installed
45+
return logs::does_ocaml_build_compiler_log_exist(package);
4546
};
4647

4748
let parsed: Result<CompilerInfoFile, _> = serde_json::from_str(&contents);

rewatch/src/build/logs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ fn get_log_file_path(package: &packages::Package, subfolder: Location) -> PathBu
2424
build_folder.join(".compiler.log")
2525
}
2626

27+
pub fn does_ocaml_build_compiler_log_exist(package: &packages::Package) -> bool {
28+
get_log_file_path(package, Location::Ocaml).exists()
29+
}
30+
2731
fn escape_colours(str: &str) -> String {
2832
let re = Regex::new(r"[\u001b\u009b]\[[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]")
2933
.expect("Could not create regex");

rewatch/tests/clean.sh

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,42 @@ else
116116
error "Expected 0 files in node_modules/rescript-nodejs/lib/ocaml after clean, got $compiler_assets"
117117
printf "%s\n" "$error_output"
118118
exit 1
119-
fi
119+
fi
120+
121+
# If we clean a package, we should not see a "Cleaned previous build due to compiler update" message.
122+
# Clean the whole repo and rebuild, then ensure the compiler-update clean message is absent
123+
bold "Test: Clean repo then rebuild should not log compiler update clean"
124+
125+
# Clean repo
126+
error_output=$(rewatch clean 2>&1)
127+
if [ $? -eq 0 ];
128+
then
129+
success "Repo Cleaned"
130+
else
131+
error "Error Cleaning Repo"
132+
printf "%s\n" "$error_output" >&2
133+
exit 1
134+
fi
135+
136+
# Rebuild with snapshot output
137+
snapshot_file=../tests/snapshots/clean-rebuild.txt
138+
rewatch build --snapshot-output &> $snapshot_file
139+
build_status=$?
140+
normalize_paths $snapshot_file
141+
if [ $build_status -eq 0 ];
142+
then
143+
success "Repo Built"
144+
else
145+
error "Error Building Repo"
146+
cat $snapshot_file >&2
147+
exit 1
148+
fi
149+
150+
# Verify the undesired message is NOT present
151+
if grep -q "Cleaned previous build due to compiler update" $snapshot_file; then
152+
error "Unexpected compiler-update clean message present in rebuild logs"
153+
cat $snapshot_file >&2
154+
exit 1
155+
else
156+
success "No compiler-update clean message present after explicit clean"
157+
fi
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Cleaned 0/0
2+
Parsed 112 source files
3+
Compiled 112 modules
4+
5+
The field 'bs-dependencies' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version.
6+
Use 'dependencies' instead.
7+
8+
The field 'bs-dev-dependencies' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version.
9+
Use 'dev-dependencies' instead.
10+
11+
The field 'bsc-flags' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version.
12+
Use 'compiler-flags' instead.

0 commit comments

Comments
 (0)