This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
CI check against Rust feature bleed #12341
Merged
Merged
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
5c7dad6
CI check for rust feature bleed
ggwpez 9cb8642
Cargo not available
ggwpez 893e448
Handle missing programs
ggwpez 14976cc
Check for deps
ggwpez 7a886bc
Add doc
ggwpez 2ea9fc3
Use correct CI image
ggwpez af8065f
Remove --offline
ggwpez 3a137b5
Install cargo-workspaces
ggwpez 9639de6
Remove cargo-workspaces dep
ggwpez 5cf9457
Fix try-runtime feature
ggwpez 040dc23
Fix features
ggwpez 15e3ac5
Fix features
ggwpez c35256e
Fix more features...
ggwpez 447fe94
Merge remote-tracking branch 'origin/master' into oty-check-rust-featβ¦
ggwpez 1d4f80a
Use pipeline-script
ggwpez 8d597ec
π€‘
ggwpez ad2746a
Make stupid change to test the CI
ggwpez a6a8ed8
This reverts commit ad2746aa117fa7cb473521113a9bec89aaf26484.
ggwpez c4eb7d9
Use correct branch
ggwpez 8286209
Allow failure
ggwpez 16ec00e
Make stupid change to test the CI
ggwpez d9b5428
Revert "Make stupid change to test the CI"
ggwpez 7c8dc30
Merge remote-tracking branch 'origin/master' into oty-check-rust-featβ¦
ggwpez d7cb880
Merge remote-tracking branch 'origin/master' into oty-check-rust-featβ¦
ggwpez be0b8fe
Merge remote-tracking branch 'origin/master' into oty-check-rust-featβ¦
ggwpez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| #!/bin/bash | ||
|
|
||
| # This file is part of Substrate. | ||
| # Copyright (C) 2022 Parity Technologies (UK) Ltd. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| ####################################################################### | ||
| # | ||
| # This script checks that no crate enables a specific feature in its | ||
| # `default` feature set. It's important to check that since features | ||
| # are used to gate specific functionality which should only be enabled | ||
| # if the feature is present. | ||
| # | ||
| # Has `cargo-workspaces` as optional dependency: | ||
| # https://github.com/pksunkara/cargo-workspaces | ||
| # | ||
| # Invocation scheme: | ||
| # ./rust-features.sh <CARGO-ROOT-PATH> | ||
| # | ||
| # The steps of this script: | ||
| # 1. Check that all required dependencies are installed. | ||
| # 2. Check that all rules are fullfilled for the whole workspace. If not: | ||
| # 3. Print an error and check if `cargo-workspaces` is installed. If so: | ||
| # 4. List all crates and go through each one to find the offending crate. | ||
| # 5. Print all offending crates and exit with failure. | ||
| # | ||
| ####################################################################### | ||
|
|
||
| set -eu | ||
|
|
||
| # Check that cargo, grep and egrep are installed. | ||
| command -v cargo >/dev/null 2>&1 || { echo >&2 "cargo is required but not installed. Aborting."; exit 1; } | ||
| command -v grep >/dev/null 2>&1 || { echo >&2 "grep is required but not installed. Aborting."; exit 1; } | ||
| command -v egrep >/dev/null 2>&1 || { echo >&2 "egrep is required but not installed. Aborting."; exit 1; } | ||
|
|
||
| SUBSTRATE_ROOT=$1 | ||
| declare -a RULES=( | ||
| "default,std never implies runtime-benchmarks" | ||
| "default,std never implies try-runtime" | ||
| ) | ||
|
|
||
| function check_does_not_imply() { | ||
| ENABLED=$1 | ||
| STAYS_DISABLED=$2 | ||
| echo "π Checking that '$ENABLED' does not imply '$STAYS_DISABLED'" | ||
|
|
||
| RET=0 | ||
| # Check if the forbidden feature is enabled anywhere in the workspace. | ||
| cargo tree --no-default-features --locked --workspace -e features --features "$ENABLED" | grep -q "feature \"$STAYS_DISABLED\"" || RET=$? | ||
| if [ $RET -ne 0 ]; then | ||
| echo "β Feature '$ENABLED' does not imply '$STAYS_DISABLED' in the workspace" | ||
| return | ||
| else | ||
| echo "β Feature '$ENABLED' implies '$STAYS_DISABLED' in the workspace" | ||
| fi | ||
|
|
||
| # Check if `cargo-workspaces` is installed. | ||
| # If not, the user only gets a generic error instead of a nicer one. | ||
| if ! cargo workspaces --version > /dev/null 2>&1; then | ||
| echo "β Install 'cargo-workspaces' for a more detailed error message." | ||
| exit 1 | ||
| fi | ||
|
|
||
| CRATES=`cargo workspaces list --all | egrep -o '^(\w|-)+'` | ||
| FAILED=0 | ||
| PASSED=0 | ||
| echo "π Checking individual crates" | ||
|
|
||
| for CRATE in $CRATES; do | ||
| RET=0 | ||
| OUTPUT=$(cargo tree --no-default-features --locked -e features --features $ENABLED -p $CRATE 2>&1 || true) | ||
| IS_NOT_SUPPORTED=$(echo $OUTPUT | grep -q "not supported for packages in this workspace" || echo $?) | ||
|
|
||
| if [ $IS_NOT_SUPPORTED -eq 0 ]; then | ||
| # This case just means that the pallet does not support the | ||
| # requested feature which is fine. | ||
| PASSED=$((PASSED+1)) | ||
| elif echo "$OUTPUT" | grep -q "feature \"$STAYS_DISABLED\""; then | ||
| echo "β Feature '$ENABLED' implies '$STAYS_DISABLED' in $CRATE; enabled by" | ||
| echo "$OUTPUT" | grep -w "feature \"$STAYS_DISABLED\"" | head -n 1 | ||
| FAILED=$((FAILED+1)) | ||
| else | ||
| PASSED=$((PASSED+1)) | ||
| fi | ||
| done | ||
|
|
||
| TOTAL=$((PASSED + FAILED)) | ||
| echo "Checked $TOTAL crates in total of which $FAILED failed and $PASSED passed." | ||
|
|
||
| if [ $FAILED -ne 0 ]; then | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| cd "$SUBSTRATE_ROOT" | ||
|
|
||
| for RULE in "${RULES[@]}"; do | ||
| read -a splits <<< "$RULE" | ||
| check_does_not_imply "${splits[0]}" "${splits[3]}" | ||
| done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.