From e5a4477e6cbaa735e04b552623abc6010d8d4542 Mon Sep 17 00:00:00 2001 From: Federico Poli Date: Thu, 10 Dec 2020 10:26:34 +0100 Subject: [PATCH] Use CARGO_PRIMARY_PACKAGE to skip dependencies See also https://github.com/rust-lang/cargo/pull/8758 and https://github.com/rust-lang/rust-clippy/pull/6188 --- prusti-tests/tests/compiletest.rs | 2 ++ prusti/src/arg_value.rs | 45 ------------------------------- prusti/src/driver.rs | 7 ++--- 3 files changed, 6 insertions(+), 48 deletions(-) delete mode 100644 prusti/src/arg_value.rs diff --git a/prusti-tests/tests/compiletest.rs b/prusti-tests/tests/compiletest.rs index fef6ca75a32..ce5dcec3028 100644 --- a/prusti-tests/tests/compiletest.rs +++ b/prusti-tests/tests/compiletest.rs @@ -146,6 +146,8 @@ fn run_verification_core_proof(group_name: &str, filter: &Option) { } fn test_runner(_tests: &[&()]) { + env::set_var("PRUSTI_TESTS", "1"); + // Spawn server process as child (so it stays around until main function terminates) let server_address = ServerSideService::spawn_off_thread(); env::set_var("PRUSTI_SERVER_ADDRESS", server_address.to_string()); diff --git a/prusti/src/arg_value.rs b/prusti/src/arg_value.rs deleted file mode 100644 index 42d0b157fdc..00000000000 --- a/prusti/src/arg_value.rs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2014-2020 The Rust Project Developers -// -// Licensed under the Apache License, Version 2.0 or the MIT license , at your option. Files in the project may not be copied, -// modified, or distributed except according to those terms. - -/// Source: https://github.com/rust-lang/rust-clippy/blob/master/src/driver.rs -use std::ops::Deref; - -/// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If -/// true, then return it. The parameter is assumed to be either `--arg=value` or `--arg value`. -pub fn arg_value<'a, T: Deref>( - args: &'a [T], - find_arg: &str, - pred: impl Fn(&str) -> bool, -) -> Option<&'a str> { - let mut args = args.iter().map(Deref::deref); - while let Some(arg) = args.next() { - let mut arg = arg.splitn(2, '='); - if arg.next() != Some(find_arg) { - continue; - } - - match arg.next().or_else(|| args.next()) { - Some(v) if pred(v) => return Some(v), - _ => {}, - } - } - None -} - -#[test] -fn test_arg_value() { - let args = &["--bar=bar", "--foobar", "123", "--foo"]; - - assert_eq!(arg_value(&[] as &[&str], "--foobar", |_| true), None); - assert_eq!(arg_value(args, "--bar", |_| false), None); - assert_eq!(arg_value(args, "--bar", |_| true), Some("bar")); - assert_eq!(arg_value(args, "--bar", |p| p == "bar"), Some("bar")); - assert_eq!(arg_value(args, "--bar", |p| p == "foo"), None); - assert_eq!(arg_value(args, "--foobar", |p| p == "foo"), None); - assert_eq!(arg_value(args, "--foobar", |p| p == "123"), Some("123")); - assert_eq!(arg_value(args, "--foo", |_| true), None); -} diff --git a/prusti/src/driver.rs b/prusti/src/driver.rs index a7d5ee1aa27..54e07b7396a 100644 --- a/prusti/src/driver.rs +++ b/prusti/src/driver.rs @@ -30,7 +30,6 @@ extern crate prusti_common; mod callbacks; mod verifier; -mod arg_value; use log::debug; use std::{env, panic, borrow::Cow, path::PathBuf}; @@ -40,7 +39,6 @@ use lazy_static::lazy_static; use callbacks::PrustiCompilerCalls; use rustc_middle::ty::TyCtxt; use prusti_common::config; -use arg_value::arg_value; /// Link to report Prusti bugs const BUG_REPORT_URL: &str = "https://github.com/viperproject/prusti-dev/issues/new"; @@ -125,8 +123,11 @@ fn main() { // If the environment asks us to actually be rustc, then do that. // If cargo is compiling a dependency, then be rustc. + let is_prusti_test = env::var("PRUSTI_TESTS").is_ok(); + let is_cargo_running = env::var("CARGO_PKG_NAME").is_ok(); + let in_primary_package = env::var("CARGO_PRIMARY_PACKAGE").is_ok(); let prusti_be_rustc = config::be_rustc() - || arg_value(&rustc_args, "--cap-lints", |val| val == "allow").is_some(); + || (!is_prusti_test && is_cargo_running && !in_primary_package); if prusti_be_rustc { rustc_driver::main(); }