Skip to content

Allow creating a list of files shipped in a release #78196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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