1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Check license of third-party deps by inspecting src/vendor
17 static LICENSES: &'static [&'static str] = &[
26 // These are exceptions to Rust's permissive licensing policy, and
27 // should be considered bugs. Exceptions are only allowed in Rust
28 // tooling. It is _crucial_ that no exception crates be dependencies
29 // of the Rust runtime (std / test).
30 static EXCEPTIONS: &'static [&'static str] = &[
31 "mdbook", // MPL2, mdbook
32 "openssl", // BSD+advertising clause, cargo, mdbook
33 "pest", // MPL2, mdbook via handlebars
34 "thread-id", // Apache-2.0, mdbook
35 "strings", // this is actually MIT/Apache-2.0 but it's not in the manifest yet
38 pub fn check(path: &Path, bad: &mut bool) {
39 let path = path.join("vendor");
40 assert!(path.exists(), "vendor directory missing");
41 let mut saw_dir = false;
42 'next_path: for dir in t!(path.read_dir()) {
46 // skip our exceptions
47 for exception in EXCEPTIONS {
51 .contains(&format!("src/vendor/{}", exception)) {
56 let toml = dir.path().join("Cargo.toml");
57 if !check_license(&toml) {
61 assert!(saw_dir, "no vendored source");
64 fn check_license(path: &Path) -> bool {
66 panic!("{} does not exist", path.display());
68 let mut contents = String::new();
69 t!(t!(File::open(path)).read_to_string(&mut contents));
71 let mut found_license = false;
72 for line in contents.lines() {
73 if !line.starts_with("license") {
76 let license = extract_license(line);
77 if !LICENSES.contains(&&*license) {
78 println!("invalid license {} in {}", license, path.display());
85 println!("no license in {}", path.display());
92 fn extract_license(line: &str) -> String {
93 let first_quote = line.find('"');
94 let last_quote = line.rfind('"');
95 if let (Some(f), Some(l)) = (first_quote, last_quote) {
96 let license = &line[f + 1 .. l];
99 "bad-license-parse".into()