Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 669876 | Differences between
and this patch

Collapse All | Expand All

(-)a/src/tools/clippy/src/driver.rs (-37 / +5 lines)
Lines 29-82 Link Here
29
            exit(0);
29
            exit(0);
30
        }
30
        }
31
31
32
        let sys_root = option_env!("SYSROOT")
33
            .map(String::from)
34
            .or_else(|| std::env::var("SYSROOT").ok())
35
            .or_else(|| {
36
                let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
37
                let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
38
                home.and_then(|home| toolchain.map(|toolchain| format!("{}/toolchains/{}", home, toolchain)))
39
            })
40
            .or_else(|| {
41
                Command::new("rustc")
42
                    .arg("--print")
43
                    .arg("sysroot")
44
                    .output()
45
                    .ok()
46
                    .and_then(|out| String::from_utf8(out.stdout).ok())
47
                    .map(|s| s.trim().to_owned())
48
            })
49
            .expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust");
50
51
        // Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
32
        // Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
52
        // We're invoking the compiler programmatically, so we ignore this/
33
        // We're invoking the compiler programmatically, so we ignore this/
53
        let mut orig_args: Vec<String> = env::args().collect();
34
        let mut args: Vec<String> = env::args().collect();
54
        if orig_args.len() <= 1 {
35
        if args.len() <= 1 {
55
            std::process::exit(1);
36
            std::process::exit(1);
56
        }
37
        }
57
        if Path::new(&orig_args[1]).file_stem() == Some("rustc".as_ref()) {
38
        if Path::new(&args[1]).file_stem() == Some("rustc".as_ref()) {
58
            // we still want to be able to invoke it normally though
39
            // we still want to be able to invoke it normally though
59
            orig_args.remove(1);
40
            args.remove(1);
60
        }
41
        }
61
        // this conditional check for the --sysroot flag is there so users can call
62
        // `clippy_driver` directly
63
        // without having to pass --sysroot or anything
64
        let mut args: Vec<String> = if orig_args.iter().any(|s| s == "--sysroot") {
65
            orig_args.clone()
66
        } else {
67
            orig_args
68
                .clone()
69
                .into_iter()
70
                .chain(Some("--sysroot".to_owned()))
71
                .chain(Some(sys_root))
72
                .collect()
73
        };
74
42
75
        // this check ensures that dependencies are built but not linted and the final
43
        // this check ensures that dependencies are built but not linted and the final
76
        // crate is
44
        // crate is
77
        // linted but not built
45
        // linted but not built
78
        let clippy_enabled = env::var("CLIPPY_TESTS").ok().map_or(false, |val| val == "true")
46
        let clippy_enabled = env::var("CLIPPY_TESTS").ok().map_or(false, |val| val == "true")
79
            || orig_args.iter().any(|s| s == "--emit=dep-info,metadata");
47
            || args.iter().any(|s| s == "--emit=dep-info,metadata");
80
48
81
        if clippy_enabled {
49
        if clippy_enabled {
82
            args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]);
50
            args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]);

Return to bug 669876