daml/dev-env/bin/bazel-project-view
Digital Asset GmbH 05e691f558 open-sourcing daml
2019-04-04 09:33:38 +01:00

77 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eo pipefail
USAGEMSG="USAGE: $0 [-o OUTPUT] PROJECT
Generate a default project view file for the specified Bazel package for the
IntelliJ Bazel plugin. PROJECT must be a valid Bazel package without the
leading '//'. For example 'ledger-client/ods'.
Example usage:
bazel-project-view -o ledger-client/ods/.bazelproject ledger-client/ods
"
usage() {
echo "$USAGEMSG"
exit $1
}
OUTPUT="-"
while getopts "ho:" flag; do
case "$flag" in
h)
usage 0
;;
o)
OUTPUT="$OPTARG"
;;
*)
usage 1
;;
esac
done
shift $((OPTIND-1))
if [[ $# -ne 1 ]]; then
usage 1
fi
PROJECT="$1"
# Run Bazel query, return results sorted and indented.
query() {
bazel query "$1" | sort | sed 's/^/ /'
}
echo "Querying library targets..." >&2
LIB_TARGETS="$(query 'kind("library rule", //'"$PROJECT"'/...)')"
echo "Querying test targets..." >&2
TEST_TARGETS="$(query 'tests(//'"$PROJECT"'/...)')"
echo "Querying executable targets..." >&2
EXE_TARGETS="$(query 'kind("binary rule", //'"$PROJECT"'/...)')"
PROJET_VIEW="directories:
$PROJECT
targets:
# Library targets
$LIB_TARGETS
# Test targets
$TEST_TARGETS
# Executable targets
$EXE_TARGETS
additional_languages:
scala
"
if [[ "$OUTPUT" == "-" ]]; then
echo "$PROJET_VIEW"
else
echo "$PROJET_VIEW" > "$OUTPUT"
fi