Skip to content

Commit 40094b7

Browse files
authored
Fix warnings (#150)
1 parent 848dabc commit 40094b7

File tree

5 files changed

+25
-48
lines changed

5 files changed

+25
-48
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: 11 additions & 40 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
@@ -148,7 +148,7 @@ pub fn compile(
148148
"cmi",
149149
);
150150

151-
let cmi_digest = helpers::compute_file_hash(&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(&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
@@ -509,15 +509,14 @@ fn compile_file(
509509
project_root: &str,
510510
workspace_root: &Option<String>,
511511
build_dev_deps: bool,
512-
) -> Result<Option<String>> {
512+
) -> Result<Option<String>, String> {
513513
let ocaml_build_path_abs = package.get_ocaml_build_path();
514514
let build_path_abs = package.get_build_path();
515515
let implementation_file_path = match &module.source_type {
516516
SourceType::SourceFile(ref source_file) => Ok(&source_file.implementation.path),
517-
sourcetype => Err(anyhow!(
517+
sourcetype => Err(format!(
518518
"Tried to compile a file that is not a source file ({}). Path to AST: {}. ",
519-
sourcetype,
520-
ast_path
519+
sourcetype, ast_path
521520
)),
522521
}?;
523522
let module_name = helpers::file_path_to_module_name(implementation_file_path, &package.namespace);
@@ -544,12 +543,11 @@ fn compile_file(
544543
Ok(x) if !x.status.success() => {
545544
let stderr = String::from_utf8_lossy(&x.stderr);
546545
let stdout = String::from_utf8_lossy(&x.stdout);
547-
Err(anyhow!(stderr.to_string() + &stdout))
546+
Err(stderr.to_string() + &stdout)
548547
}
549-
Err(e) => Err(anyhow!(
548+
Err(e) => Err(format!(
550549
"Could not compile file. Error: {}. Path to AST: {:?}",
551-
e,
552-
ast_path
550+
e, ast_path
553551
)),
554552
Ok(x) => {
555553
let err = std::str::from_utf8(&x.stderr)
@@ -598,36 +596,9 @@ fn compile_file(
598596
ocaml_build_path_abs.to_string() + "/" + &module_name + ".cmi",
599597
);
600598
}
601-
match &module.source_type {
602-
SourceType::SourceFile(SourceFile {
603-
interface: Some(Interface { path, .. }),
604-
..
605-
})
606-
| SourceType::SourceFile(SourceFile {
607-
implementation: Implementation { path, .. },
608-
..
609-
}) => {
610-
// we need to copy the source file to the build directory.
611-
// editor tools expects the source file in lib/bs for finding the current package
612-
// and in lib/ocaml when referencing modules in other packages
613-
let _ = std::fs::copy(
614-
std::path::Path::new(&package.path).join(path),
615-
std::path::Path::new(&package.get_build_path()).join(path),
616-
)
617-
.expect("copying source file failed");
618-
619-
let _ = std::fs::copy(
620-
std::path::Path::new(&package.path).join(path),
621-
std::path::Path::new(&package.get_build_path())
622-
.join(std::path::Path::new(path).file_name().unwrap()),
623-
)
624-
.expect("copying source file failed");
625-
}
626-
_ => (),
627-
}
628599

629600
if helpers::contains_ascii_characters(&err) {
630-
if package.is_pinned_dep {
601+
if package.is_pinned_dep || package.is_local_dep {
631602
// supress warnings of external deps
632603
Ok(Some(err))
633604
} else {

src/build/packages.rs

Lines changed: 3 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
}
@@ -912,6 +914,7 @@ mod test {
912914
dirs: None,
913915
is_pinned_dep: false,
914916
is_root: false,
917+
is_local_dep: false,
915918
}
916919
}
917920
#[test]

src/build/parse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ pub fn generate_asts(
205205
// probably better to do this in a different function
206206
// specific to compiling mlmaps
207207
let compile_path = package.get_mlmap_compile_path();
208-
let mlmap_hash = helpers::compute_file_hash(&compile_path);
208+
let mlmap_hash = helpers::compute_file_hash(&Path::new(&compile_path));
209209
namespaces::compile_mlmap(package, module_name, &build_state.bsc_path);
210-
let mlmap_hash_after = helpers::compute_file_hash(&compile_path);
210+
let mlmap_hash_after = helpers::compute_file_hash(&Path::new(&compile_path));
211211

212212
let suffix = package
213213
.namespace

src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ pub fn format_namespaced_module_name(module_name: &str) -> String {
308308
}
309309
}
310310

311-
pub fn compute_file_hash(path: &str) -> Option<blake3::Hash> {
311+
pub fn compute_file_hash(path: &Path) -> Option<blake3::Hash> {
312312
match fs::read(path) {
313313
Ok(str) => Some(blake3::hash(&str)),
314314
Err(_) => None,

0 commit comments

Comments
 (0)