summaryrefslogtreecommitdiffstats
path: root/debian/prune-unused-deps
diff options
context:
space:
mode:
Diffstat (limited to 'debian/prune-unused-deps')
-rwxr-xr-xdebian/prune-unused-deps73
1 files changed, 73 insertions, 0 deletions
diff --git a/debian/prune-unused-deps b/debian/prune-unused-deps
new file mode 100755
index 000000000..32063b14e
--- /dev/null
+++ b/debian/prune-unused-deps
@@ -0,0 +1,73 @@
+#!/bin/bash
+# Run this script in an unpacked upstream tarball directory, and it will update
+# (i.e. overwrite) the "unused deps" part of Files-Excluded in d/copyright.
+
+set -e
+
+scriptdir=$(dirname "$(dirname "$(readlink -f "$0")")")
+had_config_toml=$(if test -e "$scriptdir/debian/config.toml"; then echo true; else echo false; fi)
+
+( cd "$scriptdir" && debian/rules debian/config.toml )
+cp "$scriptdir/debian/config.toml" config.toml
+
+for i in "$scriptdir/debian/patches"/d-00*.patch; do
+ "$scriptdir/debian/ensure-patch" -N "$i"
+done
+
+test -f Cargo.lock.orig || cp Cargo.lock Cargo.lock.orig
+test -f src/bootstrap/Cargo.lock.orig || cp src/bootstrap/Cargo.lock src/bootstrap/Cargo.lock.orig
+test -f src/tools/rust-analyzer/Cargo.lock.orig || cp src/tools/rust-analyzer/Cargo.lock src/tools/rust-analyzer/Cargo.lock.orig
+rm -f Cargo.lock src/bootstrap/Cargo.lock src/tools/rust-analyzer/Cargo.lock
+
+find vendor -name .cargo-checksum.json -execdir "$scriptdir/debian/prune-checksums" "{}" +
+
+# re-generate Cargo.lock after patching
+cargo update --offline
+
+# re-generate src/bootstrap/Cargo.lock after patching
+(cd src/bootstrap && cargo update --offline)
+
+# re-generate src/tools/rust-analyzer/Cargo.lock after patching
+( cd src/tools/rust-analyzer && cargo update --offline )
+
+needed_crates() {
+ cat Cargo.lock \
+ src/bootstrap/Cargo.lock \
+ src/tools/rust-analyzer/Cargo.lock \
+ | sed -z -e 's/\nname = /name = /g' -e 's/\nversion = /version = /g' \
+ | sed -ne 's/\[\[package\]\]name = "\(.*\)"version = "\(.*\)"/\1 \2/gp'
+}
+
+ghetto_parse_cargo() {
+ cat "$1" \
+ | tr '\n' '\t' \
+ | sed -e 's/\t\[/\n[/g' \
+ | perl -ne 'print if s/^\[(?:package|project)\].*\tname\s*=\s*"(.*?)".*\tversion\s*=\s*"(.*?)".*/\1 \2/g'
+}
+
+pruned_paths() {
+ for i in vendor/*/Cargo.toml; do
+ pkgnamever=
+ pkgnamever=$(ghetto_parse_cargo "$i")
+ if [ -z "$pkgnamever" ]; then
+ echo >&2 "failed to parse: $i"
+ exit 1
+ fi
+ echo "$pkgnamever $i"
+ done | grep -v -F -f <(needed_crates) | cut '-d ' -f3 | while read x; do
+ echo " $(dirname $x)"
+ done
+}
+
+header='# DO NOT EDIT below, AUTOGENERATED'
+footer='# DO NOT EDIT above, AUTOGENERATED'
+{
+echo "$header"
+pruned_paths
+echo "$footer"
+} > $scriptdir/debian/copyright.unused-deps
+
+cd $scriptdir/debian
+sed -i -e "/^$header/,/^$footer/d" -e '/^# unused dependencies/rcopyright.unused-deps' copyright
+rm copyright.unused-deps
+$had_config_toml || rm "$scriptdir/debian/config.toml"