Skip to content

Commit 3570b9d

Browse files
committed
MAKE IT FAILgit statusgit status
1 parent d626218 commit 3570b9d

File tree

2 files changed

+53
-20
lines changed

2 files changed

+53
-20
lines changed

src/tools/tidy/src/deps.rs

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
//! Check license of third-party deps by inspecting src/vendor
1212
13+
use std::collections::HashSet;
1314
use std::fs::File;
1415
use std::io::Read;
1516
use std::path::Path;
16-
1717
use std::process::Command;
1818

1919
use serde_json;
@@ -56,22 +56,40 @@ static WHITELIST: &'static [(&'static str, &'static str)] = &[];
5656
#[derive(Deserialize)]
5757
struct Output {
5858
packages: Vec<Package>,
59-
_resolve: String,
59+
60+
// Not used, but needed to not confuse serde :P
61+
#[allow(dead_code)] resolve: Resolve,
6062
}
6163

6264
#[derive(Deserialize)]
6365
struct Package {
64-
_id: String,
6566
name: String,
6667
version: String,
67-
_source: Option<String>,
68-
_manifest_path: String,
68+
69+
// Not used, but needed to not confuse serde :P
70+
#[allow(dead_code)] id: String,
71+
#[allow(dead_code)] source: Option<String>,
72+
#[allow(dead_code)] manifest_path: String,
73+
}
74+
75+
// Not used, but needed to not confuse serde :P
76+
#[allow(dead_code)]
77+
#[derive(Deserialize)]
78+
struct Resolve {
79+
nodes: Vec<ResolveNode>,
80+
}
81+
82+
// Not used, but needed to not confuse serde :P
83+
#[allow(dead_code)]
84+
#[derive(Deserialize)]
85+
struct ResolveNode {
86+
id: String,
87+
dependencies: Vec<String>,
6988
}
7089

7190
/// Checks the dependency at the given path. Changes `bad` to `true` if a check failed.
7291
///
73-
/// Specifically, this checks that the license is correct and that the dependencies are on the
74-
/// whitelist.
92+
/// Specifically, this checks that the license is correct.
7593
pub fn check(path: &Path, bad: &mut bool) {
7694
// Check licences
7795
let path = path.join("vendor");
@@ -95,21 +113,35 @@ pub fn check(path: &Path, bad: &mut bool) {
95113
*bad = *bad || !check_license(&toml);
96114
}
97115
assert!(saw_dir, "no vendored source");
116+
}
98117

118+
/// Checks the dependency at the given path. Changes `bad` to `true` if a check failed.
119+
///
120+
/// Specifically, this checks that the dependencies are on the whitelist.
121+
pub fn check_whitelist(path: &Path, bad: &mut bool) {
99122
// Check dependencies
100-
let deps = get_deps(&path);
101-
*bad = *bad
102-
|| deps.iter().any(
103-
|&Package {
104-
ref name,
105-
ref version,
106-
..
107-
}| {
108-
WHITELIST
109-
.iter()
110-
.all(|&(wname, wversion)| name != wname || version != wversion)
111-
},
112-
);
123+
let deps: HashSet<_> = get_deps(&path)
124+
.into_iter()
125+
.map(|Package { name, version, .. }| (name, version))
126+
.collect();
127+
let whitelist: HashSet<(String, String)> = WHITELIST
128+
.iter()
129+
.map(|&(n, v)| (n.to_owned(), v.to_owned()))
130+
.collect();
131+
132+
// Dependencies not in the whitelist
133+
let mut unapproved: Vec<_> = deps.difference(&whitelist).collect();
134+
135+
// For ease of reading
136+
unapproved.sort();
137+
138+
if unapproved.len() > 0 {
139+
println!("Dependencies not on the whitelist:");
140+
for dep in unapproved {
141+
println!("* {} {}", dep.0, dep.1); // name version
142+
}
143+
*bad = true;
144+
}
113145
}
114146

115147
fn check_license(path: &Path) -> bool {

src/tools/tidy/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ fn main() {
4141
if !args.iter().any(|s| *s == "--no-vendor") {
4242
deps::check(&path, &mut bad);
4343
}
44+
deps::check_whitelist(&path, &mut bad);
4445

4546
if bad {
4647
eprintln!("some tidy checks failed");

0 commit comments

Comments
 (0)