11use crate :: common:: {
2- check_installed, create_virtualenv , create_virtualenv_name , maybe_mock_cargo, test_python_path,
2+ check_installed, create_named_virtualenv , create_virtualenv , maybe_mock_cargo, test_python_path,
33} ;
44use anyhow:: { bail, Context , Result } ;
55#[ cfg( feature = "zig" ) ]
66use cargo_zigbuild:: Zig ;
77use clap:: Parser ;
8- use fs2 :: FileExt ;
8+ use fs4 :: fs_err :: FileExt ;
99use fs_err:: File ;
1010use maturin:: { BuildOptions , PlatformTag , PythonInterpreter , Target } ;
1111use normpath:: PathExt ;
@@ -38,25 +38,25 @@ pub fn test_integration(
3838 let shed = format ! ( "test-crates/wheels/{unique_name}" ) ;
3939 let target_dir = format ! ( "test-crates/targets/{unique_name}" ) ;
4040 let python_interp = test_python_path ( ) ;
41- let mut cli = vec ! [
42- "build" ,
43- "--quiet" ,
44- "--manifest-path" ,
45- & package_string,
46- "--target-dir" ,
47- & target_dir,
48- "--out" ,
49- & shed,
41+ let mut cli: Vec < std :: ffi :: OsString > = vec ! [
42+ "build" . into ( ) ,
43+ "--quiet" . into ( ) ,
44+ "--manifest-path" . into ( ) ,
45+ package_string. into ( ) ,
46+ "--target-dir" . into ( ) ,
47+ target_dir. into ( ) ,
48+ "--out" . into ( ) ,
49+ shed. into ( ) ,
5050 ] ;
5151
5252 if let Some ( ref bindings) = bindings {
53- cli. push ( "--bindings" ) ;
54- cli. push ( bindings) ;
53+ cli. push ( "--bindings" . into ( ) ) ;
54+ cli. push ( bindings. into ( ) ) ;
5555 }
5656
5757 if let Some ( target) = target {
58- cli. push ( "--target" ) ;
59- cli. push ( target)
58+ cli. push ( "--target" . into ( ) ) ;
59+ cli. push ( target. into ( ) )
6060 }
6161
6262 #[ cfg( feature = "zig" ) ]
@@ -65,11 +65,11 @@ pub fn test_integration(
6565 let zig_found = false ;
6666
6767 let test_zig = if zig && ( env:: var ( "GITHUB_ACTIONS" ) . is_ok ( ) || zig_found) {
68- cli. push ( "--zig" ) ;
68+ cli. push ( "--zig" . into ( ) ) ;
6969 true
7070 } else {
71- cli. push ( "--compatibility" ) ;
72- cli. push ( "linux" ) ;
71+ cli. push ( "--compatibility" . into ( ) ) ;
72+ cli. push ( "linux" . into ( ) ) ;
7373 false
7474 } ;
7575
@@ -80,47 +80,52 @@ pub fn test_integration(
8080 . join ( "venvs" ) ;
8181 let cffi_provider = "cffi-provider" ;
8282 let cffi_venv = venvs_dir. join ( cffi_provider) ;
83- let target_triple = Target :: from_target_triple ( None ) ?;
84- let python = target_triple. get_venv_python ( & cffi_venv) ;
8583
8684 if let Some ( interp) = python_interp. as_ref ( ) {
87- cli. push ( "--interpreter" ) ;
88- cli. push ( interp) ;
85+ cli. push ( "--interpreter" . into ( ) ) ;
86+ cli. push ( interp. into ( ) ) ;
8987 } else {
9088 // Install cffi in a separate environment
9189
9290 // All tests try to use this venv at the same time, so we need to make sure only one
9391 // modifies it at a time and that during that time, no other test reads it.
9492 let file = File :: create ( venvs_dir. join ( "cffi-provider.lock" ) ) ?;
95- file. file ( ) . lock_exclusive ( ) ?;
96- if !dbg ! ( venvs_dir . join ( cffi_provider ) ) . is_dir ( ) {
97- dbg ! ( create_virtualenv_name (
98- cffi_provider ,
99- python_interp . clone ( ) . map ( PathBuf :: from )
100- ) ? ) ;
93+ file. lock_exclusive ( ) ?;
94+ let python = if !cffi_venv . is_dir ( ) {
95+ create_named_virtualenv ( cffi_provider , python_interp . clone ( ) . map ( PathBuf :: from ) ) ? ;
96+ let target_triple = Target :: from_target_triple ( None ) ? ;
97+ let python = target_triple . get_venv_python ( & cffi_venv ) ;
98+ assert ! ( python . is_file ( ) , "cffi venv not created correctly" ) ;
10199 let pip_install_cffi = [
102100 "-m" ,
103101 "pip" ,
104102 "--disable-pip-version-check" ,
103+ "--no-cache-dir" ,
105104 "install" ,
106105 "cffi" ,
107106 ] ;
108107 let output = Command :: new ( & python)
109108 . args ( pip_install_cffi)
110- . status ( )
111- //.output()
112- . context ( format ! ( "pip install cffi failed with {python:?}" ) ) ?;
113- if !output. success ( ) {
114- bail ! ( "Installing cffi into {} failed" , cffi_venv. display( ) ) ;
109+ . output ( )
110+ . with_context ( || format ! ( "pip install cffi failed with {python:?}" ) ) ?;
111+ if !output. status . success ( ) {
112+ let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
113+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
114+ bail ! (
115+ "Installing cffi into {} failed.\n stdout: {}\n stderr: {}" ,
116+ cffi_venv. display( ) ,
117+ stdout,
118+ stderr
119+ ) ;
115120 }
116- }
117- file. file ( ) . unlock ( ) ?;
118- cli. push ( "--interpreter" ) ;
119- cli. push (
120121 python
121- . to_str ( )
122- . context ( "non-utf8 python interpreter path" ) ?,
123- ) ;
122+ } else {
123+ let target_triple = Target :: from_target_triple ( None ) ?;
124+ target_triple. get_venv_python ( & cffi_venv)
125+ } ;
126+ file. unlock ( ) ?;
127+ cli. push ( "--interpreter" . into ( ) ) ;
128+ cli. push ( python. as_os_str ( ) . to_owned ( ) ) ;
124129 }
125130
126131 let options: BuildOptions = BuildOptions :: try_parse_from ( cli) ?;
@@ -234,20 +239,20 @@ pub fn test_integration_conda(package: impl AsRef<Path>, bindings: Option<String
234239 }
235240
236241 // The first argument is ignored by clap
237- let mut cli = vec ! [
238- "build" ,
239- "--manifest-path" ,
240- & package_string,
241- "--quiet" ,
242- "--interpreter" ,
242+ let mut cli: Vec < std :: ffi :: OsString > = vec ! [
243+ "build" . into ( ) ,
244+ "--manifest-path" . into ( ) ,
245+ package_string. into ( ) ,
246+ "--quiet" . into ( ) ,
247+ "--interpreter" . into ( ) ,
243248 ] ;
244249 for interp in & interpreters {
245- cli. push ( interp. to_str ( ) . unwrap ( ) ) ;
250+ cli. push ( interp. to_str ( ) . unwrap ( ) . into ( ) ) ;
246251 }
247252
248253 if let Some ( ref bindings) = bindings {
249- cli. push ( "--bindings" ) ;
250- cli. push ( bindings) ;
254+ cli. push ( "--bindings" . into ( ) ) ;
255+ cli. push ( bindings. into ( ) ) ;
251256 }
252257
253258 let options = BuildOptions :: try_parse_from ( cli) ?;
0 commit comments