blob: dd3ef434294db86bcb0cee11fa41f695f7d0526c [file] [log] [blame]
Joe Onoratof20c93a2021-01-19 22:34:22 -08001# Read and dump the product configuration.
2
3# Called from the product-config tool, not from the main build system.
4
5#
6# Ensure we are being called correctly
7#
8ifndef KATI
9 $(warning Kati must be used to call dumpconfig.mk, not make.)
10 $(error stopping)
11endif
12
13ifdef DEFAULT_GOAL
14 $(warning Calling dumpconfig.mk from inside the make build system is not)
15 $(warning supported. It is only meant to be called via kati by product-confing.)
16 $(error stopping)
17endif
18
19ifndef TARGET_PRODUCT
20 $(warning dumpconfig.mk requires TARGET_PRODUCT to be set)
21 $(error stopping)
22endif
23
24ifndef TARGET_BUILD_VARIANT
25 $(warning dumpconfig.mk requires TARGET_BUILD_VARIANT to be set)
26 $(error stopping)
27endif
28
29ifneq (build/make/core/config.mk,$(wildcard build/make/core/config.mk))
30 $(warning dumpconfig must be called from the root of the source tree)
31 $(error stopping)
32endif
33
34ifeq (,$(DUMPCONFIG_FILE))
35 $(warning dumpconfig requires DUMPCONFIG_FILE to be set)
36 $(error stopping)
37endif
38
39# Before we do anything else output the format version.
40$(file > $(DUMPCONFIG_FILE),dumpconfig_version,1)
41$(file >> $(DUMPCONFIG_FILE),dumpconfig_file,$(DUMPCONFIG_FILE))
42
43# Default goal for dumpconfig
44dumpconfig:
45 $(file >> $(DUMPCONFIG_FILE),***DONE***)
46 @echo ***DONE***
47
48# TODO(Remove): These need to be set externally
49OUT_DIR := out
50TMPDIR = /tmp/build-temp
51BUILD_DATETIME_FILE := $(OUT_DIR)/build_date.txt
52
53# Escape quotation marks for CSV, and wraps in quotation marks.
54define escape-for-csv
55"$(subst ","",$1)"
56endef
57
58# Args:
59# $(1): include stack
60define dump-import-start
61$(eval $(file >> $(DUMPCONFIG_FILE),import,$(strip $(1))))
62endef
63
64# Args:
65# $(1): include stack
66define dump-import-done
67$(eval $(file >> $(DUMPCONFIG_FILE),imported,$(strip $(1))))
68endef
69
70# Args:
71# $(1): Current file
72# $(2): Inherited file
73define dump-inherit
74$(eval $(file >> $(DUMPCONFIG_FILE),inherit,$(strip $(1)),$(strip $(2))))
75endef
76
77# Args:
78# $(1): Config phase (PRODUCT or DEVICE)
79# $(2): Root nodes to import
80# $(3): All variable names
81# $(4): Single-value variables
Joe Onorato64f3db22021-02-05 11:46:03 -080082# $(5): Makefile being processed
83define dump-phase-start
Joe Onoratof20c93a2021-01-19 22:34:22 -080084$(eval $(file >> $(DUMPCONFIG_FILE),phase,$(strip $(1)),$(strip $(2)))) \
85$(foreach var,$(3), \
86 $(eval $(file >> $(DUMPCONFIG_FILE),var,$(if $(filter $(4),$(var)),single,list),$(var))) \
Joe Onorato64f3db22021-02-05 11:46:03 -080087) \
88$(call dump-config-vals,$(strip $(5)),initial)
89endef
90
91# Args:
92# $(1): Makefile being processed
93define dump-phase-end
94$(call dump-config-vals,$(strip $(1)),final)
Joe Onoratof20c93a2021-01-19 22:34:22 -080095endef
96
97define dump-debug
98$(eval $(file >> $(DUMPCONFIG_FILE),debug,$(1)))
99endef
100
101# Skip these when dumping. They're not used and they cause a lot of noise in the dump.
102DUMPCONFIG_SKIP_VARS := \
103 .VARIABLES \
104 .KATI_SYMBOLS \
105 1 \
106 2 \
107 LOCAL_PATH \
108 MAKEFILE_LIST \
109 PARENT_PRODUCT_FILES \
110 current_mk \
111 inherit_var \
112 np \
113 _node_import_context \
114 _included \
115 _include_stack \
116 _in \
117 _nic.%
118
119# Args:
120# $(1): Makefile that was included
Joe Onorato64f3db22021-02-05 11:46:03 -0800121# $(2): block (before,import,after,initial,final)
Joe Onoratof20c93a2021-01-19 22:34:22 -0800122define dump-config-vals
123$(foreach var,$(filter-out $(DUMPCONFIG_SKIP_VARS),$(.KATI_SYMBOLS)),\
124 $(eval $(file >> $(DUMPCONFIG_FILE),val,$(call escape-for-csv,$(1)),$(2),$(call escape-for-csv,$(var)),$(call escape-for-csv,$($(var))),$(call escape-for-csv,$(KATI_variable_location $(var))))) \
125)
126endef
127
128include build/make/core/config.mk
129