Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #15 from calebcartwright/librustc_parse
Browse files Browse the repository at this point in the history
support publishing librustc_parse
  • Loading branch information
alexcrichton authored Jan 8, 2020
2 parents d283483 + 177d0b5 commit 7ad1fdd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# rustc-auto-publish

Repository for automatically publishing the `rustc-ap-syntax` crate once a day.
Repository for automatically publishing the `rustc-ap-syntax` and `rustc-ap-rustc_parse` crates once a week.
82 changes: 61 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,25 @@ fn main() {
download_src(&tmpdir, &commit);
}

println!("learning about the dependency graph");
let metadata = Command::new("cargo")
.arg("+nightly")
.current_dir(dst.join("src/libsyntax"))
.arg("metadata")
.arg("--format-version=1")
.output()
.expect("failed to execute cargo");
if !metadata.status.success() {
panic!("failed to run rustc: {:?}", metadata);
}
let output = str::from_utf8(&metadata.stdout).unwrap();
let output: Metadata = serde_json::from_str(output).unwrap();

let syntax = output
.packages
.iter()
.find(|p| p.name == "syntax")
.expect("failed to find libsyntax");
let target_crates = vec![
RustcApCrate {
name: "syntax",
dir: "src/libsyntax",
},
RustcApCrate {
name: "rustc_parse",
dir: "src/librustc_parse",
},
];

println!("learning about the dependency graph");
let rustc_packages = get_rustc_packages(&target_crates, &dst);
let mut crates = Vec::new();
fill(&output, &syntax, &mut crates, &mut HashSet::new());
let mut seen = HashSet::new();

for RustcPackageInfo { package, metadata } in rustc_packages.iter() {
fill(&metadata, &package, &mut crates, &mut seen);
}

let version_to_publish = get_version_to_publish(&crates);
println!("going to publish {}", version_to_publish);
Expand Down Expand Up @@ -127,6 +124,39 @@ fn download_src(dst: &Path, commit: &str) {
File::create(&root.join(".ok")).unwrap();
}

fn get_rustc_packages(target_crates: &[RustcApCrate], dst: &Path) -> Vec<RustcPackageInfo> {
let mut packages = Vec::new();

for RustcApCrate { name, dir } in target_crates.iter() {
let metadata = Command::new("cargo")
.arg("+nightly")
.current_dir(dst.join(dir))
.arg("metadata")
.arg("--format-version=1")
.output()
.expect("failed to execute cargo");
if !metadata.status.success() {
panic!("failed to run rustc: {:?}", metadata);
}
let output = str::from_utf8(&metadata.stdout).unwrap();
let output: Metadata = serde_json::from_str(output).unwrap();

let rustc_package = output
.packages
.iter()
.find(|p| p.name == *name)
.expect(&format!("failed to find {}", &name))
.clone();

packages.push(RustcPackageInfo {
package: rustc_package,
metadata: output,
})
}

packages
}

fn fill<'a>(
output: &'a Metadata,
pkg: &'a Package,
Expand Down Expand Up @@ -157,7 +187,7 @@ struct Metadata {
resolve: Resolve,
}

#[derive(Deserialize)]
#[derive(Deserialize, Clone)]
struct Package {
id: String,
name: String,
Expand All @@ -176,6 +206,16 @@ struct ResolveNode {
dependencies: Vec<String>,
}

struct RustcApCrate<'a> {
name: &'a str,
dir: &'a str,
}

struct RustcPackageInfo {
package: Package,
metadata: Metadata,
}

fn get_version_to_publish(crates: &[&Package]) -> semver::Version {
let mut cur = crates.iter().map(|p| get_current_version(p)).max().unwrap();
cur.major += 1;
Expand Down

0 comments on commit 7ad1fdd

Please sign in to comment.