@@ -8,7 +8,7 @@ use super::packages;
88use crate :: config;
99use crate :: helpers;
1010use ahash:: { AHashMap , AHashSet } ;
11- use anyhow:: { anyhow, Result } ;
11+ use anyhow:: anyhow;
1212use console:: style;
1313use log:: { debug, trace} ;
1414use 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 {
0 commit comments