File: prune-unused-deps

package info (click to toggle)
rustc 1.48.0+dfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, experimental, sid
  • size: 275,960 kB
  • sloc: xml: 147,652; ansic: 16,929; sh: 16,839; javascript: 6,817; python: 6,021; cpp: 4,663; makefile: 3,284; asm: 1,437; ruby: 68; awk: 12
file content (63 lines) | stat: -rwxr-xr-x 1,991 bytes parent folder | download | duplicates (3)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/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
rm -f Cargo.lock
find vendor -name .cargo-checksum.json -execdir "$scriptdir/debian/prune-checksums" "{}" +
sed -i -e 's/dev: 1/#dev: 1/g' src/stage0.txt # allow beta builds
./x.py build nonexistent/path/to/trigger/cargo/metadata src/bootstrap

massage_lock_file() {
	sed -z -e 's/\nname = /name = /g' -e 's/\nversion = /version = /g' "$1"
}

not_needed() {
	diff -ru <(massage_lock_file Cargo.lock.orig) <(massage_lock_file Cargo.lock) \
	  | 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 -F -f <(not_needed) | 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"