Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add (repeatable) --allow <crate> option #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub enum CrateSupport {
ProcMacro,
SourceOffenses(Vec<SourceOffense>),
NoOffenseDetected,
Skipped,
}

#[derive(Debug)]
Expand Down Expand Up @@ -94,6 +95,7 @@ impl CheckResult {
CrateSupport::OnlyWithoutFeature(ref feature) => !self.is_feature_active(feature),
CrateSupport::NoOffenseDetected => true,
CrateSupport::SourceOffenses(_) => false,
CrateSupport::Skipped => true,
}
}

Expand Down
1 change: 1 addition & 0 deletions src/check_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub fn get_crate_support_from_source(main_src_path: &PathBuf) -> CrateSupport {
CrateSupport::ProcMacro => return main_file_support,
CrateSupport::SourceOffenses(mut off) => offenses.append(&mut off),
CrateSupport::NoOffenseDetected => {}
CrateSupport::Skipped => return main_file_support,
};

let other_source_files_pattern = format!(
Expand Down
31 changes: 28 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod util;

use clap::{App, Arg, SubCommand};
use console::Emoji;
use std::collections::HashSet;
use std::path::PathBuf;

use crate::check::*;
Expand All @@ -17,12 +18,14 @@ use cargo_metadata::{Metadata, Package};
pub static SUCCESS: Emoji = Emoji("✅ ", "SUCCESS");
pub static FAILURE: Emoji = Emoji("❌ ", "FAILURE");
pub static MAYBE: Emoji = Emoji("❓ ", "MAYBE");
pub static SKIPPED: Emoji = Emoji("⏭ ", "SKIPPED");

fn check_and_print_package(
package: &Package,
resolved_dependency_features: &[Feature],
metadata: &Metadata,
metadata_full: &Metadata,
allowed: &HashSet<String>,
is_main_pkg: bool,
) -> bool {
let mut package_did_fail = false;
Expand All @@ -42,6 +45,9 @@ fn check_and_print_package(
if package.is_proc_macro() {
support = CrateSupport::ProcMacro;
}
if allowed.contains(&package.name) {
support = CrateSupport::Skipped;
}
if support == CrateSupport::NoOffenseDetected {
match is_main_pkg {
false => {
Expand Down Expand Up @@ -83,9 +89,15 @@ fn check_and_print_package(
if !check.no_std_itself() {
package_did_fail = true;
}
let overall_res = match check.no_std_itself() {
true => SUCCESS,
false => FAILURE,
let overall_res = match check.support {
CrateSupport::ProcMacro => SUCCESS,
CrateSupport::OnlyWithoutFeature(ref feature) => match check.is_feature_active(feature) {
false => SUCCESS,
true => FAILURE,
},
CrateSupport::NoOffenseDetected => SUCCESS,
CrateSupport::SourceOffenses(_) => FAILURE,
CrateSupport::Skipped => SKIPPED,
};
println!("{}: {}", check.package_name, overall_res);
if check.no_std_itself() {
Expand Down Expand Up @@ -128,6 +140,12 @@ fn main() {
.multiple(true)
.takes_value(true),
)
.arg(
Arg::with_name("allow")
.long("allow")
.multiple(true)
.takes_value(true),
)
.arg(Arg::with_name("package").long("package").takes_value(true)),
);

Expand All @@ -151,6 +169,11 @@ fn main() {
.unwrap_or(Vec::new())
.to_owned(),
);
let allowed: HashSet<String> = matches
.values_of("allow")
.map(|n| n.into_iter().map(|m| m.to_owned()).collect())
.unwrap_or(HashSet::new())
.to_owned();

let active_features = target_package.active_features_for_features(&features);
let active_dependencies = target_package.active_dependencies(&active_features);
Expand All @@ -171,6 +194,7 @@ fn main() {
&resolved_dependency_features,
&metadata,
&metadata_full,
&allowed,
true,
) {
package_did_fail = true;
Expand All @@ -182,6 +206,7 @@ fn main() {
&resolved_dependency_features,
&metadata,
&metadata_full,
&allowed,
false,
) {
package_did_fail = true;
Expand Down