Skip to content

Store dist manifest in JSON to improve load performance #4344

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ rustls-platform-verifier = { version = "0.5", optional = true }
same-file = "1"
semver = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
sha2 = "0.10"
sharded-slab = "0.1.1"
strsim = "0.11"
Expand Down
66 changes: 47 additions & 19 deletions src/dist/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,34 @@ mod component_target {
}
}

fn init_and_validate(mut manifest: Manifest) -> Result<Manifest> {
for (from, to) in manifest.renames.iter() {
manifest.reverse_renames.insert(to.to.clone(), from.clone());
}

manifest.validate()?;
Ok(manifest)
}

impl Manifest {
pub fn parse(data: &str) -> Result<Self> {
let mut manifest = toml::from_str::<Self>(data).context("error parsing manifest")?;
for (from, to) in manifest.renames.iter() {
manifest.reverse_renames.insert(to.to.clone(), from.clone());
}
pub fn parse_toml(data: &str) -> Result<Self> {
let manifest = toml::from_str::<Self>(data).context("error parsing manifest")?;
init_and_validate(manifest)
}

manifest.validate()?;
Ok(manifest)
pub fn parse_json(data: &str) -> Result<Self> {
let manifest = serde_json::from_str::<Self>(data).context("error parsing manifest")?;
init_and_validate(manifest)
}

pub fn stringify(self) -> anyhow::Result<String> {
pub fn stringify_to_toml(self) -> anyhow::Result<String> {
Ok(toml::to_string(&self)?)
}

pub fn stringify_to_json(self) -> anyhow::Result<String> {
Ok(serde_json::to_string(&self)?)
}

pub fn get_package(&self, name: &str) -> Result<&Package> {
self.packages
.get(name)
Expand Down Expand Up @@ -626,15 +639,17 @@ mod tests {

// Example manifest from https://public.etherpad-mozilla.org/p/Rust-infra-work-week
static EXAMPLE: &str = include_str!("manifest/tests/channel-rust-nightly-example.toml");
static EXAMPLE_JSON: &str = include_str!("manifest/tests/channel-rust-nightly-example.json");
// From brson's live build-rust-manifest.py script
static EXAMPLE2: &str = include_str!("manifest/tests/channel-rust-nightly-example2.toml");
static EXAMPLE2_JSON: &str = include_str!("manifest/tests/channel-rust-nightly-example.json");

#[test]
fn parse_smoke_test() {
let x86_64_unknown_linux_gnu = TargetTriple::new("x86_64-unknown-linux-gnu");
let x86_64_unknown_linux_musl = TargetTriple::new("x86_64-unknown-linux-musl");

let pkg = Manifest::parse(EXAMPLE).unwrap();
let pkg = Manifest::parse_toml(EXAMPLE).unwrap();

pkg.get_package("rust").unwrap();
pkg.get_package("rustc").unwrap();
Expand Down Expand Up @@ -669,23 +684,36 @@ mod tests {

#[test]
fn renames() {
let manifest = Manifest::parse(EXAMPLE2).unwrap();
let manifest = Manifest::parse_toml(EXAMPLE2).unwrap();
assert_eq!(1, manifest.renames.len());
assert_eq!(manifest.renames["cargo-old"].to, "cargo");
assert_eq!(1, manifest.reverse_renames.len());
assert_eq!(manifest.reverse_renames["cargo"], "cargo-old");
}

#[test]
fn parse_round_trip() {
let original = Manifest::parse(EXAMPLE).unwrap();
let serialized = original.clone().stringify().unwrap();
let new = Manifest::parse(&serialized).unwrap();
fn parse_round_trip_toml() {
let original = Manifest::parse_toml(EXAMPLE).unwrap();
let serialized = original.clone().stringify_to_toml().unwrap();
let new = Manifest::parse_toml(&serialized).unwrap();
assert_eq!(original, new);

let original = Manifest::parse_toml(EXAMPLE2).unwrap();
let serialized = original.clone().stringify_to_toml().unwrap();
let new = Manifest::parse_toml(&serialized).unwrap();
assert_eq!(original, new);
}

#[test]
fn parse_round_trip_json() {
let original = Manifest::parse_json(EXAMPLE_JSON).unwrap();
let serialized = original.clone().stringify_to_json().unwrap();
let new = Manifest::parse_json(&serialized).unwrap();
assert_eq!(original, new);

let original = Manifest::parse(EXAMPLE2).unwrap();
let serialized = original.clone().stringify().unwrap();
let new = Manifest::parse(&serialized).unwrap();
let original = Manifest::parse_json(EXAMPLE2_JSON).unwrap();
let serialized = original.clone().stringify_to_json().unwrap();
let new = Manifest::parse_json(&serialized).unwrap();
assert_eq!(original, new);
}

Expand Down Expand Up @@ -714,7 +742,7 @@ date = "2015-10-10"
hash = "..."
"#;

let err = Manifest::parse(manifest).unwrap_err();
let err = Manifest::parse_toml(manifest).unwrap_err();

match err.downcast::<RustupError>().unwrap() {
RustupError::MissingPackageForComponent(_) => {}
Expand All @@ -727,6 +755,6 @@ date = "2015-10-10"
fn manifest_can_contain_unknown_targets() {
let manifest = EXAMPLE.replace("x86_64-unknown-linux-gnu", "mycpu-myvendor-myos");

assert!(Manifest::parse(&manifest).is_ok());
assert!(Manifest::parse_toml(&manifest).is_ok());
}
}
142 changes: 142 additions & 0 deletions src/dist/manifest/tests/channel-rust-nightly-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"manifest-version": "2",
"date": "2015-10-10",
"pkg": {
"rust-docs": {
"version": "rustc 1.3.0 (9a92aaf19 2015-09-15)",
"target": {
"x86_64-unknown-linux-gnu": {
"available": true,
"url": "example.com",
"hash": "...",
"xz_url": null,
"xz_hash": null,
"zst_url": null,
"zst_hash": null,
"components": [],
"extensions": []
}
}
},
"cargo": {
"version": "cargo 0.4.0-nightly (553b363 2015-08-03)",
"target": {
"x86_64-unknown-linux-gnu": {
"available": true,
"url": "example.com",
"hash": "...",
"xz_url": null,
"xz_hash": null,
"zst_url": null,
"zst_hash": null,
"components": [],
"extensions": []
}
}
},
"rustc": {
"version": "rustc 1.3.0 (9a92aaf19 2015-09-15)",
"target": {
"x86_64-unknown-linux-gnu": {
"available": true,
"url": "example.com",
"hash": "...",
"xz_url": null,
"xz_hash": null,
"zst_url": null,
"zst_hash": null,
"components": [],
"extensions": []
}
}
},
"rust": {
"version": "rustc 1.3.0 (9a92aaf19 2015-09-15)",
"target": {
"x86_64-unknown-linux-gnu": {
"available": true,
"url": "example.com",
"hash": "...",
"xz_url": null,
"xz_hash": null,
"zst_url": null,
"zst_hash": null,
"components": [
{
"pkg": "rustc",
"target": "x86_64-unknown-linux-gnu",
"is_extension": false
},
{
"pkg": "rust-docs",
"target": "x86_64-unknown-linux-gnu",
"is_extension": false
},
{
"pkg": "cargo",
"target": "x86_64-unknown-linux-gnu",
"is_extension": false
},
{
"pkg": "rust-std",
"target": "x86_64-unknown-linux-gnu",
"is_extension": false
}
],
"extensions": [
{
"pkg": "rust-std",
"target": "x86_64-unknown-linux-musl",
"is_extension": true
},
{
"pkg": "rust-std",
"target": "i686-unknown-linux-gnu",
"is_extension": true
}
]
}
}
},
"rust-std": {
"version": "rustc 1.3.0 (9a92aaf19 2015-09-15)",
"target": {
"i686-unknown-linux-gnu": {
"available": true,
"url": "example.com",
"hash": "...",
"xz_url": null,
"xz_hash": null,
"zst_url": null,
"zst_hash": null,
"components": [],
"extensions": []
},
"x86_64-unknown-linux-gnu": {
"available": true,
"url": "example.com",
"hash": "...",
"xz_url": null,
"xz_hash": null,
"zst_url": null,
"zst_hash": null,
"components": [],
"extensions": []
},
"x86_64-unknown-linux-musl": {
"available": true,
"url": "example.com",
"hash": "...",
"xz_url": null,
"xz_hash": null,
"zst_url": null,
"zst_hash": null,
"components": [],
"extensions": []
}
}
}
},
"renames": {},
"profiles": {}
}
Loading
Loading