Skip to content

Commit 916ba65

Browse files
committed
Fix local warnings
1 parent d1fa395 commit 916ba65

File tree

3 files changed

+48
-34
lines changed

3 files changed

+48
-34
lines changed

src/build.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,6 @@ pub fn incremental_build(
405405
}
406406
pb.finish();
407407
if !compile_errors.is_empty() {
408-
if helpers::contains_ascii_characters(&compile_warnings) {
409-
println!("{}", &compile_warnings);
410-
}
411408
if show_progress {
412409
println!(
413410
"{}{} {}Compiled {} modules in {:.2}s",
@@ -418,7 +415,12 @@ pub fn incremental_build(
418415
default_timing.unwrap_or(compile_duration).as_secs_f64()
419416
);
420417
}
421-
println!("{}", &compile_errors);
418+
if helpers::contains_ascii_characters(&compile_warnings) {
419+
println!("{}", &compile_warnings);
420+
}
421+
if helpers::contains_ascii_characters(&compile_errors) {
422+
println!("{}", &compile_errors);
423+
}
422424
// mark the original files as dirty again, because we didn't complete a full build
423425
for (module_name, module) in build_state.modules.iter_mut() {
424426
if tracked_dirty_modules.contains(module_name) {
@@ -437,8 +439,9 @@ pub fn incremental_build(
437439
default_timing.unwrap_or(compile_duration).as_secs_f64()
438440
);
439441
}
442+
440443
if helpers::contains_ascii_characters(&compile_warnings) {
441-
log::warn!("{}", &compile_warnings);
444+
println!("{}", &compile_warnings);
442445
}
443446
Ok(())
444447
}

src/build/compile.rs

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use super::packages;
88
use crate::config;
99
use crate::helpers;
1010
use ahash::{AHashMap, AHashSet};
11-
use anyhow::{anyhow, Result};
11+
use anyhow::anyhow;
1212
use console::style;
1313
use log::{debug, trace};
1414
use rayon::prelude::*;
@@ -22,7 +22,7 @@ pub fn compile(
2222
inc: impl Fn() + std::marker::Sync,
2323
set_length: impl Fn(u64),
2424
build_dev_deps: bool,
25-
) -> Result<(String, String, usize)> {
25+
) -> anyhow::Result<(String, String, usize)> {
2626
let mut compiled_modules = AHashSet::<String>::new();
2727
let dirty_modules = build_state
2828
.modules
@@ -513,15 +513,14 @@ fn compile_file(
513513
project_root: &str,
514514
workspace_root: &Option<String>,
515515
build_dev_deps: bool,
516-
) -> Result<Option<String>> {
516+
) -> Result<Option<String>, String> {
517517
let ocaml_build_path_abs = package.get_ocaml_build_path();
518518
let build_path_abs = package.get_build_path();
519519
let implementation_file_path = match &module.source_type {
520520
SourceType::SourceFile(ref source_file) => Ok(&source_file.implementation.path),
521-
sourcetype => Err(anyhow!(
521+
sourcetype => Err(format!(
522522
"Tried to compile a file that is not a source file ({}). Path to AST: {}. ",
523-
sourcetype,
524-
ast_path
523+
sourcetype, ast_path
525524
)),
526525
}?;
527526
let module_name = helpers::file_path_to_module_name(implementation_file_path, &package.namespace);
@@ -548,12 +547,11 @@ fn compile_file(
548547
Ok(x) if !x.status.success() => {
549548
let stderr = String::from_utf8_lossy(&x.stderr);
550549
let stdout = String::from_utf8_lossy(&x.stdout);
551-
Err(anyhow!(stderr.to_string() + &stdout))
550+
Err(stderr.to_string() + &stdout)
552551
}
553-
Err(e) => Err(anyhow!(
552+
Err(e) => Err(format!(
554553
"Could not compile file. Error: {}. Path to AST: {:?}",
555-
e,
556-
ast_path
554+
e, ast_path
557555
)),
558556
Ok(x) => {
559557
let err = std::str::from_utf8(&x.stderr)
@@ -602,47 +600,58 @@ fn compile_file(
602600
ocaml_build_path_abs.to_string() + "/" + &module_name + ".cmi",
603601
);
604602
}
605-
match &module.source_type {
606-
SourceType::SourceFile(SourceFile {
607-
interface: Some(Interface { path, .. }),
608-
..
609-
})
610-
| SourceType::SourceFile(SourceFile {
611-
implementation: Implementation { path, .. },
612-
..
613-
}) => {
603+
match (&module.source_type, is_interface) {
604+
(
605+
SourceType::SourceFile(SourceFile {
606+
implementation: Implementation { path, .. },
607+
..
608+
}),
609+
false,
610+
) => {
614611
// update: we now generate the file in lib/bs/... and then install it in the right
615612
// in-source location if the hash is different
616613

617614
// the in-source file. This is the currently "installed" file
618615
let in_source_hash =
619-
helpers::compute_file_hash(&std::path::Path::new(&package.path).join(path));
616+
helpers::compute_file_hash(&helpers::get_source_file_from_rescript_file(
617+
&std::path::Path::new(&package.path).join(path),
618+
&root_package.config.get_suffix(),
619+
));
620620

621621
// this is the file that we just generated
622-
let generated_hash = helpers::compute_file_hash(
623-
&std::path::Path::new(&package.get_build_path()).join(path),
624-
);
622+
let generated_hash =
623+
helpers::compute_file_hash(&helpers::get_source_file_from_rescript_file(
624+
&std::path::Path::new(&package.get_build_path()).join(path),
625+
&root_package.config.get_suffix(),
626+
));
625627

626628
match (in_source_hash, generated_hash) {
627629
(Some(in_source_hash), Some(generated_hash)) if in_source_hash == generated_hash => {
628630
// do nothing, the hashes are the same!
629631
()
630632
}
631633
_ => {
634+
let source = helpers::get_source_file_from_rescript_file(
635+
&std::path::Path::new(&package.get_build_path()).join(path),
636+
&root_package.config.get_suffix(),
637+
);
638+
let destination = helpers::get_source_file_from_rescript_file(
639+
&std::path::Path::new(&package.path).join(path),
640+
&root_package.config.get_suffix(),
641+
);
642+
// println!("copying source file to in-source location");
643+
// println!("{}", source.display());
644+
// println!("{}", destination.display());
632645
// copy the file to the in-source location
633-
let _ = std::fs::copy(
634-
std::path::Path::new(&package.get_build_path()).join(path),
635-
std::path::Path::new(&package.path).join(path),
636-
)
637-
.expect("copying source file failed");
646+
let _ = std::fs::copy(source, destination).expect("copying source file failed");
638647
}
639648
}
640649
}
641650
_ => (),
642651
}
643652

644653
if helpers::contains_ascii_characters(&err) {
645-
if package.is_pinned_dep {
654+
if package.is_pinned_dep || package.is_local_dep {
646655
// supress warnings of external deps
647656
Ok(Some(err))
648657
} else {

src/build/packages.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub struct Package {
5959
pub path: String,
6060
pub dirs: Option<AHashSet<PathBuf>>,
6161
pub is_pinned_dep: bool,
62+
pub is_local_dep: bool,
6263
pub is_root: bool,
6364
}
6465

@@ -410,6 +411,7 @@ fn make_package(config: config::Config, package_path: &str, is_pinned_dep: bool,
410411
.to_string(),
411412
dirs: None,
412413
is_pinned_dep,
414+
is_local_dep: !package_path.contains("node_modules"),
413415
is_root,
414416
}
415417
}

0 commit comments

Comments
 (0)