Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 20 additions & 13 deletions rewatch/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions rewatch/src/build/compiler_info.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<CompilerInfoFile, _> = serde_json::from_str(&contents);
Expand Down
4 changes: 4 additions & 0 deletions rewatch/src/build/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
40 changes: 39 additions & 1 deletion rewatch/tests/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
12 changes: 12 additions & 0 deletions rewatch/tests/snapshots/clean-rebuild.txt
Original file line number Diff line number Diff line change
@@ -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.
Loading