@@ -498,43 +498,51 @@ pub fn collect_crate_types(session: &Session,
498
498
if session.opts.test {
499
499
return vec!(CrateTypeExecutable)
500
500
}
501
+
502
+ // Only check command line flags if present. If no types are specified by
503
+ // command line, then reuse the empty `base` Vec to hold the types that
504
+ // will be found in crate attributes.
501
505
let mut base = session.opts.crate_types.clone();
502
- let iter = attrs.iter().filter_map(|a| {
503
- if a.name().equiv(&(" crate_type")) {
504
- match a.value_str() {
505
- Some(ref n) if n.equiv(&(" rlib")) => Some(CrateTypeRlib),
506
- Some(ref n) if n.equiv(&(" dylib")) => Some(CrateTypeDylib),
507
- Some(ref n) if n.equiv(&(" lib")) => {
508
- Some(default_lib_output())
509
- }
510
- Some(ref n) if n.equiv(&(" staticlib")) => {
511
- Some(CrateTypeStaticlib)
512
- }
513
- Some(ref n) if n.equiv(&(" bin")) => Some(CrateTypeExecutable),
514
- Some(_) => {
515
- session.add_lint(lint::UnknownCrateType,
516
- ast::CRATE_NODE_ID,
517
- a.span,
518
- ~" invalid `crate_type` value");
519
- None
520
- }
521
- _ => {
522
- session.add_lint(lint::UnknownCrateType, ast::CRATE_NODE_ID,
523
- a.span, ~" `crate_type` requires a value" ) ;
524
- None
506
+ if base.len() > 0 {
507
+ return base
508
+ } else {
509
+ let iter = attrs.iter().filter_map(|a| {
510
+ if a.name().equiv(&(" crate_type")) {
511
+ match a.value_str() {
512
+ Some(ref n) if n.equiv(&(" rlib")) => Some(CrateTypeRlib),
513
+ Some(ref n) if n.equiv(&(" dylib")) => Some(CrateTypeDylib),
514
+ Some(ref n) if n.equiv(&(" lib")) => {
515
+ Some(default_lib_output())
516
+ }
517
+ Some(ref n) if n.equiv(&(" staticlib")) => {
518
+ Some(CrateTypeStaticlib)
519
+ }
520
+ Some(ref n) if n.equiv(&(" bin")) => Some(CrateTypeExecutable),
521
+ Some(_) => {
522
+ session.add_lint(lint::UnknownCrateType,
523
+ ast::CRATE_NODE_ID,
524
+ a.span,
525
+ ~" invalid `crate_type` value");
526
+ None
527
+ }
528
+ _ => {
529
+ session.add_lint(lint::UnknownCrateType, ast::CRATE_NODE_ID,
530
+ a.span, ~" `crate_type` requires a value" ) ;
531
+ None
532
+ }
525
533
}
534
+ } else {
535
+ None
526
536
}
527
- } else {
528
- None
537
+ } ) ;
538
+ base. extend ( iter) ;
539
+ if base. len ( ) == 0 {
540
+ base. push ( CrateTypeExecutable ) ;
529
541
}
530
- } ) ;
531
- base. extend ( iter) ;
532
- if base. len ( ) == 0 {
533
- base. push ( CrateTypeExecutable ) ;
534
- }
535
- base. as_mut_slice ( ) . sort ( ) ;
536
- base. dedup ( ) ;
537
- return base;
542
+ base. as_mut_slice ( ) . sort ( ) ;
543
+ base. dedup ( ) ;
544
+ return base;
545
+ }
538
546
}
539
547
540
548
pub fn sess_os_to_meta_os ( os : abi:: Os ) -> metadata:: loader:: Os {
0 commit comments