diff options
| author | Mark Mansi <markm@cs.wisc.edu> | 2018-02-23 18:01:51 -0600 |
|---|---|---|
| committer | Mark Mansi <markm@cs.wisc.edu> | 2018-03-05 14:43:44 -0600 |
| commit | 3570b9df6ae615691bfe296b5af816332a25299b (patch) | |
| tree | 9c217d6a5ccd2753a24c473ac8fe2f074befd0ff | |
| parent | d62621839a64352e41f8908021cfe8e7d91f064a (diff) | |
| download | rust-3570b9df6ae615691bfe296b5af816332a25299b.tar.gz rust-3570b9df6ae615691bfe296b5af816332a25299b.zip | |
MAKE IT FAILgit statusgit status
| -rw-r--r-- | src/tools/tidy/src/deps.rs | 72 | ||||
| -rw-r--r-- | src/tools/tidy/src/main.rs | 1 |
2 files changed, 53 insertions, 20 deletions
diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 30eadd9ec9d..a2d42a00c36 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -10,10 +10,10 @@ //! Check license of third-party deps by inspecting src/vendor +use std::collections::HashSet; use std::fs::File; use std::io::Read; use std::path::Path; - use std::process::Command; use serde_json; @@ -56,22 +56,40 @@ static WHITELIST: &'static [(&'static str, &'static str)] = &[]; #[derive(Deserialize)] struct Output { packages: Vec<Package>, - _resolve: String, + + // Not used, but needed to not confuse serde :P + #[allow(dead_code)] resolve: Resolve, } #[derive(Deserialize)] struct Package { - _id: String, name: String, version: String, - _source: Option<String>, - _manifest_path: String, + + // Not used, but needed to not confuse serde :P + #[allow(dead_code)] id: String, + #[allow(dead_code)] source: Option<String>, + #[allow(dead_code)] manifest_path: String, +} + +// Not used, but needed to not confuse serde :P +#[allow(dead_code)] +#[derive(Deserialize)] +struct Resolve { + nodes: Vec<ResolveNode>, +} + +// Not used, but needed to not confuse serde :P +#[allow(dead_code)] +#[derive(Deserialize)] +struct ResolveNode { + id: String, + dependencies: Vec<String>, } /// Checks the dependency at the given path. Changes `bad` to `true` if a check failed. /// -/// Specifically, this checks that the license is correct and that the dependencies are on the -/// whitelist. +/// Specifically, this checks that the license is correct. pub fn check(path: &Path, bad: &mut bool) { // Check licences let path = path.join("vendor"); @@ -95,21 +113,35 @@ pub fn check(path: &Path, bad: &mut bool) { *bad = *bad || !check_license(&toml); } assert!(saw_dir, "no vendored source"); +} +/// Checks the dependency at the given path. Changes `bad` to `true` if a check failed. +/// +/// Specifically, this checks that the dependencies are on the whitelist. +pub fn check_whitelist(path: &Path, bad: &mut bool) { // Check dependencies - let deps = get_deps(&path); - *bad = *bad - || deps.iter().any( - |&Package { - ref name, - ref version, - .. - }| { - WHITELIST - .iter() - .all(|&(wname, wversion)| name != wname || version != wversion) - }, - ); + let deps: HashSet<_> = get_deps(&path) + .into_iter() + .map(|Package { name, version, .. }| (name, version)) + .collect(); + let whitelist: HashSet<(String, String)> = WHITELIST + .iter() + .map(|&(n, v)| (n.to_owned(), v.to_owned())) + .collect(); + + // Dependencies not in the whitelist + let mut unapproved: Vec<_> = deps.difference(&whitelist).collect(); + + // For ease of reading + unapproved.sort(); + + if unapproved.len() > 0 { + println!("Dependencies not on the whitelist:"); + for dep in unapproved { + println!("* {} {}", dep.0, dep.1); // name version + } + *bad = true; + } } fn check_license(path: &Path) -> bool { diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs index f6640c902bc..f64536e2f59 100644 --- a/src/tools/tidy/src/main.rs +++ b/src/tools/tidy/src/main.rs @@ -41,6 +41,7 @@ fn main() { if !args.iter().any(|s| *s == "--no-vendor") { deps::check(&path, &mut bad); } + deps::check_whitelist(&path, &mut bad); if bad { eprintln!("some tidy checks failed"); |
