@@ -13,6 +13,7 @@ import tags::*;
13
13
import middle:: trans:: crate_ctxt;
14
14
import middle:: trans:: node_id_type;
15
15
import middle:: ty;
16
+ import middle:: attr;
16
17
17
18
export def_to_str;
18
19
export hash_path;
@@ -457,12 +458,76 @@ fn encode_attributes(&ebml::writer ebml_w, &vec[attribute] attrs) {
457
458
ebml:: end_tag( ebml_w) ;
458
459
}
459
460
461
+ // So there's a special crate attribute called 'link' which defines the metadata
462
+ // that Rust cares about for linking crates. This attribute requires name and
463
+ // value attributes, so if the user didn't provide them we will throw them in
464
+ // anyway with default values.
465
+ fn synthesize_crate_attrs( & @crate_ctxt cx,
466
+ & @crate crate) -> vec[ attribute] {
467
+
468
+ fn synthesize_link_attr( & @crate_ctxt cx,
469
+ & vec[ @meta_item] items)
470
+ -> attribute {
471
+
472
+ auto bogus_span = rec( lo = 0 u, hi = 0 u) ;
473
+
474
+ auto name_item_ = meta_name_value( "name" , cx. link_meta. name) ;
475
+ auto name_item = rec( node=name_item_,
476
+ span=bogus_span) ;
477
+
478
+ auto vers_item_ = meta_name_value( "vers" , cx. link_meta. vers) ;
479
+ auto vers_item = rec( node=vers_item_,
480
+ span=bogus_span) ;
481
+
482
+ auto other_items = {
483
+ auto tmp = attr : : remove_meta_items_by_name( items, "name" ) ;
484
+ attr:: remove_meta_items_by_name( tmp, "vers" )
485
+ } ;
486
+
487
+ auto meta_items = [ @name_item] + [ @vers_item] + other_items;
488
+
489
+ auto link_item_ = meta_list( "link" , meta_items) ;
490
+ auto link_item = rec( node=link_item_,
491
+ span=bogus_span) ;
492
+
493
+ auto attr_ = rec( style = attr_inner,
494
+ value = link_item) ;
495
+ auto attr = rec( node=attr_,
496
+ span=bogus_span) ;
497
+
498
+ ret attr;
499
+ }
500
+
501
+ let vec[ attribute] attrs = [ ] ;
502
+ auto found_link_attr = false ;
503
+ for ( attribute attr in crate . node. attrs) {
504
+ attrs += if ( attr:: get_attr_name( attr) != "link" ) {
505
+ [ attr]
506
+ } else {
507
+ alt ( attr. node. value. node) {
508
+ case ( meta_list( ?n, ?l) ) {
509
+ found_link_attr = true ;
510
+ [ synthesize_link_attr( cx, l) ]
511
+ }
512
+ case ( _) { [ attr] }
513
+ }
514
+ }
515
+ }
516
+
517
+ if ( !found_link_attr) {
518
+ attrs += [ synthesize_link_attr( cx, [ ] ) ] ;
519
+ }
520
+
521
+ ret attrs;
522
+ }
523
+
460
524
fn encode_metadata( & @crate_ctxt cx, & @crate crate) -> str {
461
525
auto string_w = io:: string_writer( ) ;
462
526
auto buf_w = string_w. get_writer( ) . get_buf_writer( ) ;
463
527
auto ebml_w = ebml:: create_writer( buf_w) ;
464
528
465
- encode_attributes( ebml_w, crate . node. attrs) ;
529
+ auto crate_attrs = synthesize_crate_attrs( cx, crate ) ;
530
+ encode_attributes( ebml_w, crate_attrs) ;
466
531
// Encode and index the paths.
467
532
468
533
ebml:: start_tag( ebml_w, tag_paths) ;
0 commit comments