| Joe Onorato | f20c93a | 2021-01-19 22:34:22 -0800 | [diff] [blame] | 1 | # 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 | # | 
|  | 8 | ifndef KATI | 
|  | 9 | $(warning Kati must be used to call dumpconfig.mk, not make.) | 
|  | 10 | $(error stopping) | 
|  | 11 | endif | 
|  | 12 |  | 
|  | 13 | ifdef 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) | 
|  | 17 | endif | 
|  | 18 |  | 
|  | 19 | ifndef TARGET_PRODUCT | 
|  | 20 | $(warning dumpconfig.mk requires TARGET_PRODUCT to be set) | 
|  | 21 | $(error stopping) | 
|  | 22 | endif | 
|  | 23 |  | 
|  | 24 | ifndef TARGET_BUILD_VARIANT | 
|  | 25 | $(warning dumpconfig.mk requires TARGET_BUILD_VARIANT to be set) | 
|  | 26 | $(error stopping) | 
|  | 27 | endif | 
|  | 28 |  | 
|  | 29 | ifneq (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) | 
|  | 32 | endif | 
|  | 33 |  | 
|  | 34 | ifeq (,$(DUMPCONFIG_FILE)) | 
|  | 35 | $(warning dumpconfig requires DUMPCONFIG_FILE to be set) | 
|  | 36 | $(error stopping) | 
|  | 37 | endif | 
|  | 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 | 
|  | 44 | dumpconfig: | 
|  | 45 | $(file >> $(DUMPCONFIG_FILE),***DONE***) | 
|  | 46 | @echo ***DONE*** | 
|  | 47 |  | 
|  | 48 | # TODO(Remove): These need to be set externally | 
|  | 49 | OUT_DIR := out | 
|  | 50 | TMPDIR = /tmp/build-temp | 
|  | 51 | BUILD_DATETIME_FILE := $(OUT_DIR)/build_date.txt | 
|  | 52 |  | 
|  | 53 | # Escape quotation marks for CSV, and wraps in quotation marks. | 
|  | 54 | define escape-for-csv | 
|  | 55 | "$(subst ","",$1)" | 
|  | 56 | endef | 
|  | 57 |  | 
|  | 58 | # Args: | 
|  | 59 | #   $(1): include stack | 
|  | 60 | define dump-import-start | 
|  | 61 | $(eval $(file >> $(DUMPCONFIG_FILE),import,$(strip $(1)))) | 
|  | 62 | endef | 
|  | 63 |  | 
|  | 64 | # Args: | 
|  | 65 | #   $(1): include stack | 
|  | 66 | define dump-import-done | 
|  | 67 | $(eval $(file >> $(DUMPCONFIG_FILE),imported,$(strip $(1)))) | 
|  | 68 | endef | 
|  | 69 |  | 
|  | 70 | # Args: | 
|  | 71 | #   $(1): Current file | 
|  | 72 | #   $(2): Inherited file | 
|  | 73 | define dump-inherit | 
|  | 74 | $(eval $(file >> $(DUMPCONFIG_FILE),inherit,$(strip $(1)),$(strip $(2)))) | 
|  | 75 | endef | 
|  | 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 Onorato | 64f3db2 | 2021-02-05 11:46:03 -0800 | [diff] [blame] | 82 | #   $(5): Makefile being processed | 
|  | 83 | define dump-phase-start | 
| Joe Onorato | f20c93a | 2021-01-19 22:34:22 -0800 | [diff] [blame] | 84 | $(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 Onorato | 64f3db2 | 2021-02-05 11:46:03 -0800 | [diff] [blame] | 87 | ) \ | 
|  | 88 | $(call dump-config-vals,$(strip $(5)),initial) | 
|  | 89 | endef | 
|  | 90 |  | 
|  | 91 | # Args: | 
|  | 92 | #   $(1): Makefile being processed | 
|  | 93 | define dump-phase-end | 
|  | 94 | $(call dump-config-vals,$(strip $(1)),final) | 
| Joe Onorato | f20c93a | 2021-01-19 22:34:22 -0800 | [diff] [blame] | 95 | endef | 
|  | 96 |  | 
|  | 97 | define dump-debug | 
|  | 98 | $(eval $(file >> $(DUMPCONFIG_FILE),debug,$(1))) | 
|  | 99 | endef | 
|  | 100 |  | 
|  | 101 | # Skip these when dumping. They're not used and they cause a lot of noise in the dump. | 
|  | 102 | DUMPCONFIG_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 Onorato | 64f3db2 | 2021-02-05 11:46:03 -0800 | [diff] [blame] | 121 | #   $(2): block (before,import,after,initial,final) | 
| Joe Onorato | f20c93a | 2021-01-19 22:34:22 -0800 | [diff] [blame] | 122 | define 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 | ) | 
|  | 126 | endef | 
|  | 127 |  | 
|  | 128 | include build/make/core/config.mk | 
|  | 129 |  |