44
55use lazy_static:: lazy_static;
66use serde:: Deserialize ;
7- use slog:: warn;
7+ use slog:: { info , warn} ;
88use std:: collections:: BTreeMap ;
99use std:: fs:: { read_dir, read_to_string} ;
1010use std:: path:: { Path , PathBuf } ;
@@ -20,16 +20,24 @@ lazy_static! {
2020 let mut res: BTreeMap <& ' static str , & ' static [ u8 ] > = BTreeMap :: new( ) ;
2121
2222 res. insert(
23- "command/build_ext.py" ,
24- include_bytes!( "../distutils/command/build_ext.py" ) ,
23+ "distutils/ command/build_ext.py" ,
24+ include_bytes!( "../cpython_lib_hacks/ distutils/command/build_ext.py" ) ,
2525 ) ;
2626 res. insert(
27- "_msvccompiler.py" ,
28- include_bytes!( "../distutils/_msvccompiler.py" ) ,
27+ "distutils/ _msvccompiler.py" ,
28+ include_bytes!( "../cpython_lib_hacks/ distutils/_msvccompiler.py" ) ,
2929 ) ;
3030 res. insert(
31- "unixccompiler.py" ,
32- include_bytes!( "../distutils/unixccompiler.py" ) ,
31+ "distutils/unixccompiler.py" ,
32+ include_bytes!( "../cpython_lib_hacks/distutils/unixccompiler.py" ) ,
33+ ) ;
34+ res. insert(
35+ "venv/__init__.py" ,
36+ include_bytes!( "../cpython_lib_hacks/venv/__init__.py" ) ,
37+ ) ;
38+ res. insert(
39+ "venv/__main__.py" ,
40+ include_bytes!( "../cpython_lib_hacks/venv/__main__.py" ) ,
3341 ) ;
3442
3543 res
@@ -56,27 +64,32 @@ pub fn prepare_hacked_distutils(logger: &slog::Logger, target: &PythonPaths) {
5664 target. stdlib. display( )
5765 ) ;
5866
59- let dest_distutils_path = target. stdlib . join ( "distutils" ) ;
67+ let dest_stdlib_path = target. stdlib . clone ( ) ;
6068
6169 // The venv "pyvenv.cfg" is used as a proxy for the first hack
6270 let src_metadata = fs:: metadata ( & target. prefix . join ( ".timestamp" ) ) . unwrap ( ) ;
6371
6472 let src_mtime = FileTime :: from_last_modification_time ( & src_metadata) ;
6573
6674 for ( path, data) in MODIFIED_DISTUTILS_FILES . iter ( ) {
67- let mut dest_path = dest_distutils_path . clone ( ) ;
75+ let mut dest_path = dest_stdlib_path . clone ( ) ;
6876 dest_path. extend ( path. split ( "/" ) ) ;
69-
70- let dest_metadata = fs:: metadata ( dest_path. canonicalize ( ) . unwrap ( ) ) . unwrap ( ) ;
71-
72- let dest_mtime = FileTime :: from_last_modification_time ( & dest_metadata) ;
73-
74- if src_mtime < dest_mtime {
75- warn ! ( logger, "not overwriting newer distutils/{}" , path) ;
76- continue ;
77+ info ! ( logger, "checking {}" , path) ;
78+ if dest_path. exists ( ) {
79+ let dest_metadata = fs:: metadata ( dest_path. canonicalize ( ) . unwrap ( ) ) . unwrap ( ) ;
80+
81+ let dest_mtime = FileTime :: from_last_modification_time ( & dest_metadata) ;
82+
83+ if src_mtime < dest_mtime {
84+ warn ! ( logger, "not overwriting newer {}" , path) ;
85+ continue ;
86+ }
87+ warn ! ( logger, "modifying {} for oxidation" , path) ;
88+ } else {
89+ let dest_dir = dest_path. parent ( ) . unwrap ( ) ;
90+ std:: fs:: create_dir_all ( & dest_dir) . unwrap ( ) ;
91+ warn ! ( logger, "installing missing {} for oxidation" , path) ;
7792 }
78-
79- warn ! ( logger, "modifying distutils/{} for oxidation" , path) ;
8093 std:: fs:: write ( dest_path, data) . unwrap ( ) ;
8194 }
8295}
0 commit comments