Skip to content

Commit 32f3ddb

Browse files
authored
Rollup merge of rust-lang#110436 - Mark-Simulacrum:support-xz-version, r=pietroalbini
Support loading version information from xz tarballs This is intended to allow us to move recompression from xz (produced in CI) to gz after an initial manifest run, which produces a list of actually required artifacts. The rest are then deleted, which means that we can avoid recompressing them, saving a bunch of time. This is essentially untested and more might be needed, will run a patched promote-release against try artifacts from this PR. If we do go ahead with this we'll either need to backport this patch to beta/stable, wait for it to propagate, or temporarily recompress to gzip but not xz tarballs (or similar). r? `@pietroalbini`
2 parents 068807a + e40a446 commit 32f3ddb

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

Cargo.lock

+5-4
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ dependencies = [
297297
"sha2",
298298
"tar",
299299
"toml",
300+
"xz2",
300301
]
301302

302303
[[package]]
@@ -2060,9 +2061,9 @@ dependencies = [
20602061

20612062
[[package]]
20622063
name = "lzma-sys"
2063-
version = "0.1.16"
2064+
version = "0.1.20"
20642065
source = "registry+https://github.com/rust-lang/crates.io-index"
2065-
checksum = "f24f76ec44a8ac23a31915d6e326bca17ce88da03096f1ff194925dc714dac99"
2066+
checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27"
20662067
dependencies = [
20672068
"cc",
20682069
"libc",
@@ -5658,9 +5659,9 @@ dependencies = [
56585659

56595660
[[package]]
56605661
name = "xz2"
5661-
version = "0.1.6"
5662+
version = "0.1.7"
56625663
source = "registry+https://github.com/rust-lang/crates.io-index"
5663-
checksum = "c179869f34fc7c01830d3ce7ea2086bc3a07e0d35289b667d0a8bf910258926c"
5664+
checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2"
56645665
dependencies = [
56655666
"lzma-sys",
56665667
]

src/tools/build-manifest/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ serde = { version = "1.0", features = ["derive"] }
99
serde_json = "1.0"
1010
anyhow = "1.0.32"
1111
flate2 = "1.0.16"
12+
xz2 = "0.1.7"
1213
tar = "0.4.29"
1314
sha2 = "0.10.1"
1415
rayon = "1.5.1"

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

+25-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::fs::File;
55
use std::io::Read;
66
use std::path::{Path, PathBuf};
77
use tar::Archive;
8+
use xz2::read::XzDecoder;
89

910
const DEFAULT_TARGET: &str = "x86_64-unknown-linux-gnu";
1011

@@ -175,9 +176,23 @@ impl Versions {
175176
}
176177

177178
fn load_version_from_tarball(&mut self, package: &PkgType) -> Result<VersionInfo, Error> {
178-
let tarball_name = self.tarball_name(package, DEFAULT_TARGET)?;
179-
let tarball = self.dist_path.join(tarball_name);
179+
for ext in ["xz", "gz"] {
180+
let info =
181+
self.load_version_from_tarball_inner(&self.dist_path.join(self.archive_name(
182+
package,
183+
DEFAULT_TARGET,
184+
&format!("tar.{}", ext),
185+
)?))?;
186+
if info.present {
187+
return Ok(info);
188+
}
189+
}
190+
191+
// If neither tarball is present, we fallback to returning the non-present info.
192+
Ok(VersionInfo::default())
193+
}
180194

195+
fn load_version_from_tarball_inner(&mut self, tarball: &Path) -> Result<VersionInfo, Error> {
181196
let file = match File::open(&tarball) {
182197
Ok(file) => file,
183198
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
@@ -187,7 +202,14 @@ impl Versions {
187202
}
188203
Err(err) => return Err(err.into()),
189204
};
190-
let mut tar = Archive::new(GzDecoder::new(file));
205+
let mut tar: Archive<Box<dyn std::io::Read>> =
206+
Archive::new(if tarball.extension().map_or(false, |e| e == "gz") {
207+
Box::new(GzDecoder::new(file))
208+
} else if tarball.extension().map_or(false, |e| e == "xz") {
209+
Box::new(XzDecoder::new(file))
210+
} else {
211+
unimplemented!("tarball extension not recognized: {}", tarball.display())
212+
});
191213

192214
let mut version = None;
193215
let mut git_commit = None;

0 commit comments

Comments
 (0)