1
- use crate :: cmd:: { Command , CommandError } ;
1
+ use crate :: cmd:: { Command , CommandError , ProcessLinesActions } ;
2
2
use crate :: { build:: CratePatch , Crate , Toolchain , Workspace } ;
3
3
use anyhow:: Context as _;
4
4
use log:: info;
@@ -101,9 +101,6 @@ impl<'a> Prepare<'a> {
101
101
return Ok ( ( ) ) ;
102
102
}
103
103
104
- let mut yanked_deps = false ;
105
- let mut missing_deps = false ;
106
- let mut broken_deps = false ;
107
104
let mut cmd = Command :: new ( self . workspace , self . toolchain . cargo ( ) ) . args ( & [
108
105
"generate-lockfile" ,
109
106
"--manifest-path" ,
@@ -115,35 +112,7 @@ impl<'a> Prepare<'a> {
115
112
. env ( "__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS" , "nightly" ) ;
116
113
}
117
114
118
- match cmd
119
- . cd ( self . source_dir )
120
- . process_lines ( & mut |line, _| {
121
- if line. contains ( "failed to select a version for the requirement" ) {
122
- yanked_deps = true ;
123
- } else if line. contains ( "failed to load source for dependency" )
124
- || line. contains ( "no matching package named" )
125
- {
126
- missing_deps = true ;
127
- } else if line. contains ( "failed to parse manifest at" )
128
- || line. contains ( "error: invalid table header" )
129
- {
130
- broken_deps = true ;
131
- }
132
- } )
133
- . run_capture ( )
134
- {
135
- Ok ( _) => Ok ( ( ) ) ,
136
- Err ( CommandError :: ExecutionFailed { status : _, stderr } ) if yanked_deps => {
137
- Err ( PrepareError :: YankedDependencies ( stderr) . into ( ) )
138
- }
139
- Err ( CommandError :: ExecutionFailed { status : _, stderr } ) if missing_deps => {
140
- Err ( PrepareError :: MissingDependencies ( stderr) . into ( ) )
141
- }
142
- Err ( CommandError :: ExecutionFailed { status : _, stderr } ) if broken_deps => {
143
- Err ( PrepareError :: InvalidCargoTomlSyntaxInDependencies ( stderr) . into ( ) )
144
- }
145
- Err ( err) => Err ( err. into ( ) ) ,
146
- }
115
+ run_command ( cmd. cd ( self . source_dir ) )
147
116
}
148
117
149
118
fn fetch_deps ( & mut self ) -> anyhow:: Result < ( ) > {
@@ -157,9 +126,6 @@ pub(crate) fn fetch_deps(
157
126
source_dir : & Path ,
158
127
fetch_build_std_targets : & [ & str ] ,
159
128
) -> anyhow:: Result < ( ) > {
160
- let mut yanked_deps = false ;
161
- let mut missing_deps = false ;
162
- let mut broken_deps = false ;
163
129
let mut cmd = Command :: new ( workspace, toolchain. cargo ( ) )
164
130
. args ( & [ "fetch" , "--manifest-path" , "Cargo.toml" ] )
165
131
. cd ( source_dir) ;
@@ -173,22 +139,29 @@ pub(crate) fn fetch_deps(
173
139
cmd = cmd. args ( & [ "--target" , target] ) ;
174
140
}
175
141
176
- match cmd
177
- . process_lines ( & mut |line, _| {
178
- if line. contains ( "failed to select a version for the requirement" ) {
179
- yanked_deps = true ;
180
- } else if line. contains ( "failed to load source for dependency" )
181
- || line. contains ( "no matching package named" )
182
- {
183
- missing_deps = true ;
184
- } else if line. contains ( "failed to parse manifest at" )
185
- || line. contains ( "error: invalid table header" )
186
- {
187
- broken_deps = true ;
188
- }
189
- } )
190
- . run_capture ( )
191
- {
142
+ run_command ( cmd)
143
+ }
144
+
145
+ fn run_command ( cmd : Command ) -> anyhow:: Result < ( ) > {
146
+ let mut yanked_deps = false ;
147
+ let mut missing_deps = false ;
148
+ let mut broken_deps = false ;
149
+
150
+ let mut process = |line : & str , _: & mut ProcessLinesActions | {
151
+ if line. contains ( "failed to select a version for the requirement" ) {
152
+ yanked_deps = true ;
153
+ } else if line. contains ( "failed to load source for dependency" )
154
+ || line. contains ( "no matching package named" )
155
+ {
156
+ missing_deps = true ;
157
+ } else if line. contains ( "failed to parse manifest at" )
158
+ || line. contains ( "error: invalid table header" )
159
+ {
160
+ broken_deps = true ;
161
+ }
162
+ } ;
163
+
164
+ match cmd. process_lines ( & mut process) . run_capture ( ) {
192
165
Ok ( _) => Ok ( ( ) ) ,
193
166
Err ( CommandError :: ExecutionFailed { status : _, stderr } ) if yanked_deps => {
194
167
Err ( PrepareError :: YankedDependencies ( stderr) . into ( ) )
0 commit comments