summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2022-04-17 12:06:41 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2022-04-17 12:06:44 +0200
commitac0aac7fc7277933e83b5c9476ae34bb607932fd (patch)
tree4ab69b8b6adc28f3d311289ae0dcb44477f938ae
parentd1fb91928772f62399c2a4957dd7fef3e9113828 (diff)
downloadptxdist-ac0aac7fc7277933e83b5c9476ae34bb607932fd.tar.gz
ptxdist-ac0aac7fc7277933e83b5c9476ae34bb607932fd.tar.xz
impove compile_commands.json handling
This adds compile_commands.json support for kbuild based packages such as the Linux kernel and Barebox. It also adds a make macro that can be used by packages with other compile_commands.json generators. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rw-r--r--rules/post/ptxd_make_world_prepare.make4
-rw-r--r--scripts/lib/ptxd_make_world_compile.sh20
-rw-r--r--scripts/lib/ptxd_make_world_compile_commands.sh39
-rw-r--r--scripts/lib/ptxd_make_world_prepare.sh25
4 files changed, 64 insertions, 24 deletions
diff --git a/rules/post/ptxd_make_world_prepare.make b/rules/post/ptxd_make_world_prepare.make
index a91f00b8a..1a0556a84 100644
--- a/rules/post/ptxd_make_world_prepare.make
+++ b/rules/post/ptxd_make_world_prepare.make
@@ -6,6 +6,10 @@
# see the README file.
#
+world/compile-commands = \
+ $(call world/env, $(1)) \
+ ptxd_make_world_compile_commands $(2)
+
world/cfghash = \
+$(call world/env, $1) \
ptxd_make_world_hash cfghash
diff --git a/scripts/lib/ptxd_make_world_compile.sh b/scripts/lib/ptxd_make_world_compile.sh
index d45b138e3..1fb70c7c5 100644
--- a/scripts/lib/ptxd_make_world_compile.sh
+++ b/scripts/lib/ptxd_make_world_compile.sh
@@ -5,6 +5,23 @@
# see the README file.
#
+ptxd_make_world_compile_finish() {
+ if [ "${pkg_build_tool}" = "kconfig" ]; then
+ if [ -x "${pkg_dir}/scripts/clang-tools/gen_compile_commands.py" ]; then
+ # fake dependency for python wrapper
+ pkg_build_deps=host-system-python3 \
+ "${pkg_dir}/scripts/clang-tools/gen_compile_commands.py" \
+ -d "${pkg_build_dir}" -o "${pkg_build_dir}/compile_commands.json"
+ if [ $? -ne 0 ]; then
+ ptxd_warning "Ignoring failed scripts/clang-tools/gen_compile_commands.py"
+ else
+ ptxd_make_world_compile_commands_filter
+ fi
+ fi
+ fi
+}
+export -f ptxd_make_world_compile_finish
+
#
# call the compiler
#
@@ -66,6 +83,7 @@ ptxd_make_world_compile() {
"${pkg_make_opt}" \
"${pkg_make_par}"
;;
- esac
+ esac &&
+ ptxd_make_world_compile_finish
}
export -f ptxd_make_world_compile
diff --git a/scripts/lib/ptxd_make_world_compile_commands.sh b/scripts/lib/ptxd_make_world_compile_commands.sh
new file mode 100644
index 000000000..a3aa2033b
--- /dev/null
+++ b/scripts/lib/ptxd_make_world_compile_commands.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+#
+# Copyright (C) 2022 by Michael Olbrich <m.olbrich@pengutronix.de>
+#
+# For further information about the PTXdist project and license conditions
+# see the README file.
+#
+
+ptxd_make_world_compile_commands_filter() {
+ local src_cmds="${1:-${pkg_build_dir}/compile_commands.json}"
+ local dst_cmds="${pkg_dir}/compile_commands.json"
+
+ if [ ! -e "${src_cmds}" ]; then
+ ptxd_verbose "Ignoring missing '${src_cmds}'."
+ return
+ fi
+
+ if [ "${src_cmds}" = "${dst_cmds}" ]; then
+ if [ grep -q "${PTXDIST_CROSS_CPPFLAGS}" "${src_cmds}" ]; then
+ ptxd_warning "compile_commands.json is already up to date!"
+ return
+ fi
+ mv "${src_cmds}" "${src_cmds}.orig"
+ src_cmds="${src_cmds}.orig"
+ fi
+
+ ptxd_verbose "Generating '$(ptxd_print_path "${dst_cmds}")'"
+ sed \
+ -e "s#\(\"command\": \"[^ ]*\(gcc\|clang\) \)#\1 ${PTXDIST_CROSS_CPPFLAGS} ${pkg_cflags} #" \
+ -e "s#\(\"command\": \"[^ ]*++ \)#\1 ${PTXDIST_CROSS_CPPFLAGS} ${pkg_cxxflags} #" \
+ "${src_cmds}" > "${dst_cmds}"
+}
+export -f ptxd_make_world_compile_commands_filter
+
+ptxd_make_world_compile_commands() {
+ ptxd_make_world_init &&
+ ptxd_make_world_compile_commands_filter
+}
+export -f ptxd_make_world_compile_commands
diff --git a/scripts/lib/ptxd_make_world_prepare.sh b/scripts/lib/ptxd_make_world_prepare.sh
index 538e2bd1b..8ffdd611f 100644
--- a/scripts/lib/ptxd_make_world_prepare.sh
+++ b/scripts/lib/ptxd_make_world_prepare.sh
@@ -69,27 +69,6 @@ EOF
}
export -f ptxd_make_world_prepare_sanity_check
-ptxd_make_world_prepare_compile_commands() {
- local src_cmds dst_cmds
- if [ ! -e compile_commands.json ]; then
- return
- fi
-
- if [ "${pkg_dir}" = "${pkg_build_dir}" ]; then
- mv compile_commands.json compile_commands.json.orig
- src_cmds=compile_commands.json.orig
- else
- src_cmds=compile_commands.json
- fi
- dst_cmds="${pkg_dir}/compile_commands.json"
-
- sed \
- -e "s#\(\"command\": \"[^ ]*\(gcc\|clang\) \)#\1 ${PTXDIST_CROSS_CPPFLAGS} ${pkg_cflags} #" \
- -e "s#\(\"command\": \"[^ ]*++ \)#\1 ${PTXDIST_CROSS_CPPFLAGS} ${pkg_cxxflags} #" \
- "${src_cmds}" > "${dst_cmds}"
-}
-export -f ptxd_make_world_prepare_compile_commands
-
#
# prepare for cmake based pkgs
#
@@ -102,7 +81,7 @@ ptxd_make_world_prepare_cmake() {
cmake \
"${pkg_conf_opt}" \
"${pkg_conf_dir}" &&
- ptxd_make_world_prepare_compile_commands
+ ptxd_make_world_compile_commands_filter
}
export -f ptxd_make_world_prepare_cmake
@@ -173,7 +152,7 @@ ptxd_make_world_prepare_meson() {
meson \
"${pkg_conf_opt}" \
"${pkg_conf_dir}" &&
- ptxd_make_world_prepare_compile_commands
+ ptxd_make_world_compile_commands_filter
}
export -f ptxd_make_world_prepare_meson