@@ -27,25 +27,35 @@ pub struct Context {
27
27
// FOO/src/bar-0.1 instead of FOO). The flag doesn't affect where
28
28
// rustpkg stores build artifacts.
29
29
use_rust_path_hack : bool ,
30
- // The root directory containing the Rust standard libraries
31
- sysroot : Path
32
30
}
33
31
34
32
#[ deriving( Clone ) ]
35
33
pub struct BuildContext {
36
34
// Context for workcache
37
35
workcache_context : workcache:: Context ,
38
- // Everything else
39
- context : Context
36
+ // Parsed command line options
37
+ context : Context ,
38
+ // The root directory containing the Rust standard libraries
39
+ sysroot : Path
40
40
}
41
41
42
42
impl BuildContext {
43
43
pub fn sysroot ( & self ) -> Path {
44
- self . context . sysroot . clone ( )
44
+ self . sysroot . clone ( )
45
45
}
46
46
47
+ // Hack so that rustpkg can run either out of a rustc target dir,
48
+ // or the host dir
47
49
pub fn sysroot_to_use ( & self ) -> Path {
48
- self . context . sysroot_to_use ( )
50
+ if !in_target ( & self . sysroot ) {
51
+ self . sysroot . clone ( )
52
+ } else {
53
+ let mut p = self . sysroot . clone ( ) ;
54
+ p. pop ( ) ;
55
+ p. pop ( ) ;
56
+ p. pop ( ) ;
57
+ p
58
+ }
49
59
}
50
60
51
61
/// Returns the flags to pass to rustc, as a vector of strings
@@ -132,28 +142,6 @@ pub enum StopBefore {
132
142
}
133
143
134
144
impl Context {
135
- pub fn sysroot ( & self ) -> Path {
136
- self . sysroot . clone ( )
137
- }
138
-
139
- /// Debugging
140
- pub fn sysroot_str ( & self ) -> ~str {
141
- self . sysroot . as_str ( ) . unwrap ( ) . to_owned ( )
142
- }
143
-
144
- // Hack so that rustpkg can run either out of a rustc target dir,
145
- // or the host dir
146
- pub fn sysroot_to_use ( & self ) -> Path {
147
- if !in_target ( & self . sysroot ) {
148
- self . sysroot . clone ( )
149
- } else {
150
- let mut p = self . sysroot . clone ( ) ;
151
- p. pop ( ) ;
152
- p. pop ( ) ;
153
- p. pop ( ) ;
154
- p
155
- }
156
- }
157
145
158
146
/// Returns the flags to pass to rustc, as a vector of strings
159
147
pub fn flag_strs ( & self ) -> ~[ ~str ] {
@@ -235,85 +223,122 @@ impl RustcFlags {
235
223
}
236
224
}
237
225
226
+
227
+ #[ deriving( Eq ) ]
228
+ pub enum Command {
229
+ BuildCmd ,
230
+ CleanCmd ,
231
+ DoCmd ,
232
+ InfoCmd ,
233
+ InstallCmd ,
234
+ ListCmd ,
235
+ PreferCmd ,
236
+ TestCmd ,
237
+ InitCmd ,
238
+ UninstallCmd ,
239
+ UnpreferCmd ,
240
+ }
241
+
242
+ impl FromStr for Command {
243
+
244
+ fn from_str ( s : & str ) -> Option < Command > {
245
+ match s {
246
+ & "build" => Some ( BuildCmd ) ,
247
+ & "clean" => Some ( CleanCmd ) ,
248
+ & "do" => Some ( DoCmd ) ,
249
+ & "info" => Some ( InfoCmd ) ,
250
+ & "install" => Some ( InstallCmd ) ,
251
+ & "list" => Some ( ListCmd ) ,
252
+ & "prefer" => Some ( PreferCmd ) ,
253
+ & "test" => Some ( TestCmd ) ,
254
+ & "init" => Some ( InitCmd ) ,
255
+ & "uninstall" => Some ( UninstallCmd ) ,
256
+ & "unprefer" => Some ( UnpreferCmd ) ,
257
+ _ => None
258
+ }
259
+ }
260
+ }
261
+
238
262
/// Returns true if any of the flags given are incompatible with the cmd
239
263
pub fn flags_forbidden_for_cmd ( flags : & RustcFlags ,
240
264
cfgs : & [ ~str ] ,
241
- cmd : & str , user_supplied_opt_level : bool ) -> bool {
265
+ cmd : Command , user_supplied_opt_level : bool ) -> bool {
242
266
let complain = |s| {
243
267
println ! ( "The {} option can only be used with the `build` command:
244
268
rustpkg [options..] build {} [package-ID]" , s, s) ;
245
269
} ;
246
270
247
- if flags. linker . is_some ( ) && cmd != "build" && cmd != "install" {
271
+ if flags. linker . is_some ( ) && cmd != BuildCmd && cmd != InstallCmd {
248
272
println ( "The --linker option can only be used with the build or install commands." ) ;
249
273
return true ;
250
274
}
251
- if flags. link_args . is_some ( ) && cmd != "build" && cmd != "install" {
275
+ if flags. link_args . is_some ( ) && cmd != BuildCmd && cmd != InstallCmd {
252
276
println ( "The --link-args option can only be used with the build or install commands." ) ;
253
277
return true ;
254
278
}
255
279
256
- if !cfgs. is_empty ( ) && cmd != "build" && cmd != "install" && cmd != "test" {
280
+ if !cfgs. is_empty ( ) && cmd != BuildCmd && cmd != InstallCmd && cmd != TestCmd {
257
281
println ( "The --cfg option can only be used with the build, test, or install commands." ) ;
258
282
return true ;
259
283
}
260
284
261
- if user_supplied_opt_level && cmd != "build" && cmd != "install" {
285
+ if user_supplied_opt_level && cmd != BuildCmd && cmd != InstallCmd {
262
286
println ( "The -O and --opt-level options can only be used with the build \
263
287
or install commands.") ;
264
288
return true ;
265
289
}
266
290
267
- if flags. save_temps && cmd != "build" && cmd != "install" {
291
+ if flags. save_temps && cmd != BuildCmd && cmd != InstallCmd {
268
292
println ( "The --save-temps option can only be used with the build \
269
293
or install commands.") ;
270
294
return true ;
271
295
}
272
296
273
- if flags. target . is_some ( ) && cmd != "build" && cmd != "install" {
297
+ if flags. target . is_some ( ) && cmd != BuildCmd && cmd != InstallCmd {
274
298
println ( "The --target option can only be used with the build \
275
299
or install commands.") ;
276
300
return true ;
277
301
}
278
- if flags. target_cpu . is_some ( ) && cmd != "build" && cmd != "install" {
302
+ if flags. target_cpu . is_some ( ) && cmd != BuildCmd && cmd != InstallCmd {
279
303
println ( "The --target-cpu option can only be used with the build \
280
304
or install commands.") ;
281
305
return true ;
282
306
}
283
- if flags. experimental_features . is_some ( ) && cmd != "build" && cmd != "install" {
307
+ if flags. experimental_features . is_some ( ) && cmd != BuildCmd && cmd != InstallCmd {
284
308
println ( "The -Z option can only be used with the build or install commands." ) ;
285
309
return true ;
286
310
}
287
311
288
312
match flags. compile_upto {
289
- Link if cmd != "build" => {
313
+ Link if cmd != BuildCmd => {
290
314
complain ( "--no-link" ) ;
291
315
true
292
316
}
293
- Trans if cmd != "build" => {
317
+ Trans if cmd != BuildCmd => {
294
318
complain ( "--no-trans" ) ;
295
319
true
296
320
}
297
- Assemble if cmd != "build" => {
321
+ Assemble if cmd != BuildCmd => {
298
322
complain ( "-S" ) ;
299
323
true
300
324
}
301
- Pretty if cmd != "build" => {
325
+ Pretty if cmd != BuildCmd => {
302
326
complain ( "--pretty" ) ;
303
327
true
304
328
}
305
- Analysis if cmd != "build" => {
329
+ Analysis if cmd != BuildCmd => {
306
330
complain ( "--parse-only" ) ;
307
331
true
308
332
}
309
- LLVMCompileBitcode if cmd != "build" => {
333
+ LLVMCompileBitcode if cmd != BuildCmd => {
310
334
complain ( "--emit-llvm" ) ;
311
335
true
312
336
}
313
- LLVMAssemble if cmd != "build" => {
337
+ LLVMAssemble if cmd != BuildCmd => {
314
338
complain ( "--emit-llvm" ) ;
315
339
true
316
340
}
317
341
_ => false
318
342
}
319
343
}
344
+
0 commit comments