diff options
author | Craig Hesling <hesling@chromium.org> | 2022-10-01 17:01:01 -0400 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-10-05 19:53:42 +0000 |
commit | 0fa7480c3876ecef887db9e4dd9a5ce2a5b03134 (patch) | |
tree | b918f941aa5d8d4b08280950b90ba7032e973d8c /Makefile.ide | |
parent | 3343af13117934611ce1a682acd1f99b8b10ed74 (diff) | |
download | chrome-ec-0fa7480c3876ecef887db9e4dd9a5ce2a5b03134.tar.gz |
Makefile.ide: Generalize to apply to more targets
It is important to note that this CL moves the format
of the compile commands json away from the simplified
commands that bear outputs. It instead inserts the
arguments that we actually use for compilation.
One caveat with this approach is that we still don't
capture special modified args that are associated with
a specific build target, like the following:
$(out)/RW/common/blah.o: CFLAGS += -g
This is because our compile commands json targets
will not match this rule.
This is benchmarked using the following command:
> time make ide-compile-cmds-hatch
Note that the extra $(shell sed ...) invocation
slows the benchmark down by about 1sec.
BRANCH=none
BUG=b:250077363,b:236389226,b:176500425
TEST=# bloonchipper doesn't work without c++ support
make ide-compile-cmds-hatch -j
TEST=# Board kukui_scp only has an RW image.
make ide-compile-cmds-kukui_scp
# Only an RW compile_commands.json should be created.
Signed-off-by: Craig Hesling <hesling@chromium.org>
Change-Id: I0a3542bbd5478311e8f2b253f88c936915ed5032
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3866112
Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
Reviewed-by: Andrea Grandi <agrandi@google.com>
Diffstat (limited to 'Makefile.ide')
-rw-r--r-- | Makefile.ide | 76 |
1 files changed, 57 insertions, 19 deletions
diff --git a/Makefile.ide b/Makefile.ide index f8174f17df..cdef041d3b 100644 --- a/Makefile.ide +++ b/Makefile.ide @@ -4,8 +4,14 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # -# Embedded Controller firmware build system - IDE integration support +# Embedded Controller firmware build system - IDE support # +# One caveat with this approach is that we still don't capture modified make +# variables that are associated with a specific build target, like the following: +# +# $(out)/RW/common/blah.o: CFLAGS += -g +# +# This is because our compile commands json targets will not match this rule. # If env EXTERNAL_TRUNK_PATH is defined, we use this to build the # absolute path to the ec directory. Otherwise, we just take the abspath of ".". @@ -15,7 +21,15 @@ ide_ec_path_abs = $(abspath .) ide_ec_path = $(or $(ide_ec_path_ext),$(ide_ec_path_abs)) # Clang doesn't support these GCC options. -ide_cflags = $(filter-out -mno-sched-prolog -fconserve-stack,$(CFLAGS)) +ide-filters = -mno-sched-prolog -fconserve-stack + +# The complete compile_commands.json targets. +ide-compile-cmds-y = $(out)/RW/compile_commands.json +ide-compile-cmds-$(CONFIG_FW_INCLUDE_RO) += $(out)/RO/compile_commands.json + +# All individual <src_file>.compile_cmds.json targets. +ide-rw-objs = $(rw-objs:.o=.compile_cmd.json) +ide-ro-objs = $(ro-objs:.o=.compile_cmd.json) # The all-ide-compile-cmds target takes about 2 minutes using 8 cores when all # work is replaced by the |true| command. Thus, the build system itself @@ -25,9 +39,6 @@ all-ide-compile-cmds: $(foreach b, $(BOARDS), ide-compile-cmds-$(b)) ide-compile-cmds-%: $(MAKE) BOARD=$* V=$(V) ide-compile-cmds -ide-compile-cmds-y = $(out)/RW/compile_commands.json -ide-compile-cmds-$(CONFIG_FW_INCLUDE_RO) += $(out)/RO/compile_commands.json - .PHONY: ide-compile-cmds ide-compile-cmds: $(ide-compile-cmds-y) @@ -44,32 +55,59 @@ cmd_combine_compile_cmd_json = \ sed 's/^/ /' $(lastword $^) >>$@ ;\ printf ']\n' >>$@ ; -$(out)/RW/compile_commands.json: override BLD:=RW -$(out)/RW/compile_commands.json: private objs := $(rw-objs:.o=.json) -$(out)/RW/compile_commands.json: $(rw-objs:.o=.compile_cmd.json) +$(out)/RW/compile_commands.json: override BLD := RW +$(out)/RW/compile_commands.json: private objs := $(rw-objs) +$(out)/RW/compile_commands.json: $(ide-rw-objs) $(call quiet,combine_compile_cmd_json,COMBINE) -$(out)/RO/compile_commands.json: override BLD:=RO -$(out)/RO/compile_commands.json: private objs := $(ro-objs:.o=.json) -$(out)/RO/compile_commands.json: $(ro-objs:.o=.compile_cmd.json) +$(out)/RO/compile_commands.json: override BLD := RO +$(out)/RO/compile_commands.json: private objs := $(ro-objs) +$(out)/RO/compile_commands.json: $(ide-ro-objs) $(call quiet,combine_compile_cmd_json,COMBINE) -cmd_c_to_compile_cmd_json = \ +# Quote all words and add a comma between words. +# The quotes are applied as \", so that they will escape shell removal. +# +# $(1) - The space separated list of words. +ide-comma = , +ide-space = $() $() +ide-esc-quoted = $(patsubst %,\"%\",$(1)) +ide-comma-sep = $(subst $(ide-space),$(ide-comma)$(ide-space),$(ide-esc-quoted)) +cmd_json_list = $(ide-comma-sep) + +# Replace any ".compile_cmd.json" with ".o" and filter out $(ide-filters) words. +# The replace is needed because we are invoking build commands from within our +# make rules that have targets set to files of type .compile_cmd.json. +# The compile commands will use special variables that pull this name into +# the command. +# +# $(1) - The compilation command. +cmd_rep_filter = $(subst .compile_cmd.json,.o,$(filter-out $(ide-filters),$(1))) + +# Form a compile command JSON block. +# +# $(1) - Used by quiet function, but it is this command name. +# $(2) - Used by quiet function, but it is the pretty action label. +# $(3) - The compilation command to place in the JSON blob. +cmd_to_compile_cmd_json = \ printf '{\n' >$@ ;\ printf ' "arguments": [\n' >>$@ ;\ - printf ' "%s",\n' cc -c -std=gnu11 $(C_WARN) $(ide_cflags) \ - -o $(@D)/$(@F:.compile_cmd.json=.o) >>$@ ;\ - printf ' "$<"\n' >>$@ ;\ + printf ' %s\n' \ + $(call cmd_json_list,$(call cmd_rep_filter,$(3))) >>$@ ;\ printf ' ],\n' >>$@ ;\ printf ' "directory": "$(ide_ec_path)",\n' >>$@ ;\ printf ' "file": "$<"\n' >>$@ ;\ printf '}\n' >>$@ ; +# Disable ccache, since this is only going to control whether the ccache +# executable shows in the compile_commands.json file. +%.compile_cmd.json: CCACHE := + $(out)/RO/%.compile_cmd.json:%.c - $(call quiet,c_to_compile_cmd_json,JSON ) + $(call quiet,to_compile_cmd_json,JSON ,$(cmd_c_to_o)) $(out)/RW/%.compile_cmd.json:%.c - $(call quiet,c_to_compile_cmd_json,JSON ) + $(call quiet,to_compile_cmd_json,JSON ,$(cmd_c_to_o)) $(out)/RO/%.compile_cmd.json:%.S - $(call quiet,c_to_compile_cmd_json,JSON ) + $(call quiet,to_compile_cmd_json,JSON ,$(cmd_c_to_o)) $(out)/RW/%.compile_cmd.json:%.S - $(call quiet,c_to_compile_cmd_json,JSON ) + $(call quiet,to_compile_cmd_json,JSON ,$(cmd_c_to_o)) |