Blame SOURCES/llhttp-packaging-bundler

rdobuilder 30d276
#!/bin/bash
rdobuilder 30d276
set -o nounset
rdobuilder 30d276
set -o errexit
rdobuilder 30d276
rdobuilder 30d276
OUTPUT_DIR="$(rpm -E '%{_sourcedir}')"
rdobuilder 30d276
SPEC_FILE="${PWD}/llhttp.spec"
rdobuilder 30d276
rdobuilder 30d276
usage() {
rdobuilder 30d276
  cat 1>&2 <
rdobuilder 30d276
Usage: $(basename "$0")
rdobuilder 30d276
rdobuilder 30d276
Given llhttp.spec in the working directory, download the source and the prod
rdobuilder 30d276
and dev dependencies, each in their own tarball.
rdobuilder 30d276
rdobuilder 30d276
Also finds licenses for prod dependencies.
rdobuilder 30d276
rdobuilder 30d276
All three tarballs and the license list are copied to
rdobuilder 30d276
${OUTPUT_DIR}.
rdobuilder 30d276
EOF
rdobuilder 30d276
  exit 1
rdobuilder 30d276
}
rdobuilder 30d276
rdobuilder 30d276
if ! [[ -f /usr/bin/npm ]]
rdobuilder 30d276
then 
rdobuilder 30d276
  cat 1>&2 <
rdobuilder 30d276
$(basename "${0}") requires npm to run
rdobuilder 30d276
rdobuilder 30d276
Run the following to fix this:
rdobuilder 30d276
  sudo dnf install npm
rdobuilder 30d276
rdobuilder 30d276
EOF
rdobuilder 30d276
  exit 2
rdobuilder 30d276
fi 
rdobuilder 30d276
rdobuilder 30d276
if [[ $# -gt 0 ]]; then 
rdobuilder 30d276
  usage
rdobuilder 30d276
fi 
rdobuilder 30d276
rdobuilder 30d276
TMP_DIR="$(mktemp -d -t ci-XXXXXXXXXX)"
rdobuilder 30d276
trap "cd /; rm -rf '${TMP_DIR}'" INT TERM EXIT
rdobuilder 30d276
cd "${TMP_DIR}"
rdobuilder 30d276
rdobuilder 30d276
echo "Reading ${SPEC_FILE}; downloading source archive" 1>&2
rdobuilder 30d276
VERSION="$(awk '$1 == "Version:" { print $2; exit }' "${SPEC_FILE}")"
rdobuilder 30d276
echo "Version is ${VERSION}" 1>&2
rdobuilder 30d276
echo "Downloading source archive" 1>&2
rdobuilder 30d276
spectool -g "${SPEC_FILE}"
rdobuilder 30d276
rdobuilder 30d276
ARCHIVE="$(
rdobuilder 30d276
  find . -mindepth 1 -maxdepth 1 -type f -name '*.tar.gz' -print -quit
rdobuilder 30d276
)"
rdobuilder 30d276
echo "Downloaded $(basename "${ARCHIVE}")" 1>&2
rdobuilder 30d276
rdobuilder 30d276
tar -xzf "${ARCHIVE}"
rdobuilder 30d276
XDIR="$(find . -mindepth 1 -maxdepth 1 -type d -print -quit)"
rdobuilder 30d276
echo "Extracted to $(basename "${XDIR}")" 1>&2
rdobuilder 30d276
rdobuilder 30d276
cd "${XDIR}"
rdobuilder 30d276
rdobuilder 30d276
echo "Downloading prod dependencies" 1>&2
rdobuilder 30d276
# Compared to nodejs-packaging-bundler, we must add --ignore-scripts or npm
rdobuilder 30d276
# unsuccessfully attempts to build the package.
rdobuilder 30d276
npm install --no-optional --only=prod --ignore-scripts
rdobuilder 30d276
echo "Successful prod dependencies download" 1>&2
rdobuilder 30d276
mv node_modules/ node_modules_prod
rdobuilder 30d276
rdobuilder 30d276
echo "LICENSES IN BUNDLE:"
rdobuilder 30d276
LICENSE_FILE="${TMP_DIR}/llhttp-${VERSION}-bundled-licenses.txt"
rdobuilder 30d276
find . -name 'package.json' -exec jq '.license | strings' '{}' ';' \
rdobuilder 30d276
    >> "${LICENSE_FILE}"
rdobuilder 30d276
for what in '.license | objects | .type' '.licenses[] .type'
rdobuilder 30d276
do
rdobuilder 30d276
  find . -name 'package.json' -exec jq "${what}" '{}' ';' \
rdobuilder 30d276
      >> "${LICENSE_FILE}" 2>/dev/null
rdobuilder 30d276
done
rdobuilder 30d276
sort -u -o "${LICENSE_FILE}" "${LICENSE_FILE}"
rdobuilder 30d276
rdobuilder 30d276
# Locate any dependencies without a provided license
rdobuilder 30d276
find . -type f -name 'package.json' -execdir jq \
rdobuilder 30d276
    'if .license==null and .licenses==null then .name else null end' '{}' '+' |
rdobuilder 30d276
  grep -vE '^null$' |
rdobuilder 30d276
  sort -u > "${TMP_DIR}/nolicense.txt"
rdobuilder 30d276
rdobuilder 30d276
if [[ -s "${TMP_DIR}/nolicense.txt" ]]
rdobuilder 30d276
then
rdobuilder 30d276
  echo -e "\e[5m\e[41mSome dependencies do not list a license. Manual verification required!\e[0m"
rdobuilder 30d276
  cat "${TMP_DIR}/nolicense.txt"
rdobuilder 30d276
  echo -e "\e[5m\e[41m======================================================================\e[0m"
rdobuilder 30d276
fi
rdobuilder 30d276
rdobuilder 30d276
echo "Downloading dev dependencies" 1>&2
rdobuilder 30d276
# Compared to nodejs-packaging-bundler, we must add --ignore-scripts or npm
rdobuilder 30d276
# unsuccessfully attempts to build the package.
rdobuilder 30d276
npm install --no-optional --only=dev --ignore-scripts
rdobuilder 30d276
echo "Successful dev dependencies download" 1>&2
rdobuilder 30d276
mv node_modules/ node_modules_dev
rdobuilder 30d276
rdobuilder 30d276
if [[ -d node_modules_prod ]]
rdobuilder 30d276
then
rdobuilder 30d276
  tar -cf "../llhttp-${VERSION}-nm-prod.tar" node_modules_prod
rdobuilder 30d276
fi
rdobuilder 30d276
if [[ -d node_modules_dev ]]
rdobuilder 30d276
then
rdobuilder 30d276
  tar -cf "../llhttp-${VERSION}-nm-dev.tar" node_modules_dev
rdobuilder 30d276
fi
rdobuilder 30d276
zstdmt --ultra -22 "../llhttp-${VERSION}-nm-prod.tar" "../llhttp-${VERSION}-nm-dev.tar"
rdobuilder 30d276
rdobuilder 30d276
cd ..
rdobuilder 30d276
find . -mindepth 1 -maxdepth 1 -type f \( -name "$(basename "${ARCHIVE}")" \
rdobuilder 30d276
    -o -name "llhttp-${VERSION}*" \) -exec cp -vp '{}' "${OUTPUT_DIR}" ';'