Skip to content

Commit

Permalink
Merge pull request geiger-rs#154 from jmcconnell26/ISSUE-16-RemoveNoL…
Browse files Browse the repository at this point in the history
…ongerNeededMappingFunctions

ISSUE-16 - Remove no longer needed mapping functions:

Signed-off-by: joshmc <josh-mcc@tiscali.co.uk>
  • Loading branch information
anderejd authored and jmcconnell26 committed Dec 2, 2020
2 parents d520b70 + 62d3d78 commit c4b4b83
Show file tree
Hide file tree
Showing 23 changed files with 463 additions and 292 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cargo-geiger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ geiger = { path = "../geiger", version = "0.4.5" }
krates = "0.5.0"
petgraph = "0.5.1"
pico-args = "0.3.3"
regex = "1.4.2"
serde = { version = "1.0.116", features = ["derive"] }
serde_json = "1.0.57"
strum = "0.19.2"
Expand Down
5 changes: 5 additions & 0 deletions cargo-geiger/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ OPTIONS:
--format <FORMAT> Format string used for printing dependencies
[default: {p}].
--json Output in JSON format.
--update-readme Writes output to README.md. Looks for a Safety
Report section, replaces if found, adds if not.
Throws an error if no README.md exists.
-v, --verbose Use verbose output (-vv very verbose/build.rs
output).
-q, --quiet No output printed to stdout other than the
Expand Down Expand Up @@ -79,6 +82,7 @@ pub struct Args {
pub quiet: bool,
pub target_args: TargetArgs,
pub unstable_flags: Vec<String>,
pub update_readme: bool,
pub verbose: u32,
pub version: bool,
pub output_format: Option<OutputFormat>,
Expand Down Expand Up @@ -129,6 +133,7 @@ impl Args {
.opt_value_from_str("-Z")?
.map(|s: String| s.split(' ').map(|s| s.to_owned()).collect())
.unwrap_or_else(Vec::new),
update_readme: raw_args.contains("--update-readme"),
verbose: match (
raw_args.contains("-vv"),
raw_args.contains(["-v", "--verbose"]),
Expand Down
3 changes: 2 additions & 1 deletion cargo-geiger/src/format/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ use crate::mapping::{
GetRepositoryFromCargoMetadataPackageId,
};

use cargo_metadata::PackageId;
use std::fmt;

pub struct Display<'a> {
pub cargo_metadata_parameters: &'a CargoMetadataParameters<'a>,
pub pattern: &'a Pattern,
pub package: &'a cargo_metadata::PackageId,
pub package: &'a PackageId,
}

impl<'a> fmt::Display for Display<'a> {
Expand Down
5 changes: 3 additions & 2 deletions cargo-geiger/src/format/pattern.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::format::parse::Parser;
use crate::format::{Chunk, RawChunk};
use crate::mapping::CargoMetadataParameters;

use super::display::Display;

use crate::mapping::CargoMetadataParameters;
use cargo_metadata::PackageId;
use std::error::Error;

#[derive(Debug, PartialEq)]
Expand All @@ -13,7 +14,7 @@ impl Pattern {
pub fn display<'a>(
&'a self,
cargo_metadata_parameters: &'a CargoMetadataParameters,
package: &'a cargo_metadata::PackageId,
package: &'a PackageId,
) -> Display<'a> {
Display {
cargo_metadata_parameters,
Expand Down
6 changes: 3 additions & 3 deletions cargo-geiger/src/format/table/handle_text_tree_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use super::total_package_counts::TotalPackageCounts;
use super::TableParameters;
use super::{table_row, table_row_empty};

use cargo_metadata::DependencyKind;
use cargo_metadata::{DependencyKind, PackageId};
use std::collections::HashSet;

pub struct HandlePackageParameters<'a> {
pub total_package_counts: &'a mut TotalPackageCounts,
pub visited_package_ids: &'a mut HashSet<cargo_metadata::PackageId>,
pub visited_package_ids: &'a mut HashSet<PackageId>,
pub warning_count: &'a mut u64,
}

Expand All @@ -36,7 +36,7 @@ pub fn handle_text_tree_line_package(
cargo_metadata_parameters: &CargoMetadataParameters,
emoji_symbols: &EmojiSymbols,
handle_package_parameters: &mut HandlePackageParameters,
package_id: cargo_metadata::PackageId,
package_id: PackageId,
table_lines: &mut Vec<String>,
table_parameters: &TableParameters,
tree_vines: String,
Expand Down
19 changes: 8 additions & 11 deletions cargo-geiger/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cargo::core::Workspace;
use cargo::util::interning::InternedString;
use cargo::util::CargoResult;
use cargo::Config;
use cargo_metadata::DependencyKind;
use cargo_metadata::{DependencyKind, PackageId};
use cargo_platform::{Cfg, Platform};
use petgraph::graph::NodeIndex;
use std::collections::hash_map::Entry;
Expand Down Expand Up @@ -39,11 +39,8 @@ impl ExtraDeps {

/// Representation of the package dependency graph
pub struct Graph {
pub graph: petgraph::Graph<
cargo_metadata::PackageId,
cargo_metadata::DependencyKind,
>,
pub nodes: HashMap<cargo_metadata::PackageId, NodeIndex>,
pub graph: petgraph::Graph<PackageId, cargo_metadata::DependencyKind>,
pub nodes: HashMap<PackageId, NodeIndex>,
}

// Almost unmodified compared to the original in cargo-tree, should be fairly
Expand All @@ -53,7 +50,7 @@ pub fn build_graph<'a>(
args: &Args,
cargo_metadata_parameters: &'a CargoMetadataParameters,
config: &Config,
root_package_id: cargo_metadata::PackageId,
root_package_id: PackageId,
workspace: &Workspace,
) -> CargoResult<Graph> {
let config_host = config.load_global_rustc(Some(&workspace))?.host;
Expand Down Expand Up @@ -102,10 +99,10 @@ struct GraphConfiguration<'a> {

fn add_graph_node_if_not_present_and_edge(
dependency: &cargo_metadata::Dependency,
dependency_package_id: cargo_metadata::PackageId,
dependency_package_id: PackageId,
graph: &mut Graph,
index: NodeIndex,
pending_packages: &mut Vec<cargo_metadata::PackageId>,
pending_packages: &mut Vec<PackageId>,
) {
let dependency_index =
match graph.nodes.entry(dependency_package_id.clone()) {
Expand All @@ -122,10 +119,10 @@ fn add_graph_node_if_not_present_and_edge(

fn add_package_dependencies_to_graph(
cargo_metadata_parameters: &CargoMetadataParameters,
package_id: cargo_metadata::PackageId,
package_id: PackageId,
graph_configuration: &GraphConfiguration,
graph: &mut Graph,
pending_packages: &mut Vec<cargo_metadata::PackageId>,
pending_packages: &mut Vec<PackageId>,
) {
let index = graph.nodes[&package_id];
let package = cargo_metadata_parameters
Expand Down
22 changes: 20 additions & 2 deletions cargo-geiger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod cli;
mod format;
mod graph;
mod mapping;
mod readme;
mod scan;
mod tree;

Expand All @@ -27,6 +28,7 @@ use crate::scan::scan;
use cargo::core::shell::Shell;
use cargo::util::important_paths;
use cargo::{CliError, CliResult, Config};
use readme::create_or_replace_section_in_readme;

const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");

Expand Down Expand Up @@ -85,14 +87,30 @@ fn real_main(args: &Args, config: &mut Config) -> CliResult {
},
);

scan(
let scan_output_lines = scan(
args,
&cargo_metadata_parameters,
config,
&graph,
query_resolve_root_package_id,
&workspace,
)
)?;

if args.update_readme {
let mut current_dir_path_buf = std::env::current_dir().unwrap();
current_dir_path_buf.push(readme::README_FILENAME);

create_or_replace_section_in_readme(
current_dir_path_buf,
&scan_output_lines,
)?;
} else {
for scan_output_line in scan_output_lines {
println!("{}", scan_output_line);
}
}

Ok(())
}

fn main() {
Expand Down
7 changes: 1 addition & 6 deletions cargo-geiger/src/mapping.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
mod core;
mod geiger;
mod krates;
mod metadata;

use ::krates::Krates;
use cargo::core::dependency::DepKind;
use cargo_metadata::{DependencyKind, Metadata};
use cargo_metadata::Metadata;
use std::collections::HashSet;
use std::path::PathBuf;

Expand Down Expand Up @@ -92,10 +91,6 @@ pub trait ToCargoGeigerSource {
) -> cargo_geiger_serde::Source;
}

pub trait ToCargoMetadataDependencyKind {
fn to_cargo_metadata_dependency_kind(&self) -> DependencyKind;
}

pub trait ToCargoMetadataPackage {
fn to_cargo_metadata_package(
&self,
Expand Down
Loading

0 comments on commit c4b4b83

Please sign in to comment.