Skip to content

Commit

Permalink
Limit cargo sort to only modify incorrect files. (#3595)
Browse files Browse the repository at this point in the history
By default `cargo sort` will *always* re-write every `Cargo.toml` file
it processes. This causes the build system to see the files changed and
results in re-compiling unnecessarily. Now `cargo sort` will only update
a file if it deviates from the desired sorting order.
  • Loading branch information
nick-mobilecoin authored Oct 2, 2023
1 parent 2f72082 commit 5b39e4a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 13 deletions.
4 changes: 2 additions & 2 deletions crypto/ake/enclave/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ license = "GPL-3.0"
rust-version = { workspace = true }

[dependencies]
mc-attest-core = { path = "../../../attest/core", default-features = false }
mc-attest-ake = { path = "../../../attest/ake", default-features = false }
mc-attest-core = { path = "../../../attest/core", default-features = false }
mc-attest-enclave-api = { path = "../../../attest/enclave-api", default-features = false }
mc-attest-trusted = { path = "../../../attest/trusted", default-features = false }
mc-attest-verifier = { path = "../../../attest/verifier", default-features = false }
mc-common = { path = "../../../common", default-features = false }
mc-crypto-keys = { path = "../../../crypto/keys", default-features = false }
mc-rand = "1.0"
mc-sgx-compat = { path = "../../../sgx/compat", default-features = false }
mc-util-from-random = { path = "../../../util/from-random" }
mc-util-serial = { path = "../../../util/serial" }
mc-sgx-compat = { path = "../../../sgx/compat", default-features = false }

aes-gcm = "0.10.1"
digest = "0.10"
Expand Down
2 changes: 1 addition & 1 deletion crypto/hashes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
rust-version = { workspace = true }

[features]
default = [ "mc-crypto-digestible/default" ]
default = ["mc-crypto-digestible/default"]

[dependencies]
mc-crypto-digestible = { path = "../digestible", default_features = false }
Expand Down
2 changes: 1 addition & 1 deletion fog/ingest/server/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ rust-version = { workspace = true }
[dependencies]
# MC/root
mc-attest-net = { path = "../../../../attest/net" }
mc-blockchain-types = { path = "../../../../blockchain/types" }
mc-blockchain-test-utils = { path = "../../../../blockchain/test-utils" }
mc-blockchain-types = { path = "../../../../blockchain/types" }
mc-common = { path = "../../../../common", features = ["loggers"] }
mc-crypto-keys = { path = "../../../../crypto/keys", default-features = false }
mc-ledger-db = { path = "../../../../ledger/db" }
Expand Down
4 changes: 2 additions & 2 deletions fog/ledger/test_infra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ mc-common = { path = "../../../common" }
mc-crypto-keys = { path = "../../../crypto/keys" }
mc-ledger-db = { path = "../../../ledger/db" }
mc-sgx-report-cache-api = { path = "../../../sgx/report-cache/api" }
mc-transaction-core = { path = "../../../transaction/core" }
mc-transaction-core = { path = "../../../transaction/core" }

# fog
mc-fog-ledger-enclave = { path = "../enclave" }
mc-fog-ledger-enclave = { path = "../enclave" }
mc-fog-ledger-enclave-api = { path = "../enclave/api" }
mc-fog-types = { path = "../../types" }

Expand Down
4 changes: 2 additions & 2 deletions sgx/compat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ rust-version = "1.68.0"
[dependencies]
cfg-if = "1.0"
mc-sgx-alloc = { path = "../alloc", optional = true }
mc-sgx-panic = { path = "../panic", optional = true }
mc-sgx-sync = { path = "../sync", optional = true }
mc-sgx-debug = { path = "../debug", optional = true }
mc-sgx-panic = { path = "../panic", optional = true }
mc-sgx-service = { path = "../service", optional = true }
mc-sgx-sync = { path = "../sync", optional = true }
mc-sgx-types = { path = "../types" }

[features]
Expand Down
2 changes: 1 addition & 1 deletion sgx/sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ readme = "README.md"
rust-version = "1.68.0"

[dependencies]
mc-sgx-types = { path = "../types" }
mc-sgx-panic = { path = "../panic", optional = true }
mc-sgx-types = { path = "../types" }

[features]
default = ["mc-sgx-panic"]
22 changes: 19 additions & 3 deletions tools/lint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright (c) 2018-2022 The MobileCoin Foundation
# Copyright (c) 2018-2023 The MobileCoin Foundation

set -e # exit on error

Expand Down Expand Up @@ -35,7 +35,6 @@ cargo install --version 1.0.9 --locked cargo-sort

# We want to check with --all-targets since it checks test code, but that flag
# leads to build errors in enclave workspaces, so check it here.
cargo sort --workspace --grouped $CHECK
cargo fmt -- --unstable-features $CHECK
cargo clippy --all --all-features --all-targets -- -D warnings

Expand All @@ -44,9 +43,26 @@ cargo clippy --all --all-features --all-targets -- -D warnings
for toml in $(find . -mindepth 2 -type f -not -path '*/cargo/*' -name Cargo.toml -exec grep -l -e '\[workspace\]' {} +); do
pushd $(dirname $toml) >/dev/null
echo "Linting in $PWD"
cargo sort --workspace --grouped $CHECK
cargo fmt -- --unstable-features $CHECK
cargo clippy --all --all-features -- -D warnings
echo "Linting in $PWD complete."
popd >/dev/null
done

# `cargo sort` is a bit too aggressive at modifying files. When not provided the
# `--check` flag it will *always* re-write the files it's sorting. This results
# in cargo seeing the `Cargo.toml` files as modified and often requiring a
# rebuild of a package. To work around this, we first check and only if it fails
# will we fix. We operate on each `Cargo.toml` file individually to minimize the
# incremental build impact of fixing a file.
SORT_COMMAND="cargo sort --grouped --check"
if [ -z "$CHECK" ]
then
SORT_COMMAND="$SORT_COMMAND || cargo sort --grouped"
fi

for toml in $(find . -type f -not -path '*/cargo/*' -name Cargo.toml); do
pushd $(dirname $toml) >/dev/null
eval $SORT_COMMAND
popd >/dev/null
done
2 changes: 1 addition & 1 deletion util/serial/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ prost = { version = "0.12", default-features = false, features = ["prost-derive"
protobuf = { version = "2.27", optional = true }
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
serde_cbor = { version = "0.11.1", default-features = false, features = ["alloc"] }
serde_with = { version = "3.1", default-features = false, features = ["macros"], optional = true}
serde_with = { version = "3.1", default-features = false, features = ["macros"], optional = true }

[dev-dependencies]
serde_json = "1.0"

0 comments on commit 5b39e4a

Please sign in to comment.