paritytech / substrate

Substrate: The platform for blockchain innovators
Apache License 2.0
8.39k stars 2.65k forks source link

Fix Substrate features #14660

Closed ggwpez closed 1 year ago

ggwpez commented 1 year ago

Trying to automatically fix std, runtime-benchmarks and try-runtime features with

zepter lint propagate-feature --feature try-runtime --left-side-feature-missing=ignore --workspace --fix --feature-enables-dep="try-runtime:frame-try-runtime"
zepter lint propagate-feature --feature runtime-benchmarks --left-side-feature-missing=ignore --workspace --fix --feature-enables-dep="runtime-benchmarks:frame-benchmarking"
zepter lint propagate-feature --feature std --left-side-feature-missing=ignore --workspace --fix

The auto-fixer tries to be as non-invasive as possible, but removes empty lines.

Explanation:

Known blindspot: The --workspace flag currently requires that both sides are in the workspace. This will be extended soon to also allow the right-hand-side dependency to be outside of the worspace. Since currently it does not detect serde/std as missing when the --workspace flag is present.

TODO:

shawntabrizi commented 1 year ago

Could we use Zepter to a little bit of toml formatting too?

For example organizing dependencies alphabetically?

ggwpez commented 1 year ago

Could we use Zepter to a little bit of toml formatting too?

For example organizing dependencies alphabetically?

Yes we definitely can. Currently the autofixer is written to not re-order anything, but it already has to touch the toml array, so it could be ordered as well.
Comments within the dependency array are lost, but i think that is a fine trade-off in this case.

koute commented 1 year ago

Comments within the dependency array are lost, but i think that is a fine trade-off in this case.

Could we make it so that they're not lost? (I assume there are toml libraries which can do this?)

ggwpez commented 1 year ago

Comments within the dependency array are lost, but i think that is a fine trade-off in this case.

Could we make it so that they're not lost? (I assume there are toml libraries which can do this?)

Oh, the official toml_edit crate actually mentions that it can preserve comment - so I must just be using it wrong. I will look into it, thanks!

ggwpez commented 1 year ago

bot merge

AurevoirXavier commented 1 year ago

cargo-featalign can address many of the situations mentioned in this thread such as preseving comments. Recently, I added support for sorting features alphabetically based on @shawntabrizi's comment.

However, I am unsure about how parity CI functions. I am eager to apply this tool to Substrate. cc @ggwpez

ggwpez commented 1 year ago

@AurevoirXavier you can check out the diff in scripts/ci/gitlab/pipeline/check.yml of this MR.
You can just add featalign alongside the Zepter invocation there into the same job. I am not a CI engie myself, but it should be fine.
The job currently takes 33 sec, it runs as one of the first jobs, but AFAIK it does not block later ones.

shawntabrizi commented 1 year ago

it would be great if these feature fix stuff was somehow integrated into the node-template, cumulus, and similar projects.

Then users would run something like ./scripts/fix-features.sh in their custom project and make sure they are doing everything right.