From cd7618b017e76d4a24a0aa16fe49fd7036553ace Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 9 Jul 2025 17:38:39 +0200 Subject: [PATCH] Don't panic when dev files are not found during clean. --- rewatch/src/build.rs | 12 +++++++---- rewatch/src/build/clean.rs | 3 ++- rewatch/src/build/packages.rs | 40 +++++++++++++++++++---------------- rewatch/src/lock.rs | 5 ++++- rewatch/src/watcher.rs | 2 +- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/rewatch/src/build.rs b/rewatch/src/build.rs index dc844a8092..1f073a4330 100644 --- a/rewatch/src/build.rs +++ b/rewatch/src/build.rs @@ -8,7 +8,10 @@ pub mod packages; pub mod parse; pub mod read_compile_state; +use self::compile::compiler_args; +use self::parse::parser_args; use crate::build::compile::{mark_modules_with_deleted_deps_dirty, mark_modules_with_expired_deps_dirty}; +use crate::build::packages::DevDeps; use crate::helpers::emojis::*; use crate::helpers::{self, get_workspace_root}; use crate::sourcedirs; @@ -26,9 +29,6 @@ use std::path::{Path, PathBuf}; use std::process::Stdio; use std::time::{Duration, Instant}; -use self::compile::compiler_args; -use self::parse::parser_args; - fn is_dirty(module: &Module) -> bool { match module.source_type { SourceType::SourceFile(SourceFile { @@ -154,7 +154,11 @@ pub fn initialize_build( &project_root, &workspace_root, show_progress, - build_dev_deps, + if build_dev_deps { + DevDeps::Build + } else { + DevDeps::DontBuild + }, )?; let timing_package_tree_elapsed = timing_package_tree.elapsed(); diff --git a/rewatch/src/build/clean.rs b/rewatch/src/build/clean.rs index 8a09bef035..255a77bd4d 100644 --- a/rewatch/src/build/clean.rs +++ b/rewatch/src/build/clean.rs @@ -1,5 +1,6 @@ use super::build_types::*; use super::packages; +use crate::build::packages::DevDeps; use crate::helpers; use crate::helpers::emojis::*; use ahash::AHashSet; @@ -346,7 +347,7 @@ pub fn clean( show_progress, // Build the package tree with dev dependencies. // They should always be cleaned if they are there. - true, + DevDeps::Clean, )?; let root_config_name = packages::read_package_name(&project_root)?; let bsc_path = match bsc_path { diff --git a/rewatch/src/build/packages.rs b/rewatch/src/build/packages.rs index 064383c3b7..d96c4947f9 100644 --- a/rewatch/src/build/packages.rs +++ b/rewatch/src/build/packages.rs @@ -426,9 +426,9 @@ fn make_package(config: config::Config, package_path: &Path, is_pinned_dep: bool } }; - let package_name = read_package_name(package_path).expect("Could not read package name"); + // let package_name = read_package_name(package_path).expect("Could not read package name"); Package { - name: package_name, + name: config.name.clone(), config: config.to_owned(), source_folders, source_files: None, @@ -490,7 +490,7 @@ pub fn get_source_files( package_dir: &Path, filter: &Option, source: &config::PackageSource, - build_dev_deps: bool, + dev_deps: DevDeps, ) -> AHashMap { let mut map: AHashMap = AHashMap::new(); @@ -504,17 +504,22 @@ pub fn get_source_files( }; let path_dir = Path::new(&source.dir); - match (build_dev_deps, type_) { - (false, Some(type_)) if type_ == "dev" => (), + let is_clean = match dev_deps { + DevDeps::Clean => true, + _ => false, + }; + match (dev_deps, type_) { + (DevDeps::DontBuild, Some(type_)) if type_ == "dev" => (), _ => match read_folders(filter, package_dir, path_dir, recurse) { Ok(files) => map.extend(files), - Err(_e) => log::error!( + Err(_e) if !is_clean => log::error!( "Could not read folder: {:?}. Specified in dependency: {}, located {:?}...", path_dir.to_path_buf().into_os_string(), package_name, package_dir ), + Err(_) => {} }, }; @@ -526,22 +531,14 @@ pub fn get_source_files( fn extend_with_children( filter: &Option, mut build: AHashMap, - build_dev_deps: bool, + dev_deps: DevDeps, ) -> AHashMap { for (_key, package) in build.iter_mut() { let mut map: AHashMap = AHashMap::new(); package .source_folders .par_iter() - .map(|source| { - get_source_files( - &package.name, - Path::new(&package.path), - filter, - source, - build_dev_deps, - ) - }) + .map(|source| get_source_files(&package.name, Path::new(&package.path), filter, source, dev_deps)) .collect::>>() .into_iter() .for_each(|source| map.extend(source)); @@ -571,6 +568,13 @@ fn extend_with_children( build } +#[derive(Clone, Copy)] +pub enum DevDeps { + Build, + DontBuild, + Clean, +} + /// Make turns a folder, that should contain a config, into a tree of Packages. /// It does so in two steps: /// 1. Get all the packages parsed, and take all the source folders from the config @@ -583,13 +587,13 @@ pub fn make( root_folder: &Path, workspace_root: &Option, show_progress: bool, - build_dev_deps: bool, + dev_deps: DevDeps, ) -> Result> { let map = read_packages(root_folder, workspace_root, show_progress)?; /* Once we have the deduplicated packages, we can add the source files for each - to minimize * the IO */ - let result = extend_with_children(filter, map, build_dev_deps); + let result = extend_with_children(filter, map, dev_deps); Ok(result) } diff --git a/rewatch/src/lock.rs b/rewatch/src/lock.rs index c0c3061abd..d81e54c1c4 100644 --- a/rewatch/src/lock.rs +++ b/rewatch/src/lock.rs @@ -21,7 +21,10 @@ pub enum Error { impl std::fmt::Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { let msg = match self { - Error::Locked(pid) => format!("A ReScript build is already running. The process ID (PID) is {}", pid), + Error::Locked(pid) => format!( + "A ReScript build is already running. The process ID (PID) is {}", + pid + ), Error::ParsingLockfile(e) => format!( "Could not parse lockfile: \n {} \n (try removing it and running the command again)", e diff --git a/rewatch/src/watcher.rs b/rewatch/src/watcher.rs index cee448ba9c..bb22a9545c 100644 --- a/rewatch/src/watcher.rs +++ b/rewatch/src/watcher.rs @@ -5,12 +5,12 @@ use crate::cmd; use crate::helpers; use crate::helpers::StrippedVerbatimPath; use crate::helpers::emojis::*; +use crate::lock::LOCKFILE; use crate::queue::FifoQueue; use crate::queue::*; use futures_timer::Delay; use notify::event::ModifyKind; use notify::{Config, Error, Event, EventKind, RecommendedWatcher, RecursiveMode, Watcher}; -use crate::lock::LOCKFILE; use std::path::{Path, PathBuf}; use std::sync::Arc; use std::sync::Mutex;