1
1
use 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,
3
3
} ;
4
4
use anyhow:: { bail, Context , Result } ;
5
5
#[ cfg( feature = "zig" ) ]
6
6
use cargo_zigbuild:: Zig ;
7
7
use clap:: Parser ;
8
- use fs2 :: FileExt ;
8
+ use fs4 :: fs_err :: FileExt ;
9
9
use fs_err:: File ;
10
10
use maturin:: { BuildOptions , PlatformTag , PythonInterpreter , Target } ;
11
11
use normpath:: PathExt ;
@@ -38,25 +38,25 @@ pub fn test_integration(
38
38
let shed = format ! ( "test-crates/wheels/{unique_name}" ) ;
39
39
let target_dir = format ! ( "test-crates/targets/{unique_name}" ) ;
40
40
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 ( ) ,
50
50
] ;
51
51
52
52
if let Some ( ref bindings) = bindings {
53
- cli. push ( "--bindings" ) ;
54
- cli. push ( bindings) ;
53
+ cli. push ( "--bindings" . into ( ) ) ;
54
+ cli. push ( bindings. into ( ) ) ;
55
55
}
56
56
57
57
if let Some ( target) = target {
58
- cli. push ( "--target" ) ;
59
- cli. push ( target)
58
+ cli. push ( "--target" . into ( ) ) ;
59
+ cli. push ( target. into ( ) )
60
60
}
61
61
62
62
#[ cfg( feature = "zig" ) ]
@@ -65,11 +65,11 @@ pub fn test_integration(
65
65
let zig_found = false ;
66
66
67
67
let test_zig = if zig && ( env:: var ( "GITHUB_ACTIONS" ) . is_ok ( ) || zig_found) {
68
- cli. push ( "--zig" ) ;
68
+ cli. push ( "--zig" . into ( ) ) ;
69
69
true
70
70
} else {
71
- cli. push ( "--compatibility" ) ;
72
- cli. push ( "linux" ) ;
71
+ cli. push ( "--compatibility" . into ( ) ) ;
72
+ cli. push ( "linux" . into ( ) ) ;
73
73
false
74
74
} ;
75
75
@@ -80,47 +80,52 @@ pub fn test_integration(
80
80
. join ( "venvs" ) ;
81
81
let cffi_provider = "cffi-provider" ;
82
82
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) ;
85
83
86
84
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 ( ) ) ;
89
87
} else {
90
88
// Install cffi in a separate environment
91
89
92
90
// All tests try to use this venv at the same time, so we need to make sure only one
93
91
// modifies it at a time and that during that time, no other test reads it.
94
92
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" ) ;
101
99
let pip_install_cffi = [
102
100
"-m" ,
103
101
"pip" ,
104
102
"--disable-pip-version-check" ,
103
+ "--no-cache-dir" ,
105
104
"install" ,
106
105
"cffi" ,
107
106
] ;
108
107
let output = Command :: new ( & python)
109
108
. 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
+ ) ;
115
120
}
116
- }
117
- file. file ( ) . unlock ( ) ?;
118
- cli. push ( "--interpreter" ) ;
119
- cli. push (
120
121
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 ( ) ) ;
124
129
}
125
130
126
131
let options: BuildOptions = BuildOptions :: try_parse_from ( cli) ?;
@@ -234,20 +239,20 @@ pub fn test_integration_conda(package: impl AsRef<Path>, bindings: Option<String
234
239
}
235
240
236
241
// 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 ( ) ,
243
248
] ;
244
249
for interp in & interpreters {
245
- cli. push ( interp. to_str ( ) . unwrap ( ) ) ;
250
+ cli. push ( interp. to_str ( ) . unwrap ( ) . into ( ) ) ;
246
251
}
247
252
248
253
if let Some ( ref bindings) = bindings {
249
- cli. push ( "--bindings" ) ;
250
- cli. push ( bindings) ;
254
+ cli. push ( "--bindings" . into ( ) ) ;
255
+ cli. push ( bindings. into ( ) ) ;
251
256
}
252
257
253
258
let options = BuildOptions :: try_parse_from ( cli) ?;
0 commit comments