diff options
author | Craig Hesling <hesling@chromium.org> | 2022-08-12 02:27:43 -0400 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-08-26 20:08:27 +0000 |
commit | bf3745a1f4cb438152694c969e8e5d2e267b380e (patch) | |
tree | 658667c8b426a66968b9a3b19505a84ef092073f /Makefile.ide | |
parent | f9f538930884f5c3361176b2731e71f281e3ca72 (diff) | |
download | chrome-ec-bf3745a1f4cb438152694c969e8e5d2e267b380e.tar.gz |
make: Add ide-compile-cmds targets suite
This suite of targets generates compile_commands.json for
specific boards/images.
It places the output file under build/$BOARD/{RO,RW}/compile_commands.json.
Targets:
* all-ide-compile-cmds
Generates the compile_commands for all boards
* ide-compile-cmds BOARD=$BOARD
Generates the compile_commands for BOARD
* ide-compile-cmds-$BOARD
Generates the compile_commands for BOARD
Cons:
* Doesn't include commands for any tests or utils
* Can't easily capture build commands for cryptoc, since it invokes
cryptoc's makefile.
BRANCH=none
BUG=b:236389226,b:176500425
TEST=make all-ide-compile-cmds -j
TEST=make ide-compile-cmds-bloonchipper -j
less build/bloonchipper/RW/compile_commands.json
TEST=make BOARD=bloonchipper ide-compile-cmds
TEST=# Board kukui_scp only has an RW image.
make BOARD=kukui_scp ide-compile-cmds
# Only an RW compile_commands.json should be created.
TEST=make BOARD=hatch build/hatch/RO/compile_commands.json
clangd --check=build/hatch/RO/compile_commands.json
Signed-off-by: Craig Hesling <hesling@chromium.org>
Change-Id: I008648e84da70149425f8a36f818b3953c7fa36d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3826375
Reviewed-by: Andrea Grandi <agrandi@google.com>
Diffstat (limited to 'Makefile.ide')
-rw-r--r-- | Makefile.ide | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Makefile.ide b/Makefile.ide new file mode 100644 index 0000000000..b86f52226e --- /dev/null +++ b/Makefile.ide @@ -0,0 +1,75 @@ +# -*- makefile -*- +# vim: set filetype=make : +# Copyright 2022 The Chromium OS Authors. All rights reserved. +# 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 +# + +# 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 ".". +ide_ec_path_ext = \ + $(if $(EXTERNAL_TRUNK_PATH),$(EXTERNAL_TRUNK_PATH)/src/platform/ec) +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)) + +# 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 +# takes 2m independent of the text manipulation. +.PHONY: all-ide-compile-cmds +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) + +# All but the last file/json-object need to have a trailing comma. +# +# The first sed line prepends 4 spaces to all lines and then adds a +# comma + implicit-newline to the end of the last line of the file. +# The second sed line prepends 4 spaces to all lines and then adds an +# implicit new line. +cmd_combine_compile_cmd_json = \ + printf '[\n' >$@ ;\ + echo $^ | xargs -n1 | head -n-1 | xargs -n1 sed 's/^/ /;$$s/$$/,/' \ + >>$@ ;\ + 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) + $(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) + $(call quiet,combine_compile_cmd_json,COMBINE) + +cmd_c_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 ' ],\n' >>$@ ;\ + printf ' "directory": "$(ide_ec_path)",\n' >>$@ ;\ + printf ' "file": "$<"\n' >>$@ ;\ + printf '}\n' >>$@ ; + +$(out)/RO/%.compile_cmd.json:%.c + $(call quiet,c_to_compile_cmd_json,JSON ) +$(out)/RW/%.compile_cmd.json:%.c + $(call quiet,c_to_compile_cmd_json,JSON ) + +$(out)/RO/%.compile_cmd.json:%.S + $(call quiet,c_to_compile_cmd_json,JSON ) +$(out)/RW/%.compile_cmd.json:%.S + $(call quiet,c_to_compile_cmd_json,JSON ) |