Skip to content

Commit

Permalink
Warn on unexpected libstd dependence (#95)
Browse files Browse the repository at this point in the history
* Warn on unexpected libstd pull

Signed-off-by: Oliver Tale-Yazdi <[email protected]>

* Bump to 1.4.1

Signed-off-by: Oliver Tale-Yazdi <[email protected]>

* Bump deps

Signed-off-by: Oliver Tale-Yazdi <[email protected]>

* fmt

Signed-off-by: Oliver Tale-Yazdi <[email protected]>

---------

Signed-off-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
ggwpez authored Apr 9, 2024
1 parent c45dc78 commit c72cce2
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 125 deletions.
204 changes: 102 additions & 102 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zepter"
version = "1.4.0"
version = "1.4.1"
edition = "2021"
authors = [ "Oliver Tale-Yazdi" ]
description = "Analyze, Fix and Format features in your Rust workspace."
Expand Down Expand Up @@ -42,7 +42,7 @@ glob = "0.3.1"
lazy_static = "1.4.0"
pretty_assertions = "1.4.0"
rand = "0.8.5"
rstest = "0.18.2"
rstest = "0.19.0"
serde = "1.0.197"
zepter = { path = ".", features = ["testing"] }

Expand Down
19 changes: 15 additions & 4 deletions src/cmd/lint/nostd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl NoStdCmd {
}

impl DefaultFeaturesDisabledCmd {
pub(crate) fn run(&self, _: &GlobalArgs) -> Result<(), String> {
pub(crate) fn run(&self, g: &GlobalArgs) -> Result<(), String> {
let meta = self.cargo_args.clone().with_workspace(true).load_metadata()?;
let pkgs = &meta.packages;
let mut cache = BTreeMap::new();
Expand All @@ -56,7 +56,7 @@ impl DefaultFeaturesDisabledCmd {

for lhs in pkgs.iter() {
// check if lhs supports no-std builds
if !Self::supports_nostd(lhs, &mut cache)? {
if !Self::supports_nostd(g, lhs, &mut cache)? {
continue;
}

Expand All @@ -67,7 +67,7 @@ impl DefaultFeaturesDisabledCmd {

let Some(rhs) = resolve_dep(lhs, dep, &meta) else { continue };

if !Self::supports_nostd(&rhs.pkg, &mut cache)? {
if !Self::supports_nostd(g, &rhs.pkg, &mut cache)? {
continue;
}

Expand Down Expand Up @@ -112,7 +112,11 @@ impl DefaultFeaturesDisabledCmd {
}
}

fn supports_nostd(krate: &Package, cache: &mut BTreeMap<String, bool>) -> Result<bool, String> {
fn supports_nostd(
g: &GlobalArgs,
krate: &Package,
cache: &mut BTreeMap<String, bool>,
) -> Result<bool, String> {
log::debug!("Checking if crate supports no-std: {}", krate.name);
if let Some(res) = cache.get(krate.manifest_path.as_str()) {
return Ok(*res)
Expand All @@ -134,6 +138,13 @@ impl DefaultFeaturesDisabledCmd {
let ret = if content.contains("#![cfg_attr(not(feature = \"std\"), no_std)]") ||
content.contains("#![no_std]")
{
if content.contains("#![cfg(") {
println!(
"{}: Crate may unexpectedly pull in libstd: {}",
g.yellow("WARN"),
krate.name
);
}
log::debug!("Crate supports no-std: {} (path={})", krate.name, krate.manifest_path);
true
} else {
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/sdk/nostd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ cases:
- cmd: lint no-std default-features-of-nostd-dependencies-disabled
stdout: |
Default features not disabled for dependency: sp-core -> sp-externalities
WARN: Crate may unexpectedly pull in libstd: frame-try-runtime
WARN: Crate may unexpectedly pull in libstd: frame-benchmarking
Default features not disabled for dependency: sp-session -> sp-runtime
Default features not disabled for dependency: sp-consensus-babe -> sp-timestamp
WARN: Crate may unexpectedly pull in libstd: frame-system-benchmarking
WARN: Crate may unexpectedly pull in libstd: pallet-election-provider-support-benchmarking
WARN: Crate may unexpectedly pull in libstd: pallet-nomination-pools-benchmarking
WARN: Crate may unexpectedly pull in libstd: pallet-offences-benchmarking
WARN: Crate may unexpectedly pull in libstd: pallet-session-benchmarking
Default features not disabled for dependency: pallet-contracts -> pallet-contracts-proc-macro
Default features not disabled for dependency: pallet-nomination-pools -> pallet-balances
Default features not disabled for dependency: pallet-nomination-pools -> sp-tracing
Expand All @@ -16,6 +23,8 @@ cases:
Default features not disabled for dependency: cumulus-primitives-parachain-inherent -> sp-runtime
Default features not disabled for dependency: cumulus-primitives-parachain-inherent -> sp-state-machine
Default features not disabled for dependency: cumulus-primitives-parachain-inherent -> sp-storage
WARN: Crate may unexpectedly pull in libstd: cumulus-pallet-session-benchmarking
WARN: Crate may unexpectedly pull in libstd: xcm-executor-integration-tests
Default features not disabled for dependency: xcm-executor-integration-tests -> frame-system
Default features not disabled for dependency: xcm-executor-integration-tests -> pallet-xcm
Default features not disabled for dependency: xcm-executor-integration-tests -> polkadot-test-runtime
Expand All @@ -31,8 +40,15 @@ cases:
- cmd: lint no-std default-features-of-nostd-dependencies-disabled --fix
stdout: |
Default features not disabled for dependency: sp-core -> sp-externalities
WARN: Crate may unexpectedly pull in libstd: frame-try-runtime
WARN: Crate may unexpectedly pull in libstd: frame-benchmarking
Default features not disabled for dependency: sp-session -> sp-runtime
Default features not disabled for dependency: sp-consensus-babe -> sp-timestamp
WARN: Crate may unexpectedly pull in libstd: frame-system-benchmarking
WARN: Crate may unexpectedly pull in libstd: pallet-election-provider-support-benchmarking
WARN: Crate may unexpectedly pull in libstd: pallet-nomination-pools-benchmarking
WARN: Crate may unexpectedly pull in libstd: pallet-offences-benchmarking
WARN: Crate may unexpectedly pull in libstd: pallet-session-benchmarking
Default features not disabled for dependency: pallet-contracts -> pallet-contracts-proc-macro
Default features not disabled for dependency: pallet-nomination-pools -> pallet-balances
Default features not disabled for dependency: pallet-nomination-pools -> sp-tracing
Expand All @@ -42,6 +58,8 @@ cases:
Default features not disabled for dependency: cumulus-primitives-parachain-inherent -> sp-runtime
Default features not disabled for dependency: cumulus-primitives-parachain-inherent -> sp-state-machine
Default features not disabled for dependency: cumulus-primitives-parachain-inherent -> sp-storage
WARN: Crate may unexpectedly pull in libstd: cumulus-pallet-session-benchmarking
WARN: Crate may unexpectedly pull in libstd: xcm-executor-integration-tests
Default features not disabled for dependency: xcm-executor-integration-tests -> frame-system
Default features not disabled for dependency: xcm-executor-integration-tests -> pallet-xcm
Default features not disabled for dependency: xcm-executor-integration-tests -> polkadot-test-runtime
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/config/v1/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ crates:
cases:
- cmd: run default
stdout: |
zepter 1.4.0
zepter 1.4.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
- cmd: run
stdout: |
zepter 1.4.0
zepter 1.4.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
- cmd: ''
stdout: |
zepter 1.4.0
zepter 1.4.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
- cmd: run my_version
stdout: |
zepter 1.4.0
zepter 1.4.1
stderr: |
[INFO] Running workflow 'my_version'
[INFO] 1/1 --version
Expand All @@ -36,7 +36,7 @@ cases:
[INFO] 1/1 debug --no-benchmark
- cmd: run both
stdout: |
zepter 1.4.0
zepter 1.4.1
Num workspace members: 1
Num dependencies: 1
DAG nodes: 0, links: 0
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/config/v1/finds_all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ crates:
cases:
- cmd: ''
stdout: |
zepter 1.4.0
zepter 1.4.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
Expand All @@ -19,7 +19,7 @@ cases:
- [ '--version' ]
- cmd: ''
stdout: |
zepter 1.4.0
zepter 1.4.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
Expand All @@ -35,7 +35,7 @@ cases:
- [ '--version' ]
- cmd: ''
stdout: |
zepter 1.4.0
zepter 1.4.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
Expand All @@ -51,7 +51,7 @@ cases:
- [ '--version' ]
- cmd: run default
stdout: |
zepter 1.4.0
zepter 1.4.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
Expand All @@ -67,7 +67,7 @@ cases:
- [ '--version' ]
- cmd: run default
stdout: |
zepter 1.4.0
zepter 1.4.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
Expand All @@ -83,7 +83,7 @@ cases:
- [ '--version' ]
- cmd: run default
stdout: |
zepter 1.4.0
zepter 1.4.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
Expand All @@ -99,7 +99,7 @@ cases:
- [ '--version' ]
- cmd: run default --config .cargo/polkadot.yaml
stdout: |
zepter 1.4.0
zepter 1.4.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
Expand All @@ -115,7 +115,7 @@ cases:
- [ '--version' ]
- cmd: run default -c .cargo/polkadot.yaml
stdout: |
zepter 1.4.0
zepter 1.4.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/config/v1/version_bin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cases:
- cmd: run default
stderr: |
thread 'main' panicked at src/cmd/run.rs:27:46:
Invalid config file: "Config file version is too new. The file requires at least version 2.0.0, but the current version is 1.4.0. Please update Zepter or ignore this check with `--check-cfg-compatibility=off`."
Invalid config file: "Config file version is too new. The file requires at least version 2.0.0, but the current version is 1.4.1. Please update Zepter or ignore this check with `--check-cfg-compatibility=off`."
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
code: 101
- cmd: run default --check-cfg-compatibility=off
Expand All @@ -13,7 +13,7 @@ cases:
stderr: |
[INFO] Running workflow 'default'
thread 'main' panicked at src/cmd/run.rs:27:46:
Invalid config file: "Config file version is too new. The file requires at least version 2.0.0, but the current version is 1.4.0. Please update Zepter or ignore this check with `--check-cfg-compatibility=off`."
Invalid config file: "Config file version is too new. The file requires at least version 2.0.0, but the current version is 1.4.1. Please update Zepter or ignore this check with `--check-cfg-compatibility=off`."
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
code: 1
configs:
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/root-args/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ crates: []
cases:
- cmd: --version
stdout: |
zepter 1.4.0
zepter 1.4.1
- cmd: -V
stdout: |
zepter 1.4.0
zepter 1.4.1

0 comments on commit c72cce2

Please sign in to comment.