Debian Codegraph @

debian/gbp-repack-mozjs-source.sh

raw
1 #!/bin/bash
2 # This script is meant to be called by gbp import-orig as postunpack cmd, and
3 # it uses official mozilla tooling to create the mozjs archive from a firefox
4 # source tarball, including only the needed files without having us to care
5 # about doing this filtering.
6 #
7 # We depend on bash here, because the script we call depends on it anyways.
8 set -xe
9
10 [ -d "$GBP_TMP_DIR" ] || exit 1
11
12 export STAGING="$GBP_TMP_DIR"
13 export DIST=/dev/null
14 export MOZJS_NAME="mozjs-repack"
15
16 export RSYNC=${RSYNC:-rsync}
17 # Don't create another archive
18 export TAR=/bin/true
19
20 EXTRA_FILES=(
21 intl/icu
22 intl/icu-patches
23 intl/icu_sources_data.py
24 )
25
26 FILTERED_FILES=(
27 '__pycache__'
28 '*.chm'
29 '*.dll'
30 '*.exe'
31 '*.pyd'
32 '*.a'
33 '*.so'
34 '*.o'
35 )
36
37 if [ -z "$GBP_SOURCES_DIR" ]; then
38 echo "\$GBP_SOURCES_DIR is not defined, need a newer gbp version"
39 exit 1
40 fi
41
42 debpath="$(dirname "$0")"
43
44 for i in $(grep-dctrl -s Files-Excluded -n - 2> /dev/null < "$debpath/copyright"); do
45 FILTERED_FILES+=("./$i")
46 done
47
48 srcpath="$GBP_SOURCES_DIR"
49 "$srcpath"/js/src/make-source-package.py
50
51 mozjspath="$(find "$STAGING" -mindepth 1 -maxdepth 1 -type d -name "$MOZJS_NAME"'-*')"
52 set +x
53
54 for ((i = 0; i < ${#EXTRA_FILES[@]}; i++)); do
55 $RSYNC -a -q "$srcpath/${EXTRA_FILES[$i]}" \
56 "$mozjspath/$(dirname "${EXTRA_FILES[$i]}")/"
57 done
58
59 for ((i = 0; i < ${#FILTERED_FILES[@]}; i++)); do
60 find_args=()
61 [[ "${FILTERED_FILES[$i]}" == .* ]] && find_args=(-mindepth 1 -maxdepth 1)
62 find "$mozjspath/$(dirname "${FILTERED_FILES[$i]}")" \
63 "${find_args[@]}" \
64 -name "$(basename "${FILTERED_FILES[$i]}")" \
65 -exec rm -rfv "{}" \; || true
66 done
67
68 find "$mozjspath" -type d -empty -delete
69
70 tmpout=$(mktemp /tmp/mozjs-debimport-XXXXXXXXX.diff)
71 echo "Differences found with orig saved at $tmpout, consider adjusting filters"
72 diff -rq "$srcpath" "$mozjspath" > "$tmpout" || true
73
74 rm -rf "$srcpath"
75 mv -v "$mozjspath" "$srcpath"