Skip to content

Commit 9f6c670

Browse files
committed
Auto merge of #78196 - pietroalbini:shipped-files, r=Mark-Simulacrum
Allow creating a list of files shipped in a release This PR adds the `BUILD_MANIFEST_SHIPPED_FILES_PATH` environment variable to `build-manifest`, which writes a list of all the files referenced in the manifest to the path defined in the variable. The use for this is for `promote-release` to prune files unused files before publishing a release. This PR **does not implement any pruning**, it just adds support for it to be implemented in the future on `promote-release`'s side. r? `@Mark-Simulacrum`
2 parents b9a94c9 + 0ee1e91 commit 9f6c670

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

src/tools/build-manifest/src/main.rs

+25-7
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ macro_rules! t {
186186

187187
struct Builder {
188188
versions: Versions,
189+
shipped_files: HashSet<String>,
189190

190191
input: PathBuf,
191192
output: PathBuf,
@@ -239,6 +240,7 @@ fn main() {
239240

240241
Builder {
241242
versions: Versions::new(&channel, &input).unwrap(),
243+
shipped_files: HashSet::new(),
242244

243245
input,
244246
output,
@@ -259,16 +261,21 @@ impl Builder {
259261
}
260262
let manifest = self.build_manifest();
261263

262-
self.write_channel_files(self.versions.channel(), &manifest);
263-
if self.versions.channel() == "stable" {
264+
let channel = self.versions.channel().to_string();
265+
self.write_channel_files(&channel, &manifest);
266+
if channel == "stable" {
264267
// channel-rust-1.XX.YY.toml
265-
let rust_version = self.versions.rustc_version();
266-
self.write_channel_files(rust_version, &manifest);
268+
let rust_version = self.versions.rustc_version().to_string();
269+
self.write_channel_files(&rust_version, &manifest);
267270

268271
// channel-rust-1.XX.toml
269272
let major_minor = rust_version.split('.').take(2).collect::<Vec<_>>().join(".");
270273
self.write_channel_files(&major_minor, &manifest);
271274
}
275+
276+
if let Some(path) = std::env::var_os("BUILD_MANIFEST_SHIPPED_FILES_PATH") {
277+
self.write_shipped_files(&Path::new(&path));
278+
}
272279
}
273280

274281
/// If a tool does not pass its tests, don't ship it.
@@ -623,7 +630,7 @@ impl Builder {
623630
})
624631
}
625632

626-
fn write_channel_files(&self, channel_name: &str, manifest: &Manifest) {
633+
fn write_channel_files(&mut self, channel_name: &str, manifest: &Manifest) {
627634
self.write(&toml::to_string(&manifest).unwrap(), channel_name, ".toml");
628635
self.write(&manifest.date, channel_name, "-date.txt");
629636
self.write(
@@ -633,14 +640,25 @@ impl Builder {
633640
);
634641
}
635642

636-
fn write(&self, contents: &str, channel_name: &str, suffix: &str) {
637-
let dst = self.output.join(format!("channel-rust-{}{}", channel_name, suffix));
643+
fn write(&mut self, contents: &str, channel_name: &str, suffix: &str) {
644+
let name = format!("channel-rust-{}{}", channel_name, suffix);
645+
self.shipped_files.insert(name.clone());
646+
647+
let dst = self.output.join(name);
638648
t!(fs::write(&dst, contents));
639649
if self.legacy {
640650
self.hash(&dst);
641651
self.sign(&dst);
642652
}
643653
}
654+
655+
fn write_shipped_files(&self, path: &Path) {
656+
let mut files = self.shipped_files.iter().map(|s| s.as_str()).collect::<Vec<_>>();
657+
files.sort();
658+
let content = format!("{}\n", files.join("\n"));
659+
660+
t!(std::fs::write(path, content.as_bytes()));
661+
}
644662
}
645663

646664
fn fetch_hash(path: &Path) -> Result<String, Box<dyn Error>> {

src/tools/build-manifest/src/manifest.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ pub(crate) struct Target {
3737
}
3838

3939
impl Target {
40-
pub(crate) fn from_compressed_tar(builder: &Builder, base_path: &str) -> Self {
40+
pub(crate) fn from_compressed_tar(builder: &mut Builder, base_path: &str) -> Self {
4141
let base_path = builder.input.join(base_path);
42-
let gz = Self::tarball_variant(&base_path, "gz");
43-
let xz = Self::tarball_variant(&base_path, "xz");
42+
let gz = Self::tarball_variant(builder, &base_path, "gz");
43+
let xz = Self::tarball_variant(builder, &base_path, "xz");
4444

4545
if gz.is_none() {
4646
return Self::unavailable();
@@ -59,10 +59,21 @@ impl Target {
5959
}
6060
}
6161

62-
fn tarball_variant(base: &Path, ext: &str) -> Option<PathBuf> {
62+
fn tarball_variant(builder: &mut Builder, base: &Path, ext: &str) -> Option<PathBuf> {
6363
let mut path = base.to_path_buf();
6464
path.set_extension(ext);
65-
if path.is_file() { Some(path) } else { None }
65+
if path.is_file() {
66+
builder.shipped_files.insert(
67+
path.file_name()
68+
.expect("missing filename")
69+
.to_str()
70+
.expect("non-utf-8 filename")
71+
.to_string(),
72+
);
73+
Some(path)
74+
} else {
75+
None
76+
}
6677
}
6778

6879
pub(crate) fn unavailable() -> Self {

0 commit comments

Comments
 (0)