generate-licenses-csv

 1#!/usr/bin/env bash
 2
 3set -euo pipefail
 4
 5CARGO_ABOUT_VERSION="0.6.1"
 6OUTPUT_FILE="${1:-$(pwd)/assets/licenses.csv}"
 7TEMPLATE_FILE="script/licenses/template.csv.hbs"
 8
 9if ! cargo install --list | grep "cargo-about v$CARGO_ABOUT_VERSION" > /dev/null; then
10  echo "Installing cargo-about@$CARGO_ABOUT_VERSION..."
11  cargo install "cargo-about@$CARGO_ABOUT_VERSION"
12else
13  echo "cargo-about@$CARGO_ABOUT_VERSION is already installed."
14fi
15
16echo "Generating cargo licenses"
17
18stderr_file=$(mktemp)
19
20cargo about generate \
21    --fail \
22    -c script/licenses/zed-licenses.toml \
23    script/licenses/template.csv.hbs \
24    2> >(tee "$stderr_file") \
25    | awk 'NR==1{print;next} NF{print | "sort"}' \
26    > $OUTPUT_FILE
27
28# Check that there are no warnings.
29if echo "$about_stderr" | grep -v "\[WARN\]" > /dev/null; then
30    echo "Error: License check failed - warnings found" >&2
31    exit 1
32fi
33
34echo "generate-licenses-csv completed. See $OUTPUT_FILE"