Skip to content

Commit 5af8be2

Browse files
author
Roland Peelen
committed
🎨 - Make sourcedir creation optional
1 parent 91f41a7 commit 5af8be2

File tree

7 files changed

+59
-15
lines changed

7 files changed

+59
-15
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rewatch"
3-
version = "1.0.5"
3+
version = "1.0.6"
44
edition = "2021"
55

66
[dependencies]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rolandpeelen/rewatch",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"license": "BSD-3-Clause",
55
"bin": {
66
"rewatch": "rewatch"

src/build.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ pub fn incremental_build(
252252
default_timing: Option<Duration>,
253253
initial_build: bool,
254254
only_incremental: bool,
255+
create_sourcedirs: bool,
255256
) -> Result<(), IncrementalBuildError> {
256257
logs::initialize(&build_state.packages);
257258
let num_dirty_modules = build_state.modules.values().filter(|m| is_dirty(m)).count() as u64;
@@ -345,7 +346,9 @@ pub fn incremental_build(
345346
let compile_duration = start_compiling.elapsed();
346347

347348
logs::finalize(&build_state.packages);
348-
sourcedirs::print(&build_state);
349+
if create_sourcedirs {
350+
sourcedirs::print(&build_state);
351+
}
349352
pb.finish();
350353
if !compile_errors.is_empty() {
351354
if helpers::contains_ascii_characters(&compile_warnings) {
@@ -404,7 +407,12 @@ impl fmt::Display for BuildError {
404407
}
405408
}
406409

407-
pub fn build(filter: &Option<regex::Regex>, path: &str, no_timing: bool) -> Result<BuildState, BuildError> {
410+
pub fn build(
411+
filter: &Option<regex::Regex>,
412+
path: &str,
413+
no_timing: bool,
414+
create_sourcedirs: bool,
415+
) -> Result<BuildState, BuildError> {
408416
let default_timing: Option<std::time::Duration> = if no_timing {
409417
Some(std::time::Duration::new(0.0 as u64, 0.0 as u32))
410418
} else {
@@ -414,7 +422,7 @@ pub fn build(filter: &Option<regex::Regex>, path: &str, no_timing: bool) -> Resu
414422
let mut build_state =
415423
initialize_build(default_timing, filter, path).map_err(BuildError::InitializeBuild)?;
416424

417-
match incremental_build(&mut build_state, default_timing, true, false) {
425+
match incremental_build(&mut build_state, default_timing, true, false, create_sourcedirs) {
418426
Ok(_) => {
419427
let timing_total_elapsed = timing_total.elapsed();
420428
println!(

src/main.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ struct Args {
4040
#[arg(short, long)]
4141
no_timing: Option<bool>,
4242

43+
/// This creates a source_dirs.json file at the root of the monorepo, which is needed when you
44+
/// want to use Reanalyze
45+
#[arg(short, long)]
46+
create_sourcedirs: Option<bool>,
47+
4348
#[arg(long)]
4449
compiler_args: Option<String>,
4550

@@ -73,7 +78,12 @@ fn main() {
7378
lock::Lock::Aquired(_) => match command {
7479
Command::Clean => build::clean::clean(&folder),
7580
Command::Build => {
76-
match build::build(&filter, &folder, args.no_timing.unwrap_or(false)) {
81+
match build::build(
82+
&filter,
83+
&folder,
84+
args.no_timing.unwrap_or(false),
85+
args.create_sourcedirs.unwrap_or(false),
86+
) {
7787
Err(e) => {
7888
eprintln!("Error Building: {e}");
7989
std::process::exit(1)
@@ -87,7 +97,12 @@ fn main() {
8797
};
8898
}
8999
Command::Watch => {
90-
watcher::start(&filter, &folder, args.after_build);
100+
watcher::start(
101+
&filter,
102+
&folder,
103+
args.after_build,
104+
args.create_sourcedirs.unwrap_or(false),
105+
);
91106
}
92107
},
93108
}

src/sourcedirs.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn print(buildstate: &BuildState) {
8585

8686
// Write sourcedirs.json
8787
write_sourcedirs_files(
88-
package.get_build_path(),
88+
package.get_bs_build_path(),
8989
&SourceDirs {
9090
dirs: &dirs.clone().into_iter().collect::<Vec<Dir>>(),
9191
pkgs: &pkgs.clone().flatten().collect::<Vec<Pkg>>(),
@@ -101,12 +101,18 @@ pub fn print(buildstate: &BuildState) {
101101
})
102102
.unzip();
103103

104+
let mut merged_dirs: AHashSet<Dir> = AHashSet::new();
105+
let mut merged_pkgs: AHashMap<PackageName, AbsolutePath> = AHashMap::new();
106+
107+
dirs.into_iter().for_each(|dir_set| merged_dirs.extend(dir_set));
108+
pkgs.into_iter().for_each(|pkg_set| merged_pkgs.extend(pkg_set));
109+
104110
// Write sourcedirs.json
105111
write_sourcedirs_files(
106112
root_package.get_bs_build_path(),
107113
&SourceDirs {
108-
dirs: &dirs.into_iter().flatten().collect::<Vec<Dir>>(),
109-
pkgs: &pkgs.into_iter().flatten().collect::<Vec<Pkg>>(),
114+
dirs: &merged_dirs.into_iter().collect::<Vec<Dir>>(),
115+
pkgs: &merged_pkgs.into_iter().collect::<Vec<Pkg>>(),
110116
generated: &vec![],
111117
},
112118
)

src/watcher.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ async fn async_watch(
5151
path: &str,
5252
filter: &Option<regex::Regex>,
5353
after_build: Option<String>,
54+
create_sourcedirs: bool,
5455
) -> notify::Result<()> {
5556
let mut build_state = build::initialize_build(None, filter, path).expect("Can't initialize build");
5657
let mut needs_compile_type = CompileType::Incremental;
@@ -178,7 +179,15 @@ async fn async_watch(
178179
match needs_compile_type {
179180
CompileType::Incremental => {
180181
let timing_total = Instant::now();
181-
if build::incremental_build(&mut build_state, None, initial_build, !initial_build).is_ok() {
182+
if build::incremental_build(
183+
&mut build_state,
184+
None,
185+
initial_build,
186+
!initial_build,
187+
create_sourcedirs,
188+
)
189+
.is_ok()
190+
{
182191
if let Some(a) = after_build.clone() {
183192
cmd::run(a)
184193
}
@@ -197,7 +206,8 @@ async fn async_watch(
197206
CompileType::Full => {
198207
let timing_total = Instant::now();
199208
build_state = build::initialize_build(None, filter, path).expect("Can't initialize build");
200-
let _ = build::incremental_build(&mut build_state, None, initial_build, false);
209+
let _ =
210+
build::incremental_build(&mut build_state, None, initial_build, false, create_sourcedirs);
201211
if let Some(a) = after_build.clone() {
202212
cmd::run(a)
203213
}
@@ -220,7 +230,12 @@ async fn async_watch(
220230
}
221231
}
222232

223-
pub fn start(filter: &Option<regex::Regex>, folder: &str, after_build: Option<String>) {
233+
pub fn start(
234+
filter: &Option<regex::Regex>,
235+
folder: &str,
236+
after_build: Option<String>,
237+
create_sourcedirs: bool,
238+
) {
224239
futures::executor::block_on(async {
225240
let queue = Arc::new(FifoQueue::<Result<Event, Error>>::new());
226241
let producer = queue.clone();
@@ -232,7 +247,7 @@ pub fn start(filter: &Option<regex::Regex>, folder: &str, after_build: Option<St
232247
.watch(folder.as_ref(), RecursiveMode::Recursive)
233248
.expect("Could not start watcher");
234249

235-
if let Err(e) = async_watch(consumer, folder, filter, after_build).await {
250+
if let Err(e) = async_watch(consumer, folder, filter, after_build, create_sourcedirs).await {
236251
println!("error: {:?}", e)
237252
}
238253
})

0 commit comments

Comments
 (0)