#!/usr/bin/env bash # Environment variables # BAZEL : the bazel binary to invoke (default: baselisk) # BAZEL_OPTS : the preferred bazel options used set -eu # Which bazel and bant to use. If unset, defaults are used. BAZEL=${BAZEL:-bazelisk} if ! command -v "${BAZEL}">/dev/null ; then BAZEL=bazel fi BANT="$($(dirname "$0")/get-bant-path.sh)" # Important to run with --remote_download_outputs=all to make sure generated # files are actually visible locally in case a remote cache (that includes # --disk_cache) is used ( https://github.com/hzeller/bazel-gen-file-issue ) BAZEL_REMOTE_MATERIALIZE=--remote_download_outputs=all # Bazel options BAZEL_OPTS="${BAZEL_OPTS:--c opt ${BAZEL_REMOTE_MATERIALIZE}}" # Tickle some build targets to fetch all dependencies and generate files, # so that they can be seen by the users of the compilation db. # (Note, we need to limit targets to everything below //src, otherwise # it requires docker) "${BAZEL}" fetch "${BAZEL_REMOTE_MATERIALIZE}" //src/... "${BAZEL}" build -k ${BAZEL_OPTS} \ @openmp//:omp_header \ $("${BANT}" list-targets ... -g "genrule|tcl_encode|tcl_wrap_cc" -g "//src" -c3) # Create compilation DB. Command 'compilation-db' would create a huge *.json file, # but compile_flags.txt is perfectly sufficient and easier for tools to use as # these tools will require much less memory. "${BANT}" compile-flags -o compile_flags.txt # Qt include files check for this echo '-fPIC' >> compile_flags.txt # Python include bindings. for f in bazel-out/../../../external/*/include/python3.*/Python.h; do if [ -f "${f}" ]; then PY_INC="$(dirname "${f}")" echo "-I${PY_INC}" echo "-I$(realpath "${PY_INC}")" # work around clangd bug break fi done >> compile_flags.txt # Since we don't do per-file define extraction in compile_flag.txt, # to avoid polluting the global namespace, selectively add necessary ones here. cat >> compile_flags.txt <