@@ -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
@@ -466,7 +466,11 @@ pub fn compiler_args(
466466 format!(
467467 "{}:{}:{}" ,
468468 root_config. get_module( ) ,
469- Path :: new( file_path) . parent( ) . unwrap( ) . to_str( ) . unwrap( ) ,
469+ // compile into lib/bs and later install in the right place
470+ Path :: new( "lib/bs" )
471+ . join( Path :: new( file_path) . parent( ) . unwrap( ) )
472+ . to_str( )
473+ . unwrap( ) ,
470474 root_config. get_suffix( )
471475 ) ,
472476 ]
@@ -610,15 +614,37 @@ fn compile_file(
610614 // we need to copy the source file to the build directory.
611615 // editor tools expects the source file in lib/bs for finding the current package
612616 // 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" ) ;
617+
618+ // update: we now generate the file in lib/bs/... and then install it in the right
619+ // in-source location if the hash is different
620+
621+ // the in-source file. This is the currently "installed" file
622+ let in_source_hash =
623+ helpers:: compute_file_hash ( & std:: path:: Path :: new ( & package. path ) . join ( path) ) ;
624+
625+ // this is the file that we just generated
626+ let generated_hash = helpers:: compute_file_hash (
627+ & std:: path:: Path :: new ( & package. get_build_path ( ) ) . join ( path) ,
628+ ) ;
629+
630+ match ( in_source_hash, generated_hash) {
631+ ( Some ( in_source_hash) , Some ( generated_hash) ) if in_source_hash == generated_hash => {
632+ // do nothing, the hashes are the same!
633+ ( )
634+ }
635+ _ => {
636+ // copy the file to the in-source location
637+ let _ = std:: fs:: copy (
638+ std:: path:: Path :: new ( & package. get_bs_build_path ( ) ) . join ( path) ,
639+ std:: path:: Path :: new ( & package. path ) . join ( path) ,
640+ )
641+ . expect ( "copying source file failed" ) ;
642+ }
643+ }
618644
619645 let _ = std:: fs:: copy (
620646 std:: path:: Path :: new ( & package. path ) . join ( path) ,
621- std:: path:: Path :: new ( & package. get_build_path ( ) )
647+ std:: path:: Path :: new ( & package. get_ocaml_build_path ( ) )
622648 . join ( std:: path:: Path :: new ( path) . file_name ( ) . unwrap ( ) ) ,
623649 )
624650 . expect ( "copying source file failed" ) ;
0 commit comments