1
Fork 0

build-manifest: allow creating a list of files shipped in a release

This commit is contained in:
Pietro Albini 2020-10-21 19:29:07 +02:00
parent 9832374f6e
commit 0ee1e91c11
No known key found for this signature in database
GPG key ID: 3E06ABE80BAAF19C
2 changed files with 41 additions and 12 deletions

View file

@ -186,6 +186,7 @@ macro_rules! t {
struct Builder { struct Builder {
versions: Versions, versions: Versions,
shipped_files: HashSet<String>,
input: PathBuf, input: PathBuf,
output: PathBuf, output: PathBuf,
@ -239,6 +240,7 @@ fn main() {
Builder { Builder {
versions: Versions::new(&channel, &input).unwrap(), versions: Versions::new(&channel, &input).unwrap(),
shipped_files: HashSet::new(),
input, input,
output, output,
@ -259,16 +261,21 @@ impl Builder {
} }
let manifest = self.build_manifest(); let manifest = self.build_manifest();
self.write_channel_files(self.versions.channel(), &manifest); let channel = self.versions.channel().to_string();
if self.versions.channel() == "stable" { self.write_channel_files(&channel, &manifest);
if channel == "stable" {
// channel-rust-1.XX.YY.toml // channel-rust-1.XX.YY.toml
let rust_version = self.versions.rustc_version(); let rust_version = self.versions.rustc_version().to_string();
self.write_channel_files(rust_version, &manifest); self.write_channel_files(&rust_version, &manifest);
// channel-rust-1.XX.toml // channel-rust-1.XX.toml
let major_minor = rust_version.split('.').take(2).collect::<Vec<_>>().join("."); let major_minor = rust_version.split('.').take(2).collect::<Vec<_>>().join(".");
self.write_channel_files(&major_minor, &manifest); 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. /// If a tool does not pass its tests, don't ship it.
@ -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(&toml::to_string(&manifest).unwrap(), channel_name, ".toml");
self.write(&manifest.date, channel_name, "-date.txt"); self.write(&manifest.date, channel_name, "-date.txt");
self.write( self.write(
@ -633,14 +640,25 @@ impl Builder {
); );
} }
fn write(&self, contents: &str, channel_name: &str, suffix: &str) { fn write(&mut self, contents: &str, channel_name: &str, suffix: &str) {
let dst = self.output.join(format!("channel-rust-{}{}", channel_name, suffix)); 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)); t!(fs::write(&dst, contents));
if self.legacy { if self.legacy {
self.hash(&dst); self.hash(&dst);
self.sign(&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>> { fn fetch_hash(path: &Path) -> Result<String, Box<dyn Error>> {

View file

@ -37,10 +37,10 @@ pub(crate) struct Target {
} }
impl 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 base_path = builder.input.join(base_path);
let gz = Self::tarball_variant(&base_path, "gz"); let gz = Self::tarball_variant(builder, &base_path, "gz");
let xz = Self::tarball_variant(&base_path, "xz"); let xz = Self::tarball_variant(builder, &base_path, "xz");
if gz.is_none() { if gz.is_none() {
return Self::unavailable(); return Self::unavailable();
@ -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(); let mut path = base.to_path_buf();
path.set_extension(ext); 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 { pub(crate) fn unavailable() -> Self {