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] = &[
27 // These are exceptions to Rust's permissive licensing policy, and
28 // should be considered bugs. Exceptions are only allowed in Rust
29 // tooling. It is _crucial_ that no exception crates be dependencies
30 // of the Rust runtime (std / test).
31 static EXCEPTIONS: &'static [&'static str] = &[
32 "mdbook", // MPL2, mdbook
33 "openssl", // BSD+advertising clause, cargo, mdbook
34 "pest", // MPL2, mdbook via handlebars
35 "thread-id", // Apache-2.0, mdbook
36 "cssparser", // MPL-2.0, rustdoc
37 "smallvec", // MPL-2.0, rustdoc
38 "fuchsia-zircon-sys", // BSD-3-Clause, rustdoc, rustc, cargo
39 "fuchsia-zircon", // BSD-3-Clause, rustdoc, rustc, cargo (jobserver & tempdir)
40 "cssparser-macros", // MPL-2.0, rustdoc
41 "selectors", // MPL-2.0, rustdoc
44 pub fn check(path: &Path, bad: &mut bool) {
45 let path = path.join("vendor");
46 assert!(path.exists(), "vendor directory missing");
47 let mut saw_dir = false;
48 'next_path: for dir in t!(path.read_dir()) {
52 // skip our exceptions
53 for exception in EXCEPTIONS {
57 .contains(&format!("src/vendor/{}", exception)) {
62 let toml = dir.path().join("Cargo.toml");
63 if !check_license(&toml) {
67 assert!(saw_dir, "no vendored source");
70 fn check_license(path: &Path) -> bool {
72 panic!("{} does not exist", path.display());
74 let mut contents = String::new();
75 t!(t!(File::open(path)).read_to_string(&mut contents));
77 let mut found_license = false;
78 for line in contents.lines() {
79 if !line.starts_with("license") {
82 let license = extract_license(line);
83 if !LICENSES.contains(&&*license) {
84 println!("invalid license {} in {}", license, path.display());
91 println!("no license in {}", path.display());
98 fn extract_license(line: &str) -> String {
99 let first_quote = line.find('"');
100 let last_quote = line.rfind('"');
101 if let (Some(f), Some(l)) = (first_quote, last_quote) {
102 let license = &line[f + 1 .. l];
105 "bad-license-parse".into()