Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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: 1 addition & 1 deletion .github/workflows/downstream_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
matrix:
repo: ["paritytech/polkadot-sdk", "open-web3-stack/open-runtime-module-library"]
version: [0.13.3, 1.4.0, "*"]
version: [1.78.0, 1.82.0, "*"]

steps:
- uses: actions/checkout@master
Expand Down
22 changes: 22 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#ffeb33",
"activityBar.background": "#ffeb33",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#009f90",
"activityBarBadge.foreground": "#e7e7e7",
"commandCenter.border": "#15202b99",
"sash.hoverBorder": "#ffeb33",
"statusBar.background": "#ffe600",
"statusBar.foreground": "#15202b",
"statusBarItem.hoverBackground": "#ccb800",
"statusBarItem.remoteBackground": "#ffe600",
"statusBarItem.remoteForeground": "#15202b",
"titleBar.activeBackground": "#ffe600",
"titleBar.activeForeground": "#15202b",
"titleBar.inactiveBackground": "#ffe60099",
"titleBar.inactiveForeground": "#15202b99"
},
"peacock.color": "#ffe600"
}
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zepter"
version = "1.82.0"
version = "1.82.1"
edition = "2021"
authors = [ "Oliver Tale-Yazdi" ]
description = "Analyze, Fix and Format features in your Rust workspace."
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ When these two experiments proove the usefulness and reliability of Zepter for C
## Testing

Unit tests: `cargo test`
UI and downstream integration tests: `cargo test -- --ignored`
UI and downstream integration tests: `cargo test -- --ignored --nocapture`

