Skip to content

Commit 95952ac

Browse files
authored
Merge pull request #21645 from ML-PA-Consulting-GmbH/dl/riot/20250805__info-build-json
makefiles/info.inc.mk: improvements to json build output
2 parents c0cc617 + ffc90a0 commit 95952ac

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

makefiles/info.inc.mk

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,33 @@ define _to_json_string_list
134134
[$(filter-out "","$(subst $(space),"$(comma)$(space)",$(1))")]
135135
endef
136136

137-
# Strips out any existing quotes so that the generated JSON is valid, not necessary sensible
137+
json_escape_swap := EsCaPe
138+
json_escape_quote := QuOtE
139+
# Corrects quotation and escape sequences in a string to be JSON compliant.
140+
# This does not support the use of single quotation. All single quotation marks
141+
# are removed.
138142
define to_json_string_list
139-
$(call _to_json_string_list,$(strip $(subst ",,$(subst \",,$(1)))))
143+
$(call _to_json_string_list,$(strip $(subst $(json_escape_swap),\,\
144+
$(subst $(json_escape_quote),",\
145+
$(subst \,$(json_escape_swap)$(json_escape_swap),\
146+
$(subst \/,$(json_escape_swap)/,\
147+
$(subst \b,$(json_escape_swap)b,\
148+
$(subst \f,$(json_escape_swap)f,\
149+
$(subst \n,$(json_escape_swap)n,\
150+
$(subst \r,$(json_escape_swap)r,\
151+
$(subst \t,$(json_escape_swap)t,\
152+
$(subst \u,$(json_escape_swap)u,\
153+
$(subst ',,\
154+
$(subst ",$(json_escape_swap)$(json_escape_quote),\
155+
$(1)))))))))))))))
140156
endef
141157

142158
# Crude json encoded build info.
143159
# The output generated here is a best-effort JSON encoding, it is not perfect,
144160
# converting the space separated lists in Make to a JSON array is flawed, it
145161
# doesn't consider quoted parts as a single list item. This mainly shows up in
146162
# cflags such as: -DNIMBLE_HOST_PRIO="(NIMBLE_CONTROLLER_PRIO + 1)", this is
147-
# splitted into 3 array elements. To ensure that the generated JSON is valid,
148-
# double quotes are currently stripped before generating the array.
163+
# splitted into 3 array elements.
149164
info-build-json:
150165
@echo '{ '
151166
@echo '"APPLICATION": "$(APPLICATION)",'
@@ -156,15 +171,19 @@ info-build-json:
156171
@echo '"BOARDDIR": "$(BOARDDIR)",'
157172
@echo '"RIOTCPU": "$(RIOTCPU)",'
158173
@echo '"RIOTPKG": "$(RIOTPKG)",'
159-
@echo '"EXTERNAL_BOARD_DIRS": $(call json_string_or_null,$(EXTERNAL_BOARD_DIRS)),'
174+
@echo '"EXTERNAL_BOARD_DIRS": $(call to_json_string_list,$(EXTERNAL_BOARD_DIRS)),'
160175
@echo '"BINDIR": "$(BINDIR)",'
161176
@echo '"ELFFILE": "$(ELFFILE)",'
162177
@echo '"HEXFILE": "$(HEXFILE)",'
163178
@echo '"BINFILE": "$(BINFILE)",'
164179
@echo '"FLASHFILE": "$(FLASHFILE)",'
180+
@echo '"EXTERNAL_MODULE_DIRS": $(call to_json_string_list,$(EXTERNAL_MODULE_DIRS)),'
181+
@echo '"EXTERNAL_MODULE_PATHS": $(call to_json_string_list,$(EXTERNAL_MODULE_PATHS)),'
182+
@echo '"EXTERNAL_PKG_DIRS": $(call to_json_string_list,$(EXTERNAL_PKG_DIRS)),'
165183
@echo '"DEFAULT_MODULE": $(call to_json_string_list,$(sort $(filter-out $(DISABLE_MODULE), $(DEFAULT_MODULE)))),'
166184
@echo '"DISABLE_MODULE": $(call to_json_string_list,$(sort $(DISABLE_MODULE))),'
167185
@echo '"USEMODULE": $(call to_json_string_list,$(sort $(filter-out $(DEFAULT_MODULE), $(USEMODULE)))),'
186+
@echo '"USEPKG": $(call to_json_string_list,$(sort $(USEPKG))),'
168187
@echo '"FEATURES_USED": $(call to_json_string_list,$(FEATURES_USED)),'
169188
@echo '"FEATURES_REQUIRED": $(call to_json_string_list,$(sort $(FEATURES_REQUIRED))),'
170189
@echo '"FEATURES_REQUIRED_ANY": $(call to_json_string_list,$(sort $(FEATURES_REQUIRED_ANY))),'

0 commit comments

Comments
 (0)