diff options
-rw-r--r-- | rules/post/ptxd_make_world_prepare.make | 4 | ||||
-rw-r--r-- | scripts/lib/ptxd_make_world_compile.sh | 20 | ||||
-rw-r--r-- | scripts/lib/ptxd_make_world_compile_commands.sh | 39 | ||||
-rw-r--r-- | scripts/lib/ptxd_make_world_prepare.sh | 25 |
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 |