forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cargo_check_dependencies.sh
executable file
·40 lines (35 loc) · 1.5 KB
/
cargo_check_dependencies.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# Copyright © Aptos Foundation
# Parts of the project are originally copyright © Meta Platforms, Inc.
# SPDX-License-Identifier: Apache-2.0
# This script assumes it runs in the same directory as a Cargo.toml file
# and sees if this Cargo.toml file can operate without some of its
# dependencies using repeated `cargo check --all-targets` attempts.
#
# In order to run this in a directory containing multiple Cargo.toml files,
# we could suggest:
# find ./ -name Cargo.toml -execdir /path/to/$(basename $0) \;
# Requirements:
# https://github.com/killercup/cargo-edit << `cargo install cargo-edit`
# awk, bash, git
# This will make one local commit per removable dependency. It is advised to
# squash those dependency-removing commits into a single one.
if [ ! -f Cargo.toml ]; then
echo "Cargo.toml not found! Are you running this script in the right directory?"
fi
# Here, awk attempts to capture the dependency names among the [(build-|dev-)dependencies]
# blocks of the Cargo.toml
dependencies=$(awk 'x==1 {print } /\[(build-|dev-)?dependencies\]/ {x=1} /^$/ {x=0}' Cargo.toml| grep -Ev '(^$|^\[.+\]$)'| grep -Eo '^\w+')
echo "$dependencies"
for i in $dependencies; do
echo "testing removal of $i"
cargo rm "$i";
cargo check --all-targets --all-features
if (( $? == 0 )); then
echo "removal succeeded, committing"
git commit --no-gpg-sign -m "Removing $i from $(basename `pwd`)" --all;
else
echo "removal failed, rolling back"
git reset --hard
fi
done