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 MPL licensed projects are acceptable, but only these.
27 static EXCEPTIONS: &'static [&'static str] = &[
34 pub fn check(path: &Path, bad: &mut bool) {
35 let path = path.join("vendor");
36 assert!(path.exists(), "vendor directory missing");
37 let mut saw_dir = false;
38 'next_path: for dir in t!(path.read_dir()) {
42 // skip our exceptions
43 for exception in EXCEPTIONS {
47 .contains(&format!("src/vendor/{}", exception)) {
52 let toml = dir.path().join("Cargo.toml");
53 if !check_license(&toml) {
57 assert!(saw_dir, "no vendored source");
60 fn check_license(path: &Path) -> bool {
62 panic!("{} does not exist", path.display());
64 let mut contents = String::new();
65 t!(t!(File::open(path)).read_to_string(&mut contents));
67 let mut found_license = false;
68 for line in contents.lines() {
69 if !line.starts_with("license") {
72 let license = extract_license(line);
73 if !LICENSES.contains(&&*license) {
74 println!("invalid license {} in {}", license, path.display());
81 println!("no license in {}", path.display());
88 fn extract_license(line: &str) -> String {
89 let first_quote = line.find('"');
90 let last_quote = line.rfind('"');
91 if let (Some(f), Some(l)) = (first_quote, last_quote) {
92 let license = &line[f + 1 .. l];
95 "bad-license-parse".into()