Skip to content

Commit 87c9be5

Browse files
committed
upstream changes
1 parent db3a126 commit 87c9be5

18 files changed

+257
-96
lines changed

rewatch/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rewatch/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rewatch"
3-
version = "1.1.3"
3+
version = "1.2.0"
44
edition = "2021"
55

66
[dependencies]

rewatch/src/build.rs

+19-22
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::build::compile::{mark_modules_with_deleted_deps_dirty, mark_modules_w
1212
use crate::helpers::emojis::*;
1313
use crate::helpers::{self, get_workspace_root};
1414
use crate::sourcedirs;
15-
use ahash::AHashSet;
1615
use anyhow::{anyhow, Result};
1716
use build_types::*;
1817
use console::style;
@@ -134,6 +133,7 @@ pub fn initialize_build(
134133
show_progress: bool,
135134
path: &str,
136135
bsc_path: Option<String>,
136+
build_dev_deps: bool,
137137
) -> Result<BuildState> {
138138
let project_root = helpers::get_abs_path(path);
139139
let workspace_root = helpers::get_workspace_root(&project_root);
@@ -150,7 +150,13 @@ pub fn initialize_build(
150150
}
151151

152152
let timing_package_tree = Instant::now();
153-
let packages = packages::make(filter, &project_root, &workspace_root, show_progress)?;
153+
let packages = packages::make(
154+
filter,
155+
&project_root,
156+
&workspace_root,
157+
show_progress,
158+
build_dev_deps,
159+
)?;
154160
let timing_package_tree_elapsed = timing_package_tree.elapsed();
155161

156162
if show_progress {
@@ -276,7 +282,7 @@ impl fmt::Display for IncrementalBuildError {
276282
pub fn incremental_build(
277283
build_state: &mut BuildState,
278284
default_timing: Option<Duration>,
279-
initial_build: bool,
285+
_initial_build: bool,
280286
show_progress: bool,
281287
only_incremental: bool,
282288
create_sourcedirs: bool,
@@ -350,17 +356,7 @@ pub fn incremental_build(
350356
);
351357
}
352358

353-
// track the compile dirty state, we reset it when the compile fails
354-
let mut tracked_dirty_modules = AHashSet::new();
355-
for (module_name, module) in build_state.modules.iter() {
356-
if module.compile_dirty {
357-
tracked_dirty_modules.insert(module_name.to_owned());
358-
}
359-
}
360-
if initial_build {
361-
// repair broken state
362-
mark_modules_with_expired_deps_dirty(build_state);
363-
}
359+
mark_modules_with_expired_deps_dirty(build_state);
364360
mark_modules_with_deleted_deps_dirty(build_state);
365361
current_step += 1;
366362

@@ -421,12 +417,6 @@ pub fn incremental_build(
421417
if helpers::contains_ascii_characters(&compile_errors) {
422418
println!("{}", &compile_errors);
423419
}
424-
// mark the original files as dirty again, because we didn't complete a full build
425-
for (module_name, module) in build_state.modules.iter_mut() {
426-
if tracked_dirty_modules.contains(module_name) {
427-
module.compile_dirty = true;
428-
}
429-
}
430420
Err(IncrementalBuildError::CompileError(None))
431421
} else {
432422
if show_progress {
@@ -476,8 +466,15 @@ pub fn build(
476466
None
477467
};
478468
let timing_total = Instant::now();
479-
let mut build_state = initialize_build(default_timing, filter, show_progress, path, bsc_path)
480-
.map_err(|e| anyhow!("Could not initialize build. Error: {e}"))?;
469+
let mut build_state = initialize_build(
470+
default_timing,
471+
filter,
472+
show_progress,
473+
path,
474+
bsc_path,
475+
build_dev_deps,
476+
)
477+
.map_err(|e| anyhow!("Could not initialize build. Error: {e}"))?;
481478

482479
match incremental_build(
483480
&mut build_state,

rewatch/src/build/clean.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,17 @@ pub fn cleanup_after_build(build_state: &BuildState) {
338338
});
339339
}
340340

341-
pub fn clean(path: &str, show_progress: bool, bsc_path: Option<String>) -> Result<()> {
341+
pub fn clean(path: &str, show_progress: bool, bsc_path: Option<String>, build_dev_deps: bool) -> Result<()> {
342342
let project_root = helpers::get_abs_path(path);
343343
let workspace_root = helpers::get_workspace_root(&project_root);
344-
let packages = packages::make(&None, &project_root, &workspace_root, show_progress)?;
344+
let packages = packages::make(
345+
&None,
346+
&project_root,
347+
&workspace_root,
348+
show_progress,
349+
// Always clean dev dependencies
350+
build_dev_deps,
351+
)?;
345352
let root_config_name = packages::read_package_name(&project_root)?;
346353
let bsc_path = match bsc_path {
347354
Some(bsc_path) => helpers::get_abs_path(&bsc_path),

rewatch/src/build/compile.rs

+83-29
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub fn compile(
148148
"cmi",
149149
);
150150

151-
let cmi_digest = helpers::compute_file_hash(&Path::new(&cmi_path));
151+
let cmi_digest = helpers::compute_file_hash(Path::new(&cmi_path));
152152

153153
let package = build_state
154154
.get_package(&module.package_name)
@@ -189,7 +189,7 @@ pub fn compile(
189189
&build_state.workspace_root,
190190
build_dev_deps,
191191
);
192-
let cmi_digest_after = helpers::compute_file_hash(&Path::new(&cmi_path));
192+
let cmi_digest_after = helpers::compute_file_hash(Path::new(&cmi_path));
193193

194194
// we want to compare both the hash of interface and the implementation
195195
// compile assets to verify that nothing changed. We also need to checke the interface
@@ -326,7 +326,7 @@ pub fn compile(
326326
if files_total_count == compile_universe_count {
327327
break;
328328
}
329-
if in_progress_modules.len() == 0 || in_progress_modules.eq(&current_in_progres_modules) {
329+
if in_progress_modules.is_empty() || in_progress_modules.eq(&current_in_progres_modules) {
330330
// find the dependency cycle
331331
let cycle = dependency_cycle::find(
332332
&compile_universe
@@ -364,33 +364,10 @@ pub fn compiler_args(
364364
packages: &Option<&AHashMap<String, packages::Package>>,
365365
build_dev_deps: bool,
366366
) -> Vec<String> {
367-
let normal_deps = config.bs_dependencies.as_ref().unwrap_or(&vec![]).to_owned();
368-
369367
let bsc_flags = config::flatten_flags(&config.bsc_flags);
370-
// don't compile dev-deps yet
371-
let dev_deps = if build_dev_deps {
372-
config.bs_dev_dependencies.as_ref().unwrap_or(&vec![]).to_owned()
373-
} else {
374-
vec![]
375-
};
376368

377-
let deps = [dev_deps, normal_deps]
378-
.concat()
379-
.par_iter()
380-
.map(|package_name| {
381-
let canonicalized_path = if let Some(packages) = packages {
382-
let package = packages.get(package_name).expect("expect package");
383-
package.path.to_string()
384-
} else {
385-
packages::read_dependency(package_name, project_root, project_root, workspace_root)
386-
.expect("cannot find dep")
387-
};
388-
vec![
389-
"-I".to_string(),
390-
packages::get_ocaml_build_path(&canonicalized_path),
391-
]
392-
})
393-
.collect::<Vec<Vec<String>>>();
369+
let dependency_paths =
370+
get_dependency_paths(config, project_root, workspace_root, packages, build_dev_deps);
394371

395372
let module_name = helpers::file_path_to_module_name(file_path, &config.get_namespace());
396373

@@ -500,7 +477,7 @@ pub fn compiler_args(
500477
namespace_args,
501478
read_cmi_args,
502479
vec!["-I".to_string(), "../ocaml".to_string()],
503-
deps.concat(),
480+
dependency_paths.concat(),
504481
uncurried_args,
505482
bsc_flags.to_owned(),
506483
warning_args,
@@ -522,6 +499,83 @@ pub fn compiler_args(
522499
.concat()
523500
}
524501

502+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
503+
enum DependentPackage {
504+
Normal(String),
505+
Dev(String),
506+
}
507+
508+
impl DependentPackage {
509+
fn name(&self) -> &str {
510+
match self {
511+
Self::Normal(name) => name,
512+
Self::Dev(name) => name,
513+
}
514+
}
515+
516+
fn is_dev(&self) -> bool {
517+
match self {
518+
Self::Normal(_) => false,
519+
Self::Dev(_) => true,
520+
}
521+
}
522+
}
523+
524+
fn get_dependency_paths(
525+
config: &config::Config,
526+
project_root: &str,
527+
workspace_root: &Option<String>,
528+
packages: &Option<&AHashMap<String, packages::Package>>,
529+
build_dev_deps: bool,
530+
) -> Vec<Vec<String>> {
531+
let normal_deps = config
532+
.bs_dependencies
533+
.clone()
534+
.unwrap_or_default()
535+
.into_iter()
536+
.map(DependentPackage::Normal)
537+
.collect();
538+
let dev_deps = if build_dev_deps {
539+
config
540+
.bs_dev_dependencies
541+
.clone()
542+
.unwrap_or_default()
543+
.into_iter()
544+
.map(DependentPackage::Dev)
545+
.collect()
546+
} else {
547+
vec![]
548+
};
549+
550+
[dev_deps, normal_deps]
551+
.concat()
552+
.par_iter()
553+
.filter_map(|dependent_package| {
554+
let package_name = dependent_package.name();
555+
let dependency_path = if let Some(packages) = packages {
556+
packages.get(package_name).map(|package| package.path.to_string())
557+
} else {
558+
packages::read_dependency(package_name, project_root, project_root, workspace_root).ok()
559+
}
560+
.map(|canonicalized_path| {
561+
vec![
562+
"-I".to_string(),
563+
packages::get_ocaml_build_path(&canonicalized_path),
564+
]
565+
});
566+
567+
if !dependent_package.is_dev() && dependency_path.is_none() {
568+
panic!(
569+
"Expected to find dependent package {} of {}",
570+
package_name, config.name
571+
);
572+
}
573+
574+
dependency_path
575+
})
576+
.collect::<Vec<Vec<String>>>()
577+
}
578+
525579
fn compile_file(
526580
package: &packages::Package,
527581
root_package: &packages::Package,

rewatch/src/build/packages.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ pub fn get_source_files(
496496
package_dir: &Path,
497497
filter: &Option<regex::Regex>,
498498
source: &config::PackageSource,
499+
build_dev_deps: bool,
499500
) -> AHashMap<String, SourceFileMeta> {
500501
let mut map: AHashMap<String, SourceFileMeta> = AHashMap::new();
501502

@@ -509,24 +510,19 @@ pub fn get_source_files(
509510
};
510511

511512
let path_dir = Path::new(&source.dir);
512-
// don't include dev sources for now
513-
if type_ != &Some("dev".to_string()) {
514-
match read_folders(filter, package_dir, path_dir, recurse) {
513+
match (build_dev_deps, type_) {
514+
(false, Some(type_)) if type_ == "dev" => (),
515+
_ => match read_folders(filter, package_dir, path_dir, recurse) {
515516
Ok(files) => map.extend(files),
516-
// Err(_e) if type_ == &Some("dev".to_string()) => {
517-
// log::warn!(
518-
// "Could not read folder: {}... Probably ok as type is dev",
519-
// path_dir.to_string_lossy()
520-
// )
521-
// }
517+
522518
Err(_e) => log::error!(
523519
"Could not read folder: {:?}. Specified in dependency: {}, located {:?}...",
524520
path_dir.to_path_buf().into_os_string(),
525521
package_name,
526522
package_dir
527523
),
528-
}
529-
}
524+
},
525+
};
530526

531527
map
532528
}
@@ -536,13 +532,22 @@ pub fn get_source_files(
536532
fn extend_with_children(
537533
filter: &Option<regex::Regex>,
538534
mut build: AHashMap<String, Package>,
535+
build_dev_deps: bool,
539536
) -> AHashMap<String, Package> {
540537
for (_key, package) in build.iter_mut() {
541538
let mut map: AHashMap<String, SourceFileMeta> = AHashMap::new();
542539
package
543540
.source_folders
544541
.par_iter()
545-
.map(|source| get_source_files(&package.name, Path::new(&package.path), filter, source))
542+
.map(|source| {
543+
get_source_files(
544+
&package.name,
545+
Path::new(&package.path),
546+
filter,
547+
source,
548+
build_dev_deps,
549+
)
550+
})
546551
.collect::<Vec<AHashMap<String, SourceFileMeta>>>()
547552
.into_iter()
548553
.for_each(|source| map.extend(source));
@@ -584,12 +589,13 @@ pub fn make(
584589
root_folder: &str,
585590
workspace_root: &Option<String>,
586591
show_progress: bool,
592+
build_dev_deps: bool,
587593
) -> Result<AHashMap<String, Package>> {
588594
let map = read_packages(root_folder, workspace_root.to_owned(), show_progress)?;
589595

590596
/* Once we have the deduplicated packages, we can add the source files for each - to minimize
591597
* the IO */
592-
let result = extend_with_children(filter, map);
598+
let result = extend_with_children(filter, map, build_dev_deps);
593599

594600
Ok(result)
595601
}

0 commit comments

Comments
 (0)