mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[build-script] Add flag to export compile commands
CMake supports generation of compilation databases. These have many uses, not least of which is in supporting code-completion engines like https://github.com/Valloric/YouCompleteMe. Add the `--export-compile-commands` flag to `utils/build-script`. Setting this flag passes `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON` to CMake, which results in a `compile_commands.json` file being generated along with built products like `cmark`, `llvm`, and `swift`.
This commit is contained in:
@@ -295,10 +295,13 @@ details of the setups of other systems or automated environments.""")
|
||||
dest="build_foundation")
|
||||
|
||||
extra_actions_group = parser.add_argument_group(
|
||||
title="Extra actions to perform before building")
|
||||
title="Extra actions to perform before or in addition to building")
|
||||
extra_actions_group.add_argument("-c", "--clean",
|
||||
help="do a clean build",
|
||||
action="store_true")
|
||||
extra_actions_group.add_argument("--export-compile-commands",
|
||||
help="generate compilation databases in addition to building",
|
||||
action="store_true")
|
||||
|
||||
build_variant_group = parser.add_mutually_exclusive_group(required=False)
|
||||
build_variant_group.add_argument("-d", "--debug",
|
||||
@@ -559,6 +562,11 @@ the number of parallel build jobs to use""",
|
||||
|
||||
build_script_impl_inferred_args = []
|
||||
|
||||
if args.export_compile_commands:
|
||||
build_script_impl_inferred_args += [
|
||||
"--export-compile-commands"
|
||||
]
|
||||
|
||||
if args.cmake_generator == "XcodeIDEOnly":
|
||||
args.cmake_generator = "Xcode"
|
||||
build_script_impl_inferred_args += [
|
||||
|
||||
@@ -182,7 +182,7 @@ KNOWN_SETTINGS=(
|
||||
darwin-toolchain-installer-package "" "The path to installer pkg"
|
||||
build-jobs "" "The number of parallel build jobs to use"
|
||||
darwin-toolchain-alias "swift" "Swift alias for toolchain"
|
||||
|
||||
export-compile-commands "" "set to generate JSON compilation databases for each build product"
|
||||
)
|
||||
|
||||
function toupper() {
|
||||
@@ -1035,6 +1035,13 @@ if [[ "${ENABLE_ASAN}" ]] ; then
|
||||
)
|
||||
fi
|
||||
|
||||
if [[ "${EXPORT_COMPILE_COMMANDS}" ]] ; then
|
||||
COMMON_CMAKE_OPTIONS=(
|
||||
"${COMMON_CMAKE_OPTIONS[@]}"
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||
)
|
||||
fi
|
||||
|
||||
if [ -z "${HOST_CC}" ] ; then
|
||||
if [ "$(uname -s)" == "Darwin" ] ; then
|
||||
HOST_CC="$(xcrun_find_tool clang)"
|
||||
|
||||
Reference in New Issue
Block a user