Environment overwrites exist for the UI tests to:
- `OVERWRITE`: Update the UI diff locks.
Expand Down
60 changes: 57 additions & 3 deletions src/cmd/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub struct PropagateFeatureCmd {
#[clap(long, short, num_args(0..))]
packages: Vec<String>,

/// The auto-fixer will enables the feature of the dependencies as non-optional.
/// Enables the feature of the dependencies as non-optional.
///
/// This can be used in case that a dependency should not be enabled like `dep?/feature` but
/// like `dep/feature` instead. In this case you would pass `--feature-enables-dep
Expand Down Expand Up @@ -471,6 +471,8 @@ impl PropagateFeatureCmd {
let dep_kinds = self.parse_dep_kinds().expect("Parse dependency kinds");
// (Crate that missing the feature) -> (Dependency that has it)
let mut feature_missing = BTreeMap::<CrateId, BTreeSet<RenamedPackage>>::new();
// (Crate that is not enabling a optional dependency) -> (Dependency that it is not enabled)
let mut non_optional_missing = BTreeMap::<CrateId, BTreeSet<RenamedPackage>>::new();

for pkg in to_check.iter() {
// TODO that it does not enable other features.
Expand All @@ -492,9 +494,31 @@ impl PropagateFeatureCmd {
continue
};

// If optional and require by `feature-enables-dep` but does not have the feature,
// then we need to enable it as non-optional.
if dep.optional {
if let Some((feature, _)) = self
.feature_enables_dep
.iter()
.flatten()
.find(|(f, name)| *f == feature && *name == dep.name())
{
if !dep.pkg.features.contains_key(feature) &&
!pkg.features.get(feature).is_some_and(|f| f.contains(&dep.name()))
{
non_optional_missing
.entry(pkg.id.to_string())
.or_default()
.insert(dep.clone());
}
}
// Continue here should not make a difference. TODO check.
}

if !dep.pkg.features.contains_key(&feature) {
continue
}

if !pkg.features.contains_key(&feature) {
if self.left_side_feature_missing != MuteSetting::Ignore {
feature_missing.entry(pkg.id.to_string()).or_default().insert(dep);
Expand Down Expand Up @@ -542,8 +566,12 @@ impl PropagateFeatureCmd {
propagate_missing.entry(pkg.id.to_string()).or_default().insert(dep);
}
}
let faulty_crates: BTreeSet<CrateId> =
propagate_missing.keys().chain(feature_missing.keys()).cloned().collect();
let faulty_crates: BTreeSet<CrateId> = propagate_missing
.keys()
.chain(feature_missing.keys())
.chain(non_optional_missing.keys())
.cloned()
.collect();
let mut faulty_crates =
faulty_crates.into_iter().map(|id| (lookup(&id), id)).collect::<Vec<_>>();
faulty_crates.sort_by(|(a, _), (b, _)| a.name.cmp(&b.name));
Expand Down Expand Up @@ -632,6 +660,32 @@ impl PropagateFeatureCmd {
}
errors += deps.len();
}

if let Some(deps) = non_optional_missing.get(&krate.id.to_string()) {
let mut named = deps.iter().map(RenamedPackage::display_name).collect::<Vec<_>>();
named.sort();
println!(
" must enable dependency as non-optional:\n {}",
named.join("\n ")
);

if self.fixer_args.enable &&
self.fix_package.as_ref().is_none_or(|p| p == &krate.name.to_string())
{
for dep in deps.iter() {
let dep_name = dep.name();
let Some(fixer) = fixer.as_mut() else { continue };

fixer.add_to_feature(&feature, &dep_name).unwrap();

log::info!("Inserted '{dep_name}' into '{}'", krate.name);
fixes += 1;
}
}

errors += deps.len();
}

if let Some(fixer) = fixer.as_mut() {
if fixes > 0 {
fixer.save().unwrap();
Expand Down
7 changes: 6 additions & 1 deletion src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct GlobalArgs {

/// Try to exit with code zero if the intended check failed.
///
/// Will still return 1 in case of an actual error (eg. failed to find some file) or a panic
/// Will still return != 0 in case of an actual error (eg. failed to find some file) or a panic
/// (aka software bug).
#[clap(long, global = true, verbatim_doc_comment)]
exit_code_zero: bool,
Expand Down Expand Up @@ -145,6 +145,11 @@ impl GlobalArgs {
}
}

/// Error code when the config file is invalid or incompatible.
pub fn error_code_cfg_parsing() -> i32 {
101
}

pub fn red(&self, s: &str) -> String {
if !self.color {
s.to_string()
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct RunArgs {

impl RunCmd {
pub fn run(&self, g: &GlobalArgs) {
let config = self.args.config.load().expect("Invalid config file");
let config = self.args.config.load_or_panic();

let name = self.args.workflow.as_deref().unwrap_or(WORKFLOW_DEFAULT_NAME);
let Some(workflow) = config.workflow(name) else {
Expand Down
9 changes: 8 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pub mod semver;
pub mod workflow;

use crate::{config::workflow::WorkflowFile, log, ErrToStr};
use crate::{cmd::GlobalArgs, config::workflow::WorkflowFile, log, ErrToStr};

use std::{
fs::canonicalize,
Expand Down Expand Up @@ -72,6 +72,13 @@ pub fn search_config<P: AsRef<Path>>(workspace: P) -> Result<PathBuf, Vec<PathBu
}

impl ConfigArgs {
pub fn load_or_panic(&self) -> WorkflowFile {
self.load().unwrap_or_else(|e| {
eprintln!("{e}");
std::process::exit(GlobalArgs::error_code_cfg_parsing());
})
}

pub fn load(&self) -> Result<WorkflowFile, String> {
let path = self.locate_config()?;
log::debug!("Using config file: {path:?}");
Expand Down
6 changes: 3 additions & 3 deletions src/config/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ impl WorkflowFile {
pub fn check_cfg_compatibility(&self) -> Result<(), String> {
let current_version =
Semver::try_from(clap::crate_version!()).expect("Crate version is valid semver");
let file_version = self.version.binary;
let required_version = self.version.binary;

if current_version.is_newer_or_equal(&file_version) {
if current_version.is_newer_or_equal(&required_version) {
Ok(())
} else {
Err(format!(
"Config file version is too new. The file requires at least version {file_version}, but the current version is {current_version}. Please update Zepter or ignore this check with `--check-cfg-compatibility=off`."
"Your version of Zepter is too old for this project.\n\n Required: {required_version}\n Installed: {current_version}\n\nPlease update Zepter with:\n\n cargo install zepter --locked\n\nOr add `--check-cfg-compatibility=off` to the config file."
))
}
}
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.82.0
zepter 1.82.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
- cmd: run
stdout: |
zepter 1.82.0
zepter 1.82.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
- cmd: ''
stdout: |
zepter 1.82.0
zepter 1.82.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
- cmd: run my_version
stdout: |
zepter 1.82.0
zepter 1.82.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.82.0
zepter 1.82.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.82.0
zepter 1.82.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
Expand All @@ -19,7 +19,7 @@ cases:
- [ '--version' ]
- cmd: ''
stdout: |
zepter 1.82.0
zepter 1.82.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
Expand All @@ -35,7 +35,7 @@ cases:
- [ '--version' ]
- cmd: ''
stdout: |
zepter 1.82.0
zepter 1.82.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
Expand All @@ -51,7 +51,7 @@ cases:
- [ '--version' ]
- cmd: run default
stdout: |
zepter 1.82.0
zepter 1.82.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
Expand All @@ -67,7 +67,7 @@ cases:
- [ '--version' ]
- cmd: run default
stdout: |
zepter 1.82.0
zepter 1.82.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
Expand All @@ -83,7 +83,7 @@ cases:
- [ '--version' ]
- cmd: run default
stdout: |
zepter 1.82.0
zepter 1.82.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.82.0
zepter 1.82.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.82.0
zepter 1.82.1
stderr: |
[INFO] Running workflow 'default'
[INFO] 1/1 --version
Expand Down
26 changes: 19 additions & 7 deletions tests/ui/config/v1/version_bin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,33 @@ crates:
- name: A
cases:
- cmd: run default
stderr: |2
stderr: |
Your version of Zepter is too old for this project.

Required: 2.0.0
Installed: 1.82.1

Please update Zepter with:

cargo install zepter --locked

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.82.0. Please update Zepter or ignore this check with `--check-cfg-compatibility=off`."
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Or add `--check-cfg-compatibility=off` to the config file.
code: 101
- cmd: run default --check-cfg-compatibility=off
stdout: |
Error: Command '' failed with exit code 101
stderr: |
[INFO] Running workflow 'default'
Your version of Zepter is too old for this project.

Required: 2.0.0
Installed: 1.82.1

Please update Zepter with:

cargo install zepter --locked

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.82.0. Please update Zepter or ignore this check with `--check-cfg-compatibility=off`."
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Or add `--check-cfg-compatibility=off` to the config file.
code: 1
configs:
- to_path: .zepter.yaml
Expand Down
7 changes: 2 additions & 5 deletions tests/ui/config/v1/version_file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ crates:
- name: A
cases:
- cmd: run default
stderr: |2

thread 'main' panicked at src/cmd/run.rs:27:46:
Invalid config file: "Can only parse workflow files with version '1'"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
stderr: |
Can only parse workflow files with version '1'
code: 101
configs:
- to_path: .zepter.yaml
Expand Down
Loading