@@ -43,17 +43,14 @@ fn main() {
43
43
env:: set_var ( "MOZCONFIG" , "" ) ;
44
44
45
45
let out_dir = PathBuf :: from ( env:: var_os ( "OUT_DIR" ) . unwrap ( ) ) ;
46
- let src_dir = out_dir. join ( "mozjs" ) ;
47
46
let build_dir = out_dir. join ( "build" ) ;
48
47
49
48
// Used by rust-mozjs downstream, don't remove.
50
49
println ! ( "cargo:outdir={}" , build_dir. display( ) ) ;
51
50
52
- copy_sources ( "mozjs" . as_ref ( ) , & src_dir) ;
53
-
54
51
fs:: create_dir_all ( & build_dir) . expect ( "could not create build dir" ) ;
55
52
56
- build_jsapi ( & src_dir , & build_dir) ;
53
+ build_jsapi ( & build_dir) ;
57
54
build_jsglue ( & build_dir) ;
58
55
build_jsapi_bindings ( & build_dir) ;
59
56
@@ -62,7 +59,11 @@ fn main() {
62
59
}
63
60
64
61
for entry in WalkDir :: new ( "mozjs" ) {
65
- println ! ( "cargo:rerun-if-changed={}" , entry. path( ) . display( ) ) ;
62
+ let entry = entry. unwrap ( ) ;
63
+ let path = entry. path ( ) ;
64
+ if !ignore ( path) {
65
+ println ! ( "cargo:rerun-if-changed={}" , path. display( ) ) ;
66
+ }
66
67
}
67
68
68
69
for file in EXTRA_FILES {
@@ -125,7 +126,7 @@ fn cc_flags() -> Vec<&'static str> {
125
126
result
126
127
}
127
128
128
- fn build_jsapi ( src_dir : & Path , build_dir : & Path ) {
129
+ fn build_jsapi ( build_dir : & Path ) {
129
130
let target = env:: var ( "TARGET" ) . unwrap ( ) ;
130
131
let mut make = find_make ( ) ;
131
132
@@ -167,7 +168,7 @@ fn build_jsapi(src_dir: &Path, build_dir: &Path) {
167
168
. args ( & [ "-R" , "-f" ] )
168
169
. arg ( cargo_manifest_dir. join ( "makefile.cargo" ) )
169
170
. current_dir ( & build_dir)
170
- . env ( "SRC_DIR" , & src_dir )
171
+ . env ( "SRC_DIR" , & cargo_manifest_dir . join ( "mozjs" ) )
171
172
. env ( "NO_RUST_PANIC_HOOK" , "1" )
172
173
. status ( )
173
174
. expect ( "Failed to run `make`" ) ;
@@ -401,45 +402,19 @@ const MODULE_RAW_LINES: &'static [(&'static str, &'static str)] = &[
401
402
( "root::JS" , "pub type Rooted<T> = ::jsgc::Rooted<T>;" ) ,
402
403
] ;
403
404
404
- fn copy_sources ( source : & Path , target : & Path ) {
405
- for entry in WalkDir :: new ( source) {
406
- let entry = entry. expect ( "could not walk source tree" ) ;
407
- let relative_path = entry. path ( ) . strip_prefix ( & source) . unwrap ( ) ;
408
- let target_path = target. join ( relative_path) ;
409
-
410
- if entry. path ( ) . is_dir ( ) {
411
- if !target_path. exists ( ) {
412
- fs:: create_dir ( target_path) . expect ( "could not create directory" ) ;
413
- }
414
- } else {
415
- copy_file ( entry. path ( ) , & target_path)
416
- }
417
- }
418
- }
419
-
420
- fn copy_file ( source : & Path , target : & Path ) {
421
- if !target_is_up_to_date ( & source, & target) {
422
- fs:: copy ( & source, & target) . expect ( "could not copy file" ) ;
423
- }
424
- }
425
-
426
- fn target_is_up_to_date ( source : & Path , target : & Path ) -> bool {
427
- if !target. exists ( ) {
428
- return false ;
429
- }
430
-
431
- let source_metadata = source. metadata ( ) . expect ( "could not read source metadata" ) ;
432
- let target_metadata = target. metadata ( ) . expect ( "could not read target metadata" ) ;
433
-
434
- let source_modified = match source_metadata. modified ( ) {
435
- Ok ( modified) => modified,
436
- Err ( _) => return false ,
437
- } ;
438
-
439
- let target_modified = match target_metadata. modified ( ) {
440
- Ok ( modified) => modified,
441
- Err ( _) => return false ,
442
- } ;
443
-
444
- source_modified < target_modified
405
+ /// Rerun this build script if files under mozjs/ changed, unless this returns true.
406
+ /// Keep this in sync with .gitignore
407
+ fn ignore ( path : & Path ) -> bool {
408
+ let ignored_extensions = [ "pyc" , "so" , "dll" , "dylib" ] ;
409
+ let ignored_trailing_paths = [ [ "psutil" , "build" ] , [ "psutil" , "tmp" ] ] ;
410
+
411
+ path. extension ( ) . map_or ( false , |extension| {
412
+ ignored_extensions. iter ( ) . any ( |& ignored| extension == ignored)
413
+ } ) ||
414
+ ignored_trailing_paths. iter ( ) . any ( |trailing| {
415
+ let mut components = path. components ( ) . rev ( ) ;
416
+ trailing. iter ( ) . rev ( ) . all ( |& ignored| {
417
+ components. next ( ) . map_or ( false , |component| component. as_os_str ( ) == ignored)
418
+ } )
419
+ } )
445
420
}
0 commit comments