@@ -42,7 +42,8 @@ fn run_ar(sess: Session, args: &str, cwd: Option<&Path>,
42
42
}
43
43
let o = Process :: new ( ar, args. as_slice ( ) , opts) . finish_with_output ( ) ;
44
44
if !o. status . success ( ) {
45
- sess. err ( format ! ( "{} failed with: {}" , ar, o. status) ) ;
45
+ sess. err ( format ! ( "{} {} failed with: {}" , ar, args. connect( " " ) ,
46
+ o. status) ) ;
46
47
sess. note ( format ! ( "stdout ---\n {}" , str :: from_utf8( o. output) ) ) ;
47
48
sess. note ( format ! ( "stderr ---\n {}" , str :: from_utf8( o. error) ) ) ;
48
49
sess. abort_if_errors ( ) ;
@@ -88,16 +89,34 @@ impl Archive {
88
89
89
90
/// Adds all of the contents of the rlib at the specified path to this
90
91
/// archive.
91
- pub fn add_rlib ( & mut self , rlib : & Path ) {
92
- let name = rlib. filename_str ( ) . unwrap ( ) . split ( '-' ) . next ( ) . unwrap ( ) ;
93
- self . add_archive ( rlib, name, [ METADATA_FILENAME ] ) ;
92
+ ///
93
+ /// This ignores adding the bytecode from the rlib, and if LTO is enabled
94
+ /// then the object file also isn't added.
95
+ pub fn add_rlib ( & mut self , rlib : & Path , name : & str , lto : bool ) {
96
+ let object = format ! ( "{}.o" , name) ;
97
+ let bytecode = format ! ( "{}.bc" , name) ;
98
+ let mut ignore = ~[ METADATA_FILENAME , bytecode. as_slice ( ) ] ;
99
+ if lto {
100
+ ignore. push ( object. as_slice ( ) ) ;
101
+ }
102
+ self . add_archive ( rlib, name, ignore) ;
94
103
}
95
104
96
105
/// Adds an arbitrary file to this archive
97
106
pub fn add_file ( & mut self , file : & Path ) {
98
107
run_ar ( self . sess , "r" , None , [ & self . dst , file] ) ;
99
108
}
100
109
110
+ /// Removes a file from this archive
111
+ pub fn remove_file ( & mut self , file : & str ) {
112
+ run_ar ( self . sess , "d" , None , [ & self . dst , & Path :: new ( file) ] ) ;
113
+ }
114
+
115
+ pub fn files ( & self ) -> ~[ ~str ] {
116
+ let output = run_ar ( self . sess , "t" , None , [ & self . dst ] ) ;
117
+ str:: from_utf8 ( output. output ) . lines ( ) . map ( |s| s. to_owned ( ) ) . collect ( )
118
+ }
119
+
101
120
fn add_archive ( & mut self , archive : & Path , name : & str , skip : & [ & str ] ) {
102
121
let loc = TempDir :: new ( "rsar" ) . unwrap ( ) ;
103
122
@@ -109,11 +128,17 @@ impl Archive {
109
128
// The reason for this is that archives are keyed off the name of the
110
129
// files, so if two files have the same name they will override one
111
130
// another in the archive (bad).
131
+ //
132
+ // We skip any files explicitly desired for skipping, and we also skip
133
+ // all SYMDEF files as these are just magical placeholders which get
134
+ // re-created when we make a new archive anyway.
112
135
let files = fs:: readdir ( loc. path ( ) ) ;
113
136
let mut inputs = ~[ ] ;
114
137
for file in files. iter ( ) {
115
138
let filename = file. filename_str ( ) . unwrap ( ) ;
116
139
if skip. iter ( ) . any ( |s| * s == filename) { continue }
140
+ if filename. contains ( ".SYMDEF" ) { continue }
141
+
117
142
let filename = format ! ( "r-{}-{}" , name, filename) ;
118
143
let new_filename = file. with_filename ( filename) ;
119
144
fs:: rename ( file, & new_filename) ;
0 commit comments