@@ -1210,6 +1210,8 @@ impl Step for Src {
12101210 }
12111211}
12121212
1213+ /// Tarball for people who want to build rustc and other components from the source.
1214+ /// Does not contain GPL code for licensing reasons.
12131215#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
12141216pub struct PlainSourceTarball ;
12151217
@@ -1232,51 +1234,18 @@ impl Step for PlainSourceTarball {
12321234
12331235 /// Creates the plain source tarball
12341236 fn run ( self , builder : & Builder < ' _ > ) -> GeneratedTarball {
1235- // NOTE: This is a strange component in a lot of ways. It uses `src` as the target, which
1236- // means neither rustup nor rustup-toolchain-install-master know how to download it.
1237- // It also contains symbolic links, unlike other any other dist tarball.
1238- // It's used for distros building rustc from source in a pre-vendored environment.
1239- let mut tarball = Tarball :: new ( builder, "rustc" , "src" ) ;
1240- tarball. permit_symlinks ( true ) ;
1241- let plain_dst_src = tarball. image_dir ( ) ;
1242-
1243- // This is the set of root paths which will become part of the source package
1244- let src_files = [
1245- // tidy-alphabetical-start
1246- ".gitmodules" ,
1247- "CONTRIBUTING.md" ,
1248- "COPYRIGHT" ,
1249- "Cargo.lock" ,
1250- "Cargo.toml" ,
1251- "LICENSE-APACHE" ,
1252- "LICENSE-MIT" ,
1253- "README.md" ,
1254- "RELEASES.md" ,
1255- "REUSE.toml" ,
1256- "bootstrap.example.toml" ,
1257- "configure" ,
1258- "license-metadata.json" ,
1259- "package.json" ,
1260- "x" ,
1261- "x.ps1" ,
1262- "x.py" ,
1263- "yarn.lock" ,
1264- // tidy-alphabetical-end
1265- ] ;
1266- let src_dirs = [ "src" , "compiler" , "library" , "tests" , "LICENSES" ] ;
1267-
1268- copy_src_dirs (
1237+ let tarball = prepare_source_tarball (
12691238 builder,
1270- & builder. src ,
1271- & src_dirs,
1239+ "src" ,
12721240 & [
12731241 // We don't currently use the GCC source code for building any official components,
12741242 // it is very big, and has unclear licensing implications due to being GPL licensed.
12751243 // We thus exclude it from the source tarball from now.
12761244 "src/gcc" ,
12771245 ] ,
1278- plain_dst_src,
12791246 ) ;
1247+
1248+ let plain_dst_src = tarball. image_dir ( ) ;
12801249 // We keep something in src/gcc because it is a registered submodule,
12811250 // and if it misses completely it can cause issues elsewhere
12821251 // (see https://github.com/rust-lang/rust/issues/137332).
@@ -1288,74 +1257,104 @@ impl Step for PlainSourceTarball {
12881257 "The GCC source code is not included due to unclear licensing implications\n "
12891258 ) ) ;
12901259 }
1260+ tarball. bare ( )
1261+ }
1262+ }
12911263
1292- // Copy the files normally
1293- for item in & src_files {
1294- builder. copy_link (
1295- & builder. src . join ( item) ,
1296- & plain_dst_src. join ( item) ,
1297- FileType :: Regular ,
1298- ) ;
1299- }
1264+ fn prepare_source_tarball ( builder : & Builder < ' _ > , name : & str , exclude_dirs : & [ & str ] ) -> Tarball {
1265+ // NOTE: This is a strange component in a lot of ways. It uses `src` as the target, which
1266+ // means neither rustup nor rustup-toolchain-install-master know how to download it.
1267+ // It also contains symbolic links, unlike other any other dist tarball.
1268+ // It's used for distros building rustc from source in a pre-vendored environment.
1269+ let mut tarball = Tarball :: new ( builder, "rustc" , name) ;
1270+ tarball. permit_symlinks ( true ) ;
1271+ let plain_dst_src = tarball. image_dir ( ) ;
1272+
1273+ // This is the set of root paths which will become part of the source package
1274+ let src_files = [
1275+ // tidy-alphabetical-start
1276+ ".gitmodules" ,
1277+ "CONTRIBUTING.md" ,
1278+ "COPYRIGHT" ,
1279+ "Cargo.lock" ,
1280+ "Cargo.toml" ,
1281+ "LICENSE-APACHE" ,
1282+ "LICENSE-MIT" ,
1283+ "README.md" ,
1284+ "RELEASES.md" ,
1285+ "REUSE.toml" ,
1286+ "bootstrap.example.toml" ,
1287+ "configure" ,
1288+ "license-metadata.json" ,
1289+ "package.json" ,
1290+ "x" ,
1291+ "x.ps1" ,
1292+ "x.py" ,
1293+ "yarn.lock" ,
1294+ // tidy-alphabetical-end
1295+ ] ;
1296+ let src_dirs = [ "src" , "compiler" , "library" , "tests" , "LICENSES" ] ;
13001297
1301- // Create the version file
1302- builder. create ( & plain_dst_src. join ( "version" ) , & builder. rust_version ( ) ) ;
1298+ copy_src_dirs ( builder, & builder. src , & src_dirs, exclude_dirs, plain_dst_src) ;
13031299
1304- // Create the files containing git info, to ensure --version outputs the same.
1305- let write_git_info = |info : Option < & Info > , path : & Path | {
1306- if let Some ( info) = info {
1307- t ! ( std:: fs:: create_dir_all( path) ) ;
1308- channel:: write_commit_hash_file ( path, & info. sha ) ;
1309- channel:: write_commit_info_file ( path, info) ;
1310- }
1311- } ;
1312- write_git_info ( builder. rust_info ( ) . info ( ) , plain_dst_src) ;
1313- write_git_info ( builder. cargo_info . info ( ) , & plain_dst_src. join ( "./src/tools/cargo" ) ) ;
1314-
1315- if builder. config . dist_vendor {
1316- builder. require_and_update_all_submodules ( ) ;
1317-
1318- // Vendor packages that are required by opt-dist to collect PGO profiles.
1319- let pkgs_for_pgo_training = build_helper:: LLVM_PGO_CRATES
1320- . iter ( )
1321- . chain ( build_helper:: RUSTC_PGO_CRATES )
1322- . map ( |pkg| {
1323- let mut manifest_path =
1324- builder. src . join ( "./src/tools/rustc-perf/collector/compile-benchmarks" ) ;
1325- manifest_path. push ( pkg) ;
1326- manifest_path. push ( "Cargo.toml" ) ;
1327- manifest_path
1328- } ) ;
1329-
1330- // Vendor all Cargo dependencies
1331- let vendor = builder. ensure ( Vendor {
1332- sync_args : pkgs_for_pgo_training. collect ( ) ,
1333- versioned_dirs : true ,
1334- root_dir : plain_dst_src. into ( ) ,
1335- output_dir : VENDOR_DIR . into ( ) ,
1336- } ) ;
1300+ // Copy the files normally
1301+ for item in & src_files {
1302+ builder. copy_link ( & builder. src . join ( item) , & plain_dst_src. join ( item) , FileType :: Regular ) ;
1303+ }
13371304
1338- let cargo_config_dir = plain_dst_src. join ( ".cargo" ) ;
1339- builder. create_dir ( & cargo_config_dir) ;
1340- builder. create ( & cargo_config_dir. join ( "config.toml" ) , & vendor. config ) ;
1341- }
1305+ // Create the version file
1306+ builder. create ( & plain_dst_src. join ( "version" ) , & builder. rust_version ( ) ) ;
13421307
1343- // Delete extraneous directories
1344- // FIXME: if we're managed by git, we should probably instead ask git if the given path
1345- // is managed by it?
1346- for entry in walkdir:: WalkDir :: new ( tarball. image_dir ( ) )
1347- . follow_links ( true )
1348- . into_iter ( )
1349- . filter_map ( |e| e. ok ( ) )
1350- {
1351- if entry. path ( ) . is_dir ( ) && entry. path ( ) . file_name ( ) == Some ( OsStr :: new ( "__pycache__" ) )
1352- {
1353- t ! ( fs:: remove_dir_all( entry. path( ) ) ) ;
1354- }
1308+ // Create the files containing git info, to ensure --version outputs the same.
1309+ let write_git_info = |info : Option < & Info > , path : & Path | {
1310+ if let Some ( info) = info {
1311+ t ! ( std:: fs:: create_dir_all( path) ) ;
1312+ channel:: write_commit_hash_file ( path, & info. sha ) ;
1313+ channel:: write_commit_info_file ( path, info) ;
13551314 }
1315+ } ;
1316+ write_git_info ( builder. rust_info ( ) . info ( ) , plain_dst_src) ;
1317+ write_git_info ( builder. cargo_info . info ( ) , & plain_dst_src. join ( "./src/tools/cargo" ) ) ;
1318+
1319+ if builder. config . dist_vendor {
1320+ builder. require_and_update_all_submodules ( ) ;
1321+
1322+ // Vendor packages that are required by opt-dist to collect PGO profiles.
1323+ let pkgs_for_pgo_training =
1324+ build_helper:: LLVM_PGO_CRATES . iter ( ) . chain ( build_helper:: RUSTC_PGO_CRATES ) . map ( |pkg| {
1325+ let mut manifest_path =
1326+ builder. src . join ( "./src/tools/rustc-perf/collector/compile-benchmarks" ) ;
1327+ manifest_path. push ( pkg) ;
1328+ manifest_path. push ( "Cargo.toml" ) ;
1329+ manifest_path
1330+ } ) ;
13561331
1357- tarball. bare ( )
1332+ // Vendor all Cargo dependencies
1333+ let vendor = builder. ensure ( Vendor {
1334+ sync_args : pkgs_for_pgo_training. collect ( ) ,
1335+ versioned_dirs : true ,
1336+ root_dir : plain_dst_src. into ( ) ,
1337+ output_dir : VENDOR_DIR . into ( ) ,
1338+ } ) ;
1339+
1340+ let cargo_config_dir = plain_dst_src. join ( ".cargo" ) ;
1341+ builder. create_dir ( & cargo_config_dir) ;
1342+ builder. create ( & cargo_config_dir. join ( "config.toml" ) , & vendor. config ) ;
1343+ }
1344+
1345+ // Delete extraneous directories
1346+ // FIXME: if we're managed by git, we should probably instead ask git if the given path
1347+ // is managed by it?
1348+ for entry in walkdir:: WalkDir :: new ( tarball. image_dir ( ) )
1349+ . follow_links ( true )
1350+ . into_iter ( )
1351+ . filter_map ( |e| e. ok ( ) )
1352+ {
1353+ if entry. path ( ) . is_dir ( ) && entry. path ( ) . file_name ( ) == Some ( OsStr :: new ( "__pycache__" ) ) {
1354+ t ! ( fs:: remove_dir_all( entry. path( ) ) ) ;
1355+ }
13581356 }
1357+ tarball
13591358}
13601359
13611360#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
0 commit comments