@@ -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        ] 
@@ -609,15 +613,37 @@ fn compile_file(
609613                    // we need to copy the source file to the build directory. 
610614                    // editor tools expects the source file in lib/bs for finding the current package 
611615                    // and in lib/ocaml when referencing modules in other packages 
612-                     let  _ = std:: fs:: copy ( 
613-                         std:: path:: Path :: new ( & package. path ) . join ( path) , 
614-                         std:: path:: Path :: new ( & package. get_build_path ( ) ) . join ( path) , 
615-                     ) 
616-                     . expect ( "copying source file failed" ) ; 
616+ 
617+                     // update: we now generate the file in lib/bs/... and then install it in the right 
618+                     // in-source location if the hash is different 
619+ 
620+                     // the in-source file. This is the currently "installed" file 
621+                     let  in_source_hash =
622+                         helpers:: compute_file_hash ( & std:: path:: Path :: new ( & package. path ) . join ( path) ) ; 
623+ 
624+                     // this is the file that we just generated 
625+                     let  generated_hash = helpers:: compute_file_hash ( 
626+                         & std:: path:: Path :: new ( & package. get_build_path ( ) ) . join ( path) , 
627+                     ) ; 
628+ 
629+                     match  ( in_source_hash,  generated_hash)  { 
630+                         ( Some ( in_source_hash) ,  Some ( generated_hash) )  if  in_source_hash == generated_hash => { 
631+                             // do nothing, the hashes are the same! 
632+                             ( ) 
633+                         } 
634+                         _ => { 
635+                             // copy the file to the in-source location 
636+                             let  _ = std:: fs:: copy ( 
637+                                 std:: path:: Path :: new ( & package. get_build_path ( ) ) . join ( path) , 
638+                                 std:: path:: Path :: new ( & package. path ) . join ( path) , 
639+                             ) 
640+                             . expect ( "copying source file failed" ) ; 
641+                         } 
642+                     } 
617643
618644                    let  _ = std:: fs:: copy ( 
619645                        std:: path:: Path :: new ( & package. path ) . join ( path) , 
620-                         std:: path:: Path :: new ( & package. get_build_path ( ) ) 
646+                         std:: path:: Path :: new ( & package. get_ocaml_build_path ( ) ) 
621647                            . join ( std:: path:: Path :: new ( path) . file_name ( ) . unwrap ( ) ) , 
622648                    ) 
623649                    . expect ( "copying source file failed" ) ; 
0 commit comments