# # 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. # """Product Templates This file contains the simplest possible templates for generating scaffolding product files. """ import string ANDROIDPRODUCTS_MK = string.Template("""\ # Automatically generated by brunch. # When editing, always keep the primary product makefile first. PRODUCT_MAKEFILES := $$(LOCAL_DIR)/${product_name}.mk """) PRODUCT_MK = string.Template("""\ # Automatically generated by brunch. include device/generic/brillo/brillo_base.mk $$(call set-product-defaults) PRODUCT_BRAND := Brillo PRODUCT_MANUFACTURER := ${product_manufacturer} PRODUCT_DEVICE := ${product_device} PRODUCT_PACKAGES += \\ """) HELLO_WORLD_MK = string.Template("""\ # Automatically generated by brunch. include device/generic/brillo/brillo_base.mk $$(call set-product-defaults) PRODUCT_BRAND := Brillo PRODUCT_MANUFACTURER := ${product_manufacturer} PRODUCT_DEVICE := ${product_device} PRODUCT_PACKAGES += \\ helloservice.${product_name} \\ """) SRC_HELLOSERVICE_ANDROID_MK = string.Template("""\ LOCAL_PATH := $$(call my-dir) include $$(CLEAR_VARS) LOCAL_MODULE := helloservice.${product_name} LOCAL_SRC_FILES := helloservice.cpp LOCAL_SHARED_LIBRARIES := libc libbase LOCAL_CFLAGS := -Werror include $$(BUILD_EXECUTABLE) """) SRC_HELLOSERVICE_HELLOSERVICE_CPP = string.Template("""\ #include #include int main(int argc __unused, char **argv __unused) { LOG(INFO) << "starting"; while (1) { LOG(INFO) << "loop iteration"; sleep(5); } LOG(INFO) << "exiting"; return 0; } """) BDK_BANNER = string.Template("""\ bdk_banner() { echo Environment configured for product \\""${product_name}"\\". echo Using Brillo Development Kit v."${bdk_version}" from "${bdk_path}" echo echo "${bdk_warning}" echo echo Available commands: echo brunch, m, mm, adb, fastboot, provision } bdk_banner """) ENV_EXPORTS = string.Template("""\ export BDK_PATH="${bdk_path}" # Put the brunch in your path. export PATH=${brunch_path}:$$PATH # For adb, fastboot. export ANDROID_PRODUCT_OUT="${target_out}" export ANDROID_BUILD_TOP="${product_path}/out/.bdk" """) ENV_ALIASES = string.Template("""\ m() { brunch product build -p=${product_path} -- "$$@" } mm() { brunch product build -s -p=${product_path} -- "$$@" } adb() { brunch product tool -p=${product_path} adb "$$@" } fastboot() { brunch product tool -p=${product_path} fastboot "$$@" } provision() { brunch product provision -p=${product_path} "$$@" } """) # Inside this template, brunch is re-called to export an updated # environment. To do so, the output is packed into an fd and then # source'd by the shell. The approach is messier than using <() # in order to avoid a specific bashism and keep this part dash clean. # That is yet to be a requirement across all the scripts, though. ENVSETUP = string.Template("""\ _envsetup_load() { # Allow the environment to override the BDK path. local bdk="$${BDK_PATH:-${bdk_path}}" if ! test -x "$${bdk}/tools/bdk/brunch/brunch"; then echo "The BDK cannot be found." 1>&2 echo "Please supply its path in the BDK_PATH environment variable or " 1>&2 echo "run 'brunch product reconfig'" 1>&2 return 1 fi # Make sure we're in the root of a product. # If the user explicitly exported a PRODUCT_PATH, then fail if it is wrong. if test -n "$${PRODUCT_PATH}" && \ ! test -e "$${PRODUCT_PATH}/.brunch_product.db"; then echo "Cannot find a product at PRODUCT_PATH: $${PRODUCT_PATH}" 1>&2 return 1 fi # Otherwise, use the default or check the cwd. local product_path="$${PRODUCT_PATH:-${product_path}}" if ! test -e "$${product_path}/.brunch_product.db"; then echo "Checking current directory for a valid product . . ." 1>&2 product_path=$$PWD if ! test -e "$${product_path}/.brunch_product.db"; then echo "Please source envsetup.sh from the product directory " 1>&2 echo "or set a valid PRODUCT_PATH in the environment." 1>&2 return 1 fi fi # Find a free file descriptor and use it rather than a tempfile. fd=$$((`ls /dev/fd/ | sort -n | tail -1` + 1)) eval 'exec '$$fd'<