diff options
author | Will Drewry <drewry@google.com> | 2015-11-02 21:55:03 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-11-02 21:55:03 +0000 |
commit | 9dd31cb924cee7b30b23b4f071343933458272f2 (patch) | |
tree | 02b71de57dd7b720c271aac20ee9ff88ac52ac98 | |
parent | 70c526d69fe8a77344e73acf1f92323d03a5987a (diff) | |
parent | 997086a5690742e1b1d721ec6b94bc0e7d7597fe (diff) | |
download | brillo-m7-dev.tar.gz |
Merge "cfgtree.mk: file-based configuration" into mnc-brillo-devbrillo-m7-releasebrillo-m7-dev
-rw-r--r-- | brillo_base.mk | 9 | ||||
-rw-r--r-- | cfgtree.mk | 71 |
2 files changed, 80 insertions, 0 deletions
diff --git a/brillo_base.mk b/brillo_base.mk index e7e27bf..3101c59 100644 --- a/brillo_base.mk +++ b/brillo_base.mk @@ -34,6 +34,9 @@ OSRELEASED_DIRECTORY := os-release.d PRODUCT_COPY_FILES += \ tools/bdk/VERSION:system/etc/$(OSRELEASED_DIRECTORY)/bdk_version +# Include the cfgtree helpers for loading config values from disk. +include device/generic/brillo/cfgtree.mk + # Skip API checks. WITHOUT_CHECK_API := true # Don't try to build and run all tests by default. Several tests have @@ -318,10 +321,16 @@ define generate-initrc-file endef # Called from the product makefile, it sets any derived defaults. +# DEPRECATED define set-product-defaults $(eval PRODUCT_NAME := $$(basename $$(notdir \ $$(filter $$(LOCAL_PATH)/%.mk,$$(MAKEFILE_LIST))))) endef +# Returns the product name as guessed from the calling file. +define get_product_name_from_file +$(firstword $(basename $(notdir \ + $(filter $(LOCAL_PATH)/%.mk,$(MAKEFILE_LIST))))) +endef HARDWARE_BSP_PREFIX := hardware/bsp HARDWARE_BSP_PREBUILTS_PREFIX := vendor/bsp diff --git a/cfgtree.mk b/cfgtree.mk new file mode 100644 index 0000000..dea3943 --- /dev/null +++ b/cfgtree.mk @@ -0,0 +1,71 @@ +# +# Copyright (C) 2015 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# This file provides a helper which loads the contents of a given file +# relative to a common root path. The helper ensures there is consistent +# path resolution for loading and error messaging for missing or empty +# files that are required. +# +# The primary usage of this file is for loading product-level configuration +# from plaintext files. An example usage in a makefile is: +# BRILLO_CRASH_SERVER := $(call cfgtree_get,brillo/crash_server,required) +# +# Note the use of an immediate assignment. If any other variable assignment is +# used, be sure to test that it resolves as and when expected. +# +# Populating the file is as simple as: +# cd $PRODUCT_DIR +# mkdir -p config/brillo +# echo https://some.server/handle/crash.cgi > config/brillo/crash_server +# +# Any lines beginning with '#' will be ignored, but if a '#' is required, it +# can be inserted by simply starting the line with a space which will be +# stripped off during the loading process. +# +# Note, there is no central mapping of variables to files. If any files will +# be used from different contexts, be sure to keep all users in sync. +# +# For any PRODUCT_* variable set using this mechanism, it is possible to +# verify a correct assignment by calling: +# +# m dump-products +# + +# Path to load from +CFGTREE_ROOT ?= $(LOCAL_PATH) +CFGTREE_PREFIX ?= config +CFGTREE_PATH := $(CFGTREE_ROOT)/$(CFGTREE_PREFIX) + +# Command to run to dump the file content. +CFGTREE_CMD ?= grep -v -e '^$(shell printf '\043')' + +# $(1) is the file to load from cfgtree +# +# Returns the output of $(CFGTREE_CMD) $(1)/$(2) if the file exists. +# Normally, this is all the text excluding lines starting with '#'. +# +define cfgtree-get +$(strip \ + $(if $(filter 0,$(words $(call cfgtree-get-if-exists,$(1)))),\ + $(error Required configuration file \ + $(CFGTREE_PREFIX)/$(1) is empty or missing.),\ + $(call cfgtree-get-if-exists,$(1)))\ +) +endef + +define cfgtree-get-if-exists +$(strip $(shell $(CFGTREE_CMD) $(CFGTREE_PATH)/$(1) 2>/dev/null)) +endef |