Skip to content

Commit

Permalink
Add deduplication (#28)
Browse files Browse the repository at this point in the history
* Add deduplication

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Work on deduplication

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix feature deduplication

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Bump deps

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Bump serde

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update README

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Hide files

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
ggwpez committed Aug 27, 2023
1 parent 6088a15 commit 69f0a66
Show file tree
Hide file tree
Showing 19 changed files with 596 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
echo "Checking features #3"
zepter lint propagate-feature --feature std --left-side-feature-missing=ignore --workspace
echo "Checking formatting #1"
zepter format features --check
zepter format features --check --exit-code-zero
- if: matrix.repo != 'substrate'
name: Zepter doesnt panic
# Polkadot and Cumulus can be red, but should not panic. Hence the `--exit-code-zero`.
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions spec.toml → .spec.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# UNUSED these are some ides on how to do config files.

test: Check that the feature propagates.
given:
crates: [A, B]
Expand Down
59 changes: 29 additions & 30 deletions Cargo.lock

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

32 changes: 12 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[package]
name = "zepter"
version = "0.10.1"
version = "0.11.0"
edition = "2021"
authors = [ "Oliver Tale-Yazdi" ]
description = "Check if features are correctly propagated in your workspace."
description = "Analyze, Fix and Format features in your Rust workspace."
license = "GPL-3.0-only"
repository = "https://github.com/ggwpez/zepter"
rust-version = "1.65"
# Update the README if you change this:
rust-version = "1.70"

[[bin]]
name = "zepter"
Expand All @@ -16,42 +17,34 @@ name = "dag"
harness = false

[dependencies]
anyhow = { version = "1.0.75", optional = true }
assert_cmd = { version = "2.0.11", optional = true }
cargo_metadata = "0.17.0"
clap = { version = "4.3.24", features = ["derive"] }
toml_edit = "0.19.14"

# Optional deps
colour = { version = "0.7.0", optional = true }
env_logger = { version = "0.10.0", features = [ "auto-color", "humantime" ], optional = true }
log = { version = "0.4.20", optional = true }

# Testing deps
anyhow = { version = "1.0.75", optional = true }
assert_cmd = { version = "2.0.11", optional = true }
colour = { version = "0.7.0", optional = true }
serde = { version = "1.0.185", optional = true }
serde = { version = "1.0.188", optional = true }
serde_yaml = { version = "0.9.25", optional = true }
tempfile = { version = "3.8.0", optional = true }
toml_edit = "0.19.14"

[dev-dependencies]
zepter = { path = ".", features = ["testing"] }

anyhow = "1.0.75"
criterion = "0.5"
glob = "0.3.1"
lazy_static = "1.4.0"
pretty_assertions = "1.4.0"
rand = "0.8.5"
rstest = "0.18.2"
serde = "1.0.185"
serde = "1.0.188"
void = "1.0.2"
zepter = { path = ".", features = ["testing"] }

[features]
default = [ "logging" ]

logging = [
"dep:env_logger",
"dep:log",
]
logging = [ "dep:env_logger", "dep:log" ]

testing = [
"dep:anyhow",
Expand All @@ -60,7 +53,6 @@ testing = [
"dep:serde",
"dep:serde_yaml",
"dep:tempfile",

]

[profile.dev]
Expand Down
69 changes: 67 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,82 @@

[![Rust](https://github.com/ggwpez/zepter/actions/workflows/rust.yml/badge.svg)](https://github.com/ggwpez/zepter/actions/workflows/rust.yml)
[![crates.io](https://img.shields.io/crates/v/zepter.svg)](https://crates.io/crates/zepter)
![MSRV](https://img.shields.io/badge/MSRV-1.65-informational)
![MSRV](https://img.shields.io/badge/MSRV-1.70-informational)
[![docs.rs](https://img.shields.io/docsrs/zepter)](https://docs.rs/zepter/latest/zepter)

Analyze and fix feature propagation in your Rust workspace. The goal of this tool is to automatically lint and fix feature propagation in CI runs.
Analyze, Fix and Format features in your Rust workspace. The goal of this tool is to have this CI ready to prevent common errors with Rust features.

## Install

```bash
cargo install -f zepter --locked
```

## Commands

zepter
- format
- features: Format features layout and remove duplicates.
- trace: Trace dependencies paths.
- lint
- propagate-features: Check that features are passed down.
- never-enables: A feature should never enable another other.
- never-implies *(⚠️ unstable)*: A feature should never transitively imply another one.
- only-enables *(⚠️ unstable)*: A features should exclusively enable another one.
- why-enables *(⚠️ unstable)*: Find out why a specific feature is enables.

## Example - Feature Formatting

To ensure that your features are in canonical formatting, just run:

```bash
zepter format features --check
# Or shorter:
zepter f f -c
```

The output will tell you which features are missing formatting:

```pre
Found 3 crates with unformatted features:
polkadot-cli
polkadot-runtime-common
polkadot-runtime-parachains
...
Run again without --check to format them.
```

You can then re-run without the `check`/`c` flag to get it fixed automatically:

```pre
Found 3 crates with unformatted features:
polkadot-cli
polkadot-parachain
polkadot-core-primitives
polkadot-primitives
...
Formatted 37 crates (all fixed).
```

Looking at the diff that this command produces; Zepter assumes a default line width of 80. For one-lined features they will just be padded with spaces:

```patch
-default = [
- "static_assertions",
-]
+default = [ "static_assertions" ]
```

Entries are sorted, comments are kept and indentation is one tab for your convenience 😊

```patch
- # Hi
- "xcm/std",
"xcm-builder/std",
+ # Hi
+ "xcm/std",
```

## Example - Fixing feature propagation

Let's check that the `runtime-benchmarks` feature is properly passed down to all the dependencies of the `frame-support` crate in the workspace of [Substrate]. You can use commit `395853ac15` to verify it yourself:
Expand Down
Loading

0 comments on commit 69f0a66

Please sign in to comment.