Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Rename to dev-context-only-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoqun committed Jul 4, 2023
1 parent fd2d6cf commit bf92965
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 39 deletions.
4 changes: 2 additions & 2 deletions ci/buildkite-pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ wait_step() {

all_test_steps() {
command_step checks1 ". ci/rust-version.sh; ci/docker-run.sh \$\$rust_nightly_docker_image ci/test-checks.sh" 20 check
command_step checks2 ". ci/rust-version.sh; ci/docker-run.sh \$\$rust_nightly_docker_image ci/test-dev-utils.sh check-bins" 15 check
command_step checks3 ". ci/rust-version.sh; ci/docker-run.sh \$\$rust_nightly_docker_image ci/test-dev-utils.sh check-all-targets" 15 check
command_step checks2 ". ci/rust-version.sh; ci/docker-run.sh \$\$rust_nightly_docker_image ci/test-dev-context-only-utils.sh check-bins" 15 check
command_step checks3 ". ci/rust-version.sh; ci/docker-run.sh \$\$rust_nightly_docker_image ci/test-dev-context-only-utils.sh check-all-targets" 15 check
wait_step

# Full test suite
Expand Down
2 changes: 1 addition & 1 deletion ci/test-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ else
_ scripts/cargo-for-all-lock-files.sh -- "+${rust_nightly}" sort --workspace --check
fi

_ scripts/check-dev-utils.sh tree
_ scripts/check-dev-context-only-utils.sh tree

_ scripts/cargo-for-all-lock-files.sh -- "+${rust_nightly}" fmt --all -- --check

Expand Down
5 changes: 5 additions & 0 deletions ci/test-dev-context-only-utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -eo pipefail

scripts/check-dev-context-only-utils.sh "$@"
5 changes: 0 additions & 5 deletions ci/test-dev-utils.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,32 @@ source ci/_
# (benches, frozen abi...)
source ci/rust-version.sh nightly

# There's a special common feature called `dev-utils` to
# There's a special common feature called `dev-context-only-utils` to
# overcome cargo's issue: https://github.com/rust-lang/cargo/issues/8379
# This feature is like `cfg(test)`, which works between crates.
#
# Unfortunately, this in turn needs some special checks to avoid common
# pitfalls of `dev-utils` itself.
# pitfalls of `dev-context-only-utils` itself.
#
# Firstly, detect any misuse of dev-utils as normal/build dependencies.
# Also, allow some exceptions for special purpose crates. This white-listing
# mechanism can be used for core-development-oriented crates like bench bins.
# Firstly, detect any misuse of dev-context-only-utils as normal/build
# dependencies. Also, allow some exceptions for special purpose crates. This
# white-listing mechanism can be used for core-development-oriented crates like
# bench bins.
#
# Put differently, use of dev-utils is forbidden for non-dev dependencies in
# general. However, allow its use for non-dev dependencies only if its use
# is confined under a dep. subgraph with all nodes being marked as dev-utils.
# Put differently, use of dev-context-only-utils is forbidden for non-dev
# dependencies in general. However, allow its use for non-dev dependencies only
# if its use is confined under a dep. subgraph with all nodes being marked as
# dev-context-only-utils.

# Add your troubled package which seems to want to use `dev-utils` as normal (not
# dev) dependencies, only if you're sure that there's good reason to bend
# dev-util's original intention and that listed package isn't part of released
# binaries.
declare -r dev_utils_feature="dev-utils"
declare dev_util_tainted_packages=(
# Add your troubled package which seems to want to use `dev-context-only-utils`
# as normal (not dev) dependencies, only if you're sure that there's good
# reason to bend dev-context-only-utils's original intention and that listed
# package isn't part of released binaries.
declare tainted_packages=(
)

# convert to comma separeted (ref: https://stackoverflow.com/a/53839433)
printf -v allowed '"%s",' "${dev_util_tainted_packages[@]}"
printf -v allowed '"%s",' "${tainted_packages[@]}"
allowed="${allowed%,}"

mode=${1:-full}
Expand Down Expand Up @@ -60,7 +61,7 @@ if [[ $mode = "tree" || $mode = "full" ]]; then
| flatten
| map(select(
(.dependencyFeatures
| index("${dev_utils_feature}")
| index("dev-context-only-utils")
) and (.crate as \$needle
| ([$allowed] | index(\$needle))
| not
Expand All @@ -71,10 +72,11 @@ if [[ $mode = "tree" || $mode = "full" ]]; then
EOF
)

abusers="$(_ cargo "+${rust_nightly}" metadata --format-version=1 | jq -r "$query")"
abusers="$(_ cargo "+${rust_nightly}" metadata --format-version=1 |
jq -r "$query")"
if [[ -n "$abusers" ]]; then
cat <<EOF 1>&2
${dev_utils_feature} must not be used as normal dependencies, but is by \
dev-context-only-utils must not be used as normal dependencies, but is by \
"([crate]: [dependency])":
$abusers
EOF
Expand Down Expand Up @@ -106,7 +108,7 @@ EOF
end)
| flatten
| map(select(
(.crateFeatures | index("${dev_utils_feature}")) | not
(.crateFeatures | index("dev-context-only-utils")) | not
))
| map(.crate)
| join("\n ")
Expand All @@ -121,25 +123,27 @@ EOF
if [[ -n "$misconfigured_crates" ]]; then
cat <<EOF 1>&2
All crates marked \`tainted\`, as well as their dependents, MUST declare the \
\`$dev_utils_feature\`. The following crates are in violation:
\`dev-context-only-utils`. The following crates are in violation:
$misconfigured_crates
EOF
exit 1
fi
fi
# Detect possible compilation errors of problematic usage of `dev-utils`-gated code
# without being explicitly declared as such in respective workspace member
# `Cargo.toml`s. This cannot be detected with `--workspace --all-targets`, due
# to unintentional `dev-utils` feature activation by cargo's feature
# unification mechanism.
# So, we use `cargo hack` to exhaustively build each individual workspace
# members in isolation to work around.
# Detect possible compilation errors of problematic usage of
# `dev-context-only-utils`-gated code without being explicitly declared as such
# in respective workspace member `Cargo.toml`s. This cannot be detected with
# `--workspace --all-targets`, due to unintentional `dev-context-only-utils`
# feature activation by cargo's feature unification mechanism. So, we use
# `cargo hack` to exhaustively build each individual workspace members in
# isolation to work around.
#
# 1. Check implicit usage of `dev-utils`-gated code in non-dev (= production) code by
# building without dev dependencies (= tests/benches) for each crate
# 2. Check implicit usage of `dev-utils`-gated code in dev (= test/benches) code by
# building in isolation from other crates, which might happen to enable `dev-utils`
# 1. Check implicit usage of `dev-context-only-utils`-gated code in non-dev (=
# production) code by building without dev dependencies (= tests/benches) for
# each crate
# 2. Check implicit usage of `dev-context-only-utils`-gated code in dev (=
# test/benches) code by building in isolation from other crates, which might
# happen to enable `dev-context-only-utils`
if [[ $mode = "check-bins" || $mode = "full" ]]; then
_ cargo "+${rust_nightly}" hack check --bins
fi
Expand Down

0 comments on commit bf92965

Please sign in to comment.