Skip to content

Don't panic when dev files are not found during clean. #7622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions rewatch/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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();

Expand Down
3 changes: 2 additions & 1 deletion rewatch/src/build/clean.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
40 changes: 22 additions & 18 deletions rewatch/src/build/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -490,7 +490,7 @@ pub fn get_source_files(
package_dir: &Path,
filter: &Option<regex::Regex>,
source: &config::PackageSource,
build_dev_deps: bool,
dev_deps: DevDeps,
) -> AHashMap<PathBuf, SourceFileMeta> {
let mut map: AHashMap<PathBuf, SourceFileMeta> = AHashMap::new();

Expand All @@ -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(_) => {}
},
};

Expand All @@ -526,22 +531,14 @@ pub fn get_source_files(
fn extend_with_children(
filter: &Option<regex::Regex>,
mut build: AHashMap<String, Package>,
build_dev_deps: bool,
dev_deps: DevDeps,
) -> AHashMap<String, Package> {
for (_key, package) in build.iter_mut() {
let mut map: AHashMap<PathBuf, SourceFileMeta> = 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::<Vec<AHashMap<PathBuf, SourceFileMeta>>>()
.into_iter()
.for_each(|source| map.extend(source));
Expand Down Expand Up @@ -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
Expand All @@ -583,13 +587,13 @@ pub fn make(
root_folder: &Path,
workspace_root: &Option<PathBuf>,
show_progress: bool,
build_dev_deps: bool,
dev_deps: DevDeps,
) -> Result<AHashMap<String, Package>> {
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)
}
Expand Down
5 changes: 4 additions & 1 deletion rewatch/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rewatch/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down