Skip to content

Commit

Permalink
Auto merge of rust-lang#78196 - pietroalbini:shipped-files, r=Mark-Si…
Browse files Browse the repository at this point in the history
…mulacrum

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`
  • Loading branch information
bors committed Oct 26, 2020
2 parents b9a94c9 + 0ee1e91 commit 9f6c670
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
32 changes: 25 additions & 7 deletions src/tools/build-manifest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ macro_rules! t {

struct Builder {
versions: Versions,
shipped_files: HashSet<String>,

input: PathBuf,
output: PathBuf,
Expand Down Expand Up @@ -239,6 +240,7 @@ fn main() {

Builder {
versions: Versions::new(&channel, &input).unwrap(),
shipped_files: HashSet::new(),

input,
output,
Expand All @@ -259,16 +261,21 @@ impl Builder {
}
let manifest = self.build_manifest();

self.write_channel_files(self.versions.channel(), &manifest);
if self.versions.channel() == "stable" {
let channel = self.versions.channel().to_string();
self.write_channel_files(&channel, &manifest);
if channel == "stable" {
// channel-rust-1.XX.YY.toml
let rust_version = self.versions.rustc_version();
self.write_channel_files(rust_version, &manifest);
let rust_version = self.versions.rustc_version().to_string();
self.write_channel_files(&rust_version, &manifest);

// channel-rust-1.XX.toml
let major_minor = rust_version.split('.').take(2).collect::<Vec<_>>().join(".");
self.write_channel_files(&major_minor, &manifest);
}

if let Some(path) = std::env::var_os("BUILD_MANIFEST_SHIPPED_FILES_PATH") {
self.write_shipped_files(&Path::new(&path));
}
}

/// If a tool does not pass its tests, don't ship it.
Expand Down Expand Up @@ -623,7 +630,7 @@ impl Builder {
})
}

fn write_channel_files(&self, channel_name: &str, manifest: &Manifest) {
fn write_channel_files(&mut self, channel_name: &str, manifest: &Manifest) {
self.write(&toml::to_string(&manifest).unwrap(), channel_name, ".toml");
self.write(&manifest.date, channel_name, "-date.txt");
self.write(
Expand All @@ -633,14 +640,25 @@ impl Builder {
);
}

fn write(&self, contents: &str, channel_name: &str, suffix: &str) {
let dst = self.output.join(format!("channel-rust-{}{}", channel_name, suffix));
fn write(&mut self, contents: &str, channel_name: &str, suffix: &str) {
let name = format!("channel-rust-{}{}", channel_name, suffix);
self.shipped_files.insert(name.clone());

let dst = self.output.join(name);
t!(fs::write(&dst, contents));
if self.legacy {
self.hash(&dst);
self.sign(&dst);
}
}

fn write_shipped_files(&self, path: &Path) {
let mut files = self.shipped_files.iter().map(|s| s.as_str()).collect::<Vec<_>>();
files.sort();
let content = format!("{}\n", files.join("\n"));

t!(std::fs::write(path, content.as_bytes()));
}
}

fn fetch_hash(path: &Path) -> Result<String, Box<dyn Error>> {
Expand Down
21 changes: 16 additions & 5 deletions src/tools/build-manifest/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ pub(crate) struct Target {
}

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

if gz.is_none() {
return Self::unavailable();
Expand All @@ -59,10 +59,21 @@ impl Target {
}
}

fn tarball_variant(base: &Path, ext: &str) -> Option<PathBuf> {
fn tarball_variant(builder: &mut Builder, base: &Path, ext: &str) -> Option<PathBuf> {
let mut path = base.to_path_buf();
path.set_extension(ext);
if path.is_file() { Some(path) } else { None }
if path.is_file() {
builder.shipped_files.insert(
path.file_name()
.expect("missing filename")
.to_str()
.expect("non-utf-8 filename")
.to_string(),
);
Some(path)
} else {
None
}
}

pub(crate) fn unavailable() -> Self {
Expand Down

0 comments on commit 9f6c670

Please sign in to comment.