Skip to content

Commit

Permalink
Add features (#42)
Browse files Browse the repository at this point in the history
* Make more complicated feature testing

* Begin fleshing out features

* Format

* Checkpoint

* Checkpoint again

* Checkpoint

* Checkpoint

* Remove files I shouldn't have checked in

* Checkpoint

* Checkpoint

* Update to new manifest format

* Update cfg-expr

* Cleanup

* Checkpoint

* Checkpoint

* Fix lints

* Add simpl dot graph output example

* Fix features

* Expose feature parsing

* Use a BTreeMap for feature edge output consistency

* Update CI

* Transition to snapshots

* Fix lint

* Fix deny

* Fix doc tests
  • Loading branch information
Jake-Shadle authored Oct 6, 2022
1 parent 9df0830 commit bd10b88
Show file tree
Hide file tree
Showing 55 changed files with 8,489 additions and 613 deletions.
79 changes: 79 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
[target.'cfg(all())']
rustflags = [
# BEGIN - Embark standard lints v6 for Rust 1.55+
# do not change or add/remove here, but one can add exceptions after this section
# for more info see: <https://github.com/EmbarkStudios/rust-ecosystem/issues/59>
"-Dunsafe_code",
"-Wclippy::all",
"-Wclippy::await_holding_lock",
"-Wclippy::char_lit_as_u8",
"-Wclippy::checked_conversions",
"-Wclippy::dbg_macro",
"-Wclippy::debug_assert_with_mut_call",
"-Wclippy::doc_markdown",
"-Wclippy::empty_enum",
"-Wclippy::enum_glob_use",
"-Wclippy::exit",
"-Wclippy::expl_impl_clone_on_copy",
"-Wclippy::explicit_deref_methods",
"-Wclippy::explicit_into_iter_loop",
"-Wclippy::fallible_impl_from",
"-Wclippy::filter_map_next",
"-Wclippy::flat_map_option",
"-Wclippy::float_cmp_const",
"-Wclippy::fn_params_excessive_bools",
"-Wclippy::from_iter_instead_of_collect",
"-Wclippy::if_let_mutex",
"-Wclippy::implicit_clone",
"-Wclippy::imprecise_flops",
"-Wclippy::inefficient_to_string",
"-Wclippy::invalid_upcast_comparisons",
"-Wclippy::large_digit_groups",
"-Wclippy::large_stack_arrays",
"-Wclippy::large_types_passed_by_value",
"-Wclippy::let_unit_value",
"-Wclippy::linkedlist",
"-Wclippy::lossy_float_literal",
"-Wclippy::macro_use_imports",
"-Wclippy::manual_ok_or",
"-Wclippy::map_err_ignore",
"-Wclippy::map_flatten",
"-Wclippy::map_unwrap_or",
"-Wclippy::match_on_vec_items",
"-Wclippy::match_same_arms",
"-Wclippy::match_wild_err_arm",
"-Wclippy::match_wildcard_for_single_variants",
"-Wclippy::mem_forget",
"-Wclippy::mismatched_target_os",
"-Wclippy::missing_enforced_import_renames",
"-Wclippy::mut_mut",
"-Wclippy::mutex_integer",
"-Wclippy::needless_borrow",
"-Wclippy::needless_continue",
"-Wclippy::needless_for_each",
"-Wclippy::option_option",
"-Wclippy::path_buf_push_overwrite",
"-Wclippy::ptr_as_ptr",
"-Wclippy::rc_mutex",
"-Wclippy::ref_option_ref",
"-Wclippy::rest_pat_in_fully_bound_structs",
"-Wclippy::same_functions_in_if_condition",
"-Wclippy::semicolon_if_nothing_returned",
"-Wclippy::single_match_else",
"-Wclippy::string_add_assign",
"-Wclippy::string_add",
"-Wclippy::string_lit_as_bytes",
"-Wclippy::string_to_string",
"-Wclippy::todo",
"-Wclippy::trait_duplication_in_bounds",
"-Wclippy::unimplemented",
"-Wclippy::unnested_or_patterns",
"-Wclippy::unused_self",
"-Wclippy::useless_transmute",
"-Wclippy::verbose_file_reads",
"-Wclippy::zero_sized_map_values",
"-Wfuture_incompatible",
"-Wnonstandard_style",
"-Wrust_2018_idioms",
# END - Embark standard lints v6 for Rust 1.55+
]
37 changes: 15 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@ name: CI
jobs:
lint:
name: Lint
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
override: true

components: "clippy, rustfmt"
- uses: Swatinem/rust-cache@v2
# make sure all code has been formatted with rustfmt
- run: rustup component add rustfmt
- name: check rustfmt
run: cargo fmt -- --check --color always

# run clippy to verify we have no warnings
- run: rustup component add clippy
- run: cargo fetch
- name: cargo clippy
run: cargo clippy --all-targets -- -D warnings
Expand All @@ -39,14 +36,12 @@ jobs:
name: Test
strategy:
matrix:
os: [ubuntu-20.04, macOS-latest]
os: [ubuntu-22.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo fetch
- name: cargo test build
run: cargo build --tests --release
Expand All @@ -59,20 +54,18 @@ jobs:

deny-check:
name: cargo-deny
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1

publish-check:
name: Publish Check
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo fetch
- name: cargo publish check
run: cargo publish --dry-run
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ documentation = "https://docs.rs/krates"
homepage = "https://github.com/EmbarkStudios/krates"
keywords = ["cargo", "metadata", "graph"]
categories = ["visualization"]
exclude = [".github", "tests"]

[features]
default = []
Expand All @@ -25,13 +26,16 @@ targets = ["cfg-expr/targets"]
# Used for acquiring and/or deserializing `cargo metadata` output
cargo_metadata = "0.15"
# Used to parse and evaluate cfg() expressions for dependencies
cfg-expr = "0.10"
cfg-expr = "0.11"
# Used to create and traverse graph structures
petgraph = "0.6"
# Used for checking version requirements
semver = "1.0"

[dev-dependencies]
# Example CLI
clap = { version = "4.0", features = ["derive"] }
insta = "1.21"
# Used to print colored diffs in case of test failures
similar-asserts = "1.1"
# Used to deserialize test files into metadata we can load
Expand Down
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ allow = [
"Apache-2.0",
"Apache-2.0 WITH LLVM-exception",
"MIT",
"Unicode-DFS-2016",
]
copyleft = "deny"

Expand Down
64 changes: 64 additions & 0 deletions examples/graph.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use clap::Parser;
use std::fmt;

/// Simple program to greet a person
#[derive(Parser, Debug)]
struct Args {
#[arg(short, long)]
manifest_path: String,
#[arg(long)]
features: Vec<String>,
#[arg(long)]
all_features: bool,
#[arg(long)]
no_default_features: bool,
}

pub struct Simple {
id: krates::Kid,
//features: HashMap<String, Vec<String>>,
}

pub type Graph = krates::Krates<Simple>;

impl From<krates::cm::Package> for Simple {
fn from(pkg: krates::cm::Package) -> Self {
Self {
id: pkg.id,
//features: pkg.fee
}
}
}

impl fmt::Display for Simple {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.id.repr)
}
}

fn main() {
let args = Args::parse();

let cmd = {
let mut cmd = krates::Cmd::new();
if args.all_features {
cmd.all_features();
}
if args.no_default_features {
cmd.no_default_features();
}
if !args.features.is_empty() {
cmd.features(args.features);
}
cmd.manifest_path(args.manifest_path);
cmd
};

let builder = krates::Builder::new();
let graph: Graph = builder.build(cmd, krates::NoneFilter).unwrap();

let dot = krates::petgraph::dot::Dot::new(graph.graph()).to_string();

use std::io::Write;
std::io::stdout().write_all(dot.as_bytes()).unwrap();
}
Loading

0 comments on commit bd10b88

Please sign in to comment.