@@ -23,7 +23,7 @@ use std::io::Write;
2323use std:: path:: { PathBuf , Path } ;
2424use std:: process:: Command ;
2525
26- use { Build , Compiler } ;
26+ use { Build , Compiler , Mode } ;
2727use util:: { cp_r, libdir, is_dylib, cp_filtered, copy} ;
2828
2929pub fn package_vers ( build : & Build ) -> & str {
@@ -289,6 +289,50 @@ pub fn rust_src_location(build: &Build) -> PathBuf {
289289 distdir ( build) . join ( & format ! ( "{}.tar.gz" , plain_name) )
290290}
291291
292+ /// Creates a tarball of save-analysis metadata, if available.
293+ pub fn analysis ( build : & Build , compiler : & Compiler , target : & str ) {
294+ println ! ( "Dist analysis" ) ;
295+
296+ if build. config . channel != "nightly" {
297+ println ! ( "Skipping dist-analysis - not on nightly channel" ) ;
298+ return ;
299+ }
300+ if compiler. stage != 2 {
301+ return
302+ }
303+
304+ let name = format ! ( "rust-analysis-{}" , package_vers( build) ) ;
305+ let image = tmpdir ( build) . join ( format ! ( "{}-{}-image" , name, target) ) ;
306+
307+ let src = build. stage_out ( compiler, Mode :: Libstd ) . join ( target) . join ( "release" ) . join ( "deps" ) ;
308+
309+ let image_src = src. join ( "save-analysis" ) ;
310+ let dst = image. join ( "lib/rustlib" ) . join ( target) . join ( "analysis" ) ;
311+ t ! ( fs:: create_dir_all( & dst) ) ;
312+ cp_r ( & image_src, & dst) ;
313+
314+ let mut cmd = Command :: new ( "sh" ) ;
315+ cmd. arg ( sanitize_sh ( & build. src . join ( "src/rust-installer/gen-installer.sh" ) ) )
316+ . arg ( "--product-name=Rust" )
317+ . arg ( "--rel-manifest-dir=rustlib" )
318+ . arg ( "--success-message=save-analysis-saved." )
319+ . arg ( format ! ( "--image-dir={}" , sanitize_sh( & image) ) )
320+ . arg ( format ! ( "--work-dir={}" , sanitize_sh( & tmpdir( build) ) ) )
321+ . arg ( format ! ( "--output-dir={}" , sanitize_sh( & distdir( build) ) ) )
322+ . arg ( format ! ( "--package-name={}-{}" , name, target) )
323+ . arg ( format ! ( "--component-name=rust-analysis-{}" , target) )
324+ . arg ( "--legacy-manifest-dirs=rustlib,cargo" ) ;
325+ build. run ( & mut cmd) ;
326+ t ! ( fs:: remove_dir_all( & image) ) ;
327+
328+ // Create plain source tarball
329+ let mut cmd = Command :: new ( "tar" ) ;
330+ cmd. arg ( "-czf" ) . arg ( sanitize_sh ( & distdir ( build) . join ( & format ! ( "{}.tar.gz" , name) ) ) )
331+ . arg ( "analysis" )
332+ . current_dir ( & src) ;
333+ build. run ( & mut cmd) ;
334+ }
335+
292336/// Creates the `rust-src` installer component and the plain source tarball
293337pub fn rust_src ( build : & Build ) {
294338 println ! ( "Dist src" ) ;
0 commit comments