@@ -197,23 +197,70 @@ pub struct OutputFilenames {
197197 pub outputs : HashMap < OutputType , Option < PathBuf > > ,
198198}
199199
200+ /// Codegen unit names generated by the numbered naming scheme will contain this
201+ /// marker right before the index of the codegen unit.
202+ pub const NUMBERED_CODEGEN_UNIT_MARKER : & ' static str = ".cgu-" ;
203+
200204impl OutputFilenames {
201205 pub fn path ( & self , flavor : OutputType ) -> PathBuf {
202206 self . outputs . get ( & flavor) . and_then ( |p| p. to_owned ( ) )
203207 . or_else ( || self . single_output_file . clone ( ) )
204- . unwrap_or_else ( || self . temp_path ( flavor) )
208+ . unwrap_or_else ( || self . temp_path ( flavor, None ) )
205209 }
206210
207- pub fn temp_path ( & self , flavor : OutputType ) -> PathBuf {
211+ /// Get the path where a compilation artifact of the given type for the
212+ /// given codegen unit should be placed on disk. If codegen_unit_name is
213+ /// None, a path distinct from those of any codegen unit will be generated.
214+ pub fn temp_path ( & self ,
215+ flavor : OutputType ,
216+ codegen_unit_name : Option < & str > )
217+ -> PathBuf {
218+ let extension = match flavor {
219+ OutputType :: Bitcode => "bc" ,
220+ OutputType :: Assembly => "s" ,
221+ OutputType :: LlvmAssembly => "ll" ,
222+ OutputType :: Object => "o" ,
223+ OutputType :: DepInfo => "d" ,
224+ OutputType :: Exe => "" ,
225+ } ;
226+
227+ self . temp_path_ext ( extension, codegen_unit_name)
228+ }
229+
230+ /// Like temp_path, but also supports things where there is no corresponding
231+ /// OutputType, like no-opt-bitcode or lto-bitcode.
232+ pub fn temp_path_ext ( & self ,
233+ ext : & str ,
234+ codegen_unit_name : Option < & str > )
235+ -> PathBuf {
208236 let base = self . out_directory . join ( & self . filestem ( ) ) ;
209- match flavor {
210- OutputType :: Bitcode => base. with_extension ( "bc" ) ,
211- OutputType :: Assembly => base. with_extension ( "s" ) ,
212- OutputType :: LlvmAssembly => base. with_extension ( "ll" ) ,
213- OutputType :: Object => base. with_extension ( "o" ) ,
214- OutputType :: DepInfo => base. with_extension ( "d" ) ,
215- OutputType :: Exe => base,
237+
238+ let mut extension = String :: new ( ) ;
239+
240+ if let Some ( codegen_unit_name) = codegen_unit_name {
241+ if codegen_unit_name. contains ( NUMBERED_CODEGEN_UNIT_MARKER ) {
242+ // If we use the numbered naming scheme for modules, we don't want
243+ // the files to look like <crate-name><extra>.<crate-name>.<index>.<ext>
244+ // but simply <crate-name><extra>.<index>.<ext>
245+ let marker_offset = codegen_unit_name. rfind ( NUMBERED_CODEGEN_UNIT_MARKER )
246+ . unwrap ( ) ;
247+ let index_offset = marker_offset + NUMBERED_CODEGEN_UNIT_MARKER . len ( ) ;
248+ extension. push_str ( & codegen_unit_name[ index_offset .. ] ) ;
249+ } else {
250+ extension. push_str ( codegen_unit_name) ;
251+ } ;
252+ }
253+
254+ if !ext. is_empty ( ) {
255+ if !extension. is_empty ( ) {
256+ extension. push_str ( "." ) ;
257+ }
258+
259+ extension. push_str ( ext) ;
216260 }
261+
262+ let path = base. with_extension ( & extension[ ..] ) ;
263+ path
217264 }
218265
219266 pub fn with_extension ( & self , extension : & str ) -> PathBuf {
0 commit comments