MAKE IT FAILgit statusgit status
This commit is contained in:
parent
d62621839a
commit
3570b9df6a
@ -10,10 +10,10 @@
|
|||||||
|
|
||||||
//! Check license of third-party deps by inspecting src/vendor
|
//! Check license of third-party deps by inspecting src/vendor
|
||||||
|
|
||||||
|
use std::collections::HashSet;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
use serde_json;
|
use serde_json;
|
||||||
@ -56,22 +56,40 @@ static WHITELIST: &'static [(&'static str, &'static str)] = &[];
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Output {
|
struct Output {
|
||||||
packages: Vec<Package>,
|
packages: Vec<Package>,
|
||||||
_resolve: String,
|
|
||||||
|
// Not used, but needed to not confuse serde :P
|
||||||
|
#[allow(dead_code)] resolve: Resolve,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Package {
|
struct Package {
|
||||||
_id: String,
|
|
||||||
name: String,
|
name: String,
|
||||||
version: 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.
|
/// 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
|
/// Specifically, this checks that the license is correct.
|
||||||
/// whitelist.
|
|
||||||
pub fn check(path: &Path, bad: &mut bool) {
|
pub fn check(path: &Path, bad: &mut bool) {
|
||||||
// Check licences
|
// Check licences
|
||||||
let path = path.join("vendor");
|
let path = path.join("vendor");
|
||||||
@ -95,21 +113,35 @@ pub fn check(path: &Path, bad: &mut bool) {
|
|||||||
*bad = *bad || !check_license(&toml);
|
*bad = *bad || !check_license(&toml);
|
||||||
}
|
}
|
||||||
assert!(saw_dir, "no vendored source");
|
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
|
// Check dependencies
|
||||||
let deps = get_deps(&path);
|
let deps: HashSet<_> = get_deps(&path)
|
||||||
*bad = *bad
|
.into_iter()
|
||||||
|| deps.iter().any(
|
.map(|Package { name, version, .. }| (name, version))
|
||||||
|&Package {
|
.collect();
|
||||||
ref name,
|
let whitelist: HashSet<(String, String)> = WHITELIST
|
||||||
ref version,
|
.iter()
|
||||||
..
|
.map(|&(n, v)| (n.to_owned(), v.to_owned()))
|
||||||
}| {
|
.collect();
|
||||||
WHITELIST
|
|
||||||
.iter()
|
// Dependencies not in the whitelist
|
||||||
.all(|&(wname, wversion)| name != wname || version != wversion)
|
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 {
|
fn check_license(path: &Path) -> bool {
|
||||||
|
@ -41,6 +41,7 @@ fn main() {
|
|||||||
if !args.iter().any(|s| *s == "--no-vendor") {
|
if !args.iter().any(|s| *s == "--no-vendor") {
|
||||||
deps::check(&path, &mut bad);
|
deps::check(&path, &mut bad);
|
||||||
}
|
}
|
||||||
|
deps::check_whitelist(&path, &mut bad);
|
||||||
|
|
||||||
if bad {
|
if bad {
|
||||||
eprintln!("some tidy checks failed");
|
eprintln!("some tidy checks failed");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user