1#!/usr/bin/env bash
2
3set -euo pipefail
4
5CARGO_ABOUT_VERSION="0.6.1"
6OUTPUT_FILE="${1:-$(pwd)/assets/licenses.md}"
7TEMPLATE_FILE="script/licenses/template.md.hbs"
8
9> $OUTPUT_FILE
10
11echo -e "# ###### THEME LICENSES ######\n" >> $OUTPUT_FILE
12cat assets/themes/LICENSES >> $OUTPUT_FILE
13
14echo -e "\n# ###### ICON LICENSES ######\n" >> $OUTPUT_FILE
15cat assets/icons/LICENSES >> $OUTPUT_FILE
16
17echo -e "\n# ###### CODE LICENSES ######\n" >> $OUTPUT_FILE
18
19if ! cargo install --list | grep "cargo-about v$CARGO_ABOUT_VERSION" > /dev/null; then
20 echo "Installing cargo-about@$CARGO_ABOUT_VERSION..."
21 cargo install "cargo-about@$CARGO_ABOUT_VERSION"
22else
23 echo "cargo-about@$CARGO_ABOUT_VERSION is already installed."
24fi
25
26echo "Generating cargo licenses"
27
28stderr_file=$(mktemp)
29
30cargo about generate \
31 --fail \
32 -c script/licenses/zed-licenses.toml \
33 "${TEMPLATE_FILE}" \
34 2> >(tee "$stderr_file") \
35 >> $OUTPUT_FILE
36
37if cat "$stderr_file" | grep -v "\[WARN\]" > /dev/null; then
38 echo "Error: License check failed - warnings found" >&2
39 exit 1
40fi
41
42sed -i.bak 's/"/"/g' $OUTPUT_FILE
43sed -i.bak 's/'/'\''/g' $OUTPUT_FILE # The ` '\'' ` thing ends the string, appends a single quote, and re-opens the string
44sed -i.bak 's/=/=/g' $OUTPUT_FILE
45sed -i.bak 's/`/`/g' $OUTPUT_FILE
46sed -i.bak 's/</</g' $OUTPUT_FILE
47sed -i.bak 's/>/>/g' $OUTPUT_FILE
48
49rm -rf "${OUTPUT_FILE}.bak"
50
51echo "generate-licenses completed. See $OUTPUT_FILE"