aboutsummaryrefslogtreecommitdiff
path: root/brunch/lib/core/product_templates.py
blob: 332e9360c98f58aff32cec35c893ba0513809711 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#
# 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 <unistd.h>
#include <base/logging.h>
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'<<EOFEOF
  $$($${bdk}/tools/bdk/brunch/brunch product envsetup \\
    --product_path="$${product_path}")
EOFEOF'
  . /dev/fd/$$fd
  eval "exec $$fd<&-"
}
_envsetup_load
""")