blob: a5f46678ec6798bbab9e9058a12d8978ef4efd6b [file] [log] [blame]
#!/bin/bash
# Copyright 2018 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
### generate a compilation database for the current build configuration
## usage: fx compdb <-z>
## -z|--zircon to additonally generate compile_commands.json for Zircon
## -z option also concatenates the two compile_commands.json
generate_zircon () {
zirc_compdb=$(which compiledb || echo)
if [[ -z ${zirc_compdb} ]]; then
echo "Could not find compiledb, cannot generate Zircon compile_commands.json"
exit
fi
( cd ${FUCHSIA_DIR}/zircon; compiledb -o compile_commands.json -n make ${FUCHSIA_ARCH}) \
|| echo "An unknown error has occurred" #TODO what errors could this be?
}
main () {
zirc=0 #boolean for if compiledb has been run
case $1 in
-z|--zircon)
zirc=1
;;
-h|--help)
echo "Script to generate compile_commands.json files"
echo "-z|--zircon to additonally generate compile_commands.json for Zircon"
echo "-z option also concatenates the two compile_commands.json"
echo
exit
;;
esac
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/lib/vars.sh
fx-config-read
# TODO(BLD-165): This is a temporary workaround, as it uses the specific rule names
# generated by GN for each arch's shared directory. A better solution is to
# teach GN itself to output the compdb.
"${FUCHSIA_DIR}/buildtools/ninja" -C "${FUCHSIA_BUILD_DIR}" -t compdb cc cxx ${FUCHSIA_ARCH}-shared_cc ${FUCHSIA_ARCH}-shared_cxx > "${FUCHSIA_BUILD_DIR}/compile_commands.json"
ln -sf "${FUCHSIA_BUILD_DIR}/compile_commands.json" "${FUCHSIA_DIR}/compile_commands.json"
echo "Note: The compile_commands may be incomplete if you are building with variants other than arch."
if [[ $zirc -eq 1 ]]; then
generate_zircon
#concatenate the two files together by making a tmp file and then removing it when done
${FUCHSIA_DIR}/scripts/editors/cat_compile_commands.py ${FUCHSIA_DIR}/zircon/compile_commands.json \
${FUCHSIA_DIR}/out/${FUCHSIA_ARCH}/compile_commands.json > ${FUCHSIA_DIR}/compile_commands-tmp.json \
&& cp ${FUCHSIA_DIR}/compile_commands-tmp.json ${FUCHSIA_DIR}/compile_commands.json \
&& rm ${FUCHSIA_DIR}/compile_commands-tmp.json
fi
}
main "$@"