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 |
| 82 | define dump-product-var-names |
| 83 | $(eval $(file >> $(DUMPCONFIG_FILE),phase,$(strip $(1)),$(strip $(2)))) \ |
| 84 | $(foreach var,$(3), \ |
| 85 | $(eval $(file >> $(DUMPCONFIG_FILE),var,$(if $(filter $(4),$(var)),single,list),$(var))) \ |
| 86 | ) |
| 87 | endef |
| 88 | |
| 89 | define dump-debug |
| 90 | $(eval $(file >> $(DUMPCONFIG_FILE),debug,$(1))) |
| 91 | endef |
| 92 | |
| 93 | # Skip these when dumping. They're not used and they cause a lot of noise in the dump. |
| 94 | DUMPCONFIG_SKIP_VARS := \ |
| 95 | .VARIABLES \ |
| 96 | .KATI_SYMBOLS \ |
| 97 | 1 \ |
| 98 | 2 \ |
| 99 | LOCAL_PATH \ |
| 100 | MAKEFILE_LIST \ |
| 101 | PARENT_PRODUCT_FILES \ |
| 102 | current_mk \ |
| 103 | inherit_var \ |
| 104 | np \ |
| 105 | _node_import_context \ |
| 106 | _included \ |
| 107 | _include_stack \ |
| 108 | _in \ |
| 109 | _nic.% |
| 110 | |
| 111 | # Args: |
| 112 | # $(1): Makefile that was included |
| 113 | # $(2): block (before,import,after) |
| 114 | define dump-config-vals |
| 115 | $(foreach var,$(filter-out $(DUMPCONFIG_SKIP_VARS),$(.KATI_SYMBOLS)),\ |
| 116 | $(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))))) \ |
| 117 | ) |
| 118 | endef |
| 119 | |
| 120 | include build/make/core/config.mk |
| 121 | |