1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:12:57 +01:00

info.inc.mk: Add info-build-json as JSON-formatted build info

This commit is contained in:
Koen Zandberg 2020-10-08 15:18:29 +02:00
parent 2dac4db343
commit aba91f144c
No known key found for this signature in database
GPG Key ID: 0895A893E6D2985B

View File

@ -114,6 +114,72 @@ info-build:
@echo ''
@echo -e 'MAKEFILE_LIST:$(patsubst %, \n\t%, $(abspath $(MAKEFILE_LIST)))'
define json_string_or_null
$(or $(1:%="%"), null)
endef
# Convert a space separated list to a JSON array
define _to_json_string_list
[$(filter-out "","$(subst $(space),"$(comma)$(space)",$(1))")]
endef
# Strips out any existing quotes so that the generated JSON is valid, not necessary sensible
define to_json_string_list
$(call _to_json_string_list,$(strip $(subst ",,$(subst \",,$(1)))))
endef
# Crude json encoded build info.
# The output generated here is a best-effort JSON encoding, it is not perfect,
# converting the space separated lists in Make to a JSON array is flawed, it
# doesn't consider quoted parts as a single list item. This mainly shows up in
# cflags such as: -DNIMBLE_HOST_PRIO="(NIMBLE_CONTROLLER_PRIO + 1)", this is
# splitted into 3 array elements. To ensure that the generated JSON is valid,
# double quotes are currently stripped before generating the array.
info-build-json:
@echo '{ '
@echo '"APPLICATION": "$(APPLICATION)",'
@echo '"APPDIR": "$(APPDIR)",'
@echo '"BOARD": "$(BOARD)",'
@echo '"CPU": "$(CPU)",'
@echo '"MCU": "$(MCU)",'
@echo '"RIOTBASE": "$(RIOTBASE)",'
@echo '"BOARDDIR": "$(BOARDDIR)",'
@echo '"RIOTCPU": "$(RIOTCPU)",'
@echo '"RIOTPKG": "$(RIOTPKG)",'
@echo '"EXTERNAL_BOARD_DIRS": $(call json_string_or_null $(EXTERNAL_BOARD_DIRS)),'
@echo '"BINDIR": "$(BINDIR)",'
@echo '"ELFFILE": "$(ELFFILE)",'
@echo '"HEXFILE": "$(HEXFILE)",'
@echo '"BINFILE": "$(BINFILE)",'
@echo '"FLASHFILE": "$(FLASHFILE)",'
@echo '"DEFAULT_MODULE": $(call to_json_string_list,$(sort $(filter-out $(DISABLE_MODULE), $(DEFAULT_MODULE)))),'
@echo '"DISABLE_MODULE": $(call to_json_string_list,$(sort $(DISABLE_MODULE))),'
@echo '"USEMODULE": $(call to_json_string_list,$(sort $(filter-out $(DEFAULT_MODULE), $(USEMODULE)))),'
@echo '"FEATURES_USED": $(call to_json_string_list,$(FEATURES_USED)),'
@echo '"FEATURES_REQUIRED": $(call to_json_string_list,$(sort $(FEATURES_REQUIRED))),'
@echo '"FEATURES_REQUIRED_ANY": $(call to_json_string_list,$(sort $(FEATURES_REQUIRED_ANY))),'
@echo '"FEATURES_OPTIONAL_ONLY": $(call to_json_string_list,$(FEATURES_OPTIONAL_ONLY)),'
@echo '"FEATURES_OPTIONAL_MISSING": $(call to_json_string_list,$(FEATURES_OPTIONAL_MISSING)),'
@echo '"FEATURES_PROVIDED": $(call to_json_string_list,$(sort $(FEATURES_PROVIDED))),'
@echo '"FEATURES_MISSING": $(call to_json_string_list,$(FEATURES_MISSING)),'
@echo '"FEATURES_BLACKLIST": $(call to_json_string_list,$(sort $(FEATURES_BLACKLIST))),'
@echo '"FEATURES_USED_BLACKLISTED": $(call to_json_string_list,$(sort $(FEATURES_USED_BLACKLISTED))),'
@echo '"FEATURES_CONFLICT": $(call to_json_string_list,$(FEATURES_CONFLICT)),'
@echo '"FEATURES_CONFLICTING": $(call to_json_string_list,$(FEATURES_CONFLICTING)),'
@echo '"PREFIX": $(call json_string_or_null,$(PREFIX)),'
@echo '"CC": "$(CC)",'
@echo '"CXX": "$(CXX)",'
@echo '"LINK": "$(LINK)",'
@echo '"OBJCOPY": "$(OBJCOPY)",'
@echo '"INCLUDES": $(call to_json_string_list,$(strip $(INCLUDES))),'
@echo '"OFLAGS": $(call to_json_string_list,$(OFLAGS)),'
@echo '"CFLAGS": $(call to_json_string_list,$(CFLAGS)),'
@echo '"CXXUWFLAGS": $(call to_json_string_list,$(CXXUWFLAGS)),'
@echo '"CXXEXFLAGS": $(call to_json_string_list,$(CXXEXFLAGS)),'
@echo '"LINKFLAGS": $(call to_json_string_list,$(LINKFLAGS))'
@echo '}'
info-files: QUIET := 0
info-files:
@( \