• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2#
3# Copyright 2020 The ChromiumOS Authors
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# Used for first time generation of the basic structure of a project.
8
9# Exit if any command fails.
10set -e
11
12function usage() {
13  echo "Usage: $0 <config dir> <program name> <program dir> <project name> <project dir>" >&2
14  echo "where" >&2
15  echo "  <config_dir> is the mount path of the chromiumos/config repo" >&2
16  echo "  <program name> is the name of the program the project belongs to" >&2
17  echo "  <program dir> is the mount path of the program repo" >&2
18  echo "  <project name> is name of the new project" >&2
19  echo "  <project dir> is directory to generate the new project config in" >&2
20  exit 1
21}
22
23function _make_symlink() {
24  local target="${1}"
25  local name="${2}"
26  # Shift target and name off, remaining arguments used as ln options.
27  shift 2
28  if [[ -e "${name}" ]]; then
29    echo "${name} already exists, skipping symlinking."
30  else
31    echo "Symlinking ${target} to ${name}."
32    ln "${@}" "${target}" "${name}"
33  fi
34}
35
36function make_relative_symlink() {
37  _make_symlink "${1}" "${2}" -sr
38}
39
40function make_symlink() {
41  _make_symlink "${1}" "${2}" -s
42}
43
44function write_project_config() {
45  local file="${1}"
46  local program="${2}"
47  local project="${3}"
48  cat << EOF > "${file}"
49#!/usr/bin/env gen_config
50
51"""Generates a ConfigBundle proto for the ${project} project."""
52
53load("//components_config.star", "COMPONENTS", "COMPONENT_VENDORS")
54load("//config/util/config_bundle.star", "config_bundle")
55load("//config/util/design.star", "design")
56load("//config/util/hw_topology.star", "hw_topo")
57load("//device_brand_config.star", "device_brand_config")
58load("//fw_version_config.star", "SC_FW_CONFIG_${project^^}")
59load("//program/program.star", "program")
60
61_${project^^}="${project^}"
62
63_DESIGN_ID = design.create_design_id(_${project^^})
64
65_CLAMSHELL = hw_topo.create_form_factor(hw_topo.ff.CLAMSHELL)
66
67_HW_TOPO = hw_topo.create_hardware_topology(
68    form_factor = _CLAMSHELL,
69)
70
71_FW_BUILD_CONFIG = None
72
73_AUDIO = None
74
75_SW_CONFIGS = []
76_HW_CONFIGS = []
77
78design.append_configs(
79    sw_configs=_SW_CONFIGS,
80    hw_configs=_HW_CONFIGS,
81    design_id=_DESIGN_ID,
82    config_id=design.UNPROVISIONED_CONFIG_ID,
83    hardware_topology=_HW_TOPO,
84    firmware_build_config=_FW_BUILD_CONFIG,
85    audio=_AUDIO,
86    firmware = SC_FW_CONFIG_${project^^},
87)
88
89_DESIGN = design.create_design(
90    id=_DESIGN_ID,
91    program_id=program.${program}.id,
92    odm_id=None,
93    configs=_HW_CONFIGS,
94)
95
96_CONFIG_BUNDLE = config_bundle.create(
97    designs=[_DESIGN],
98    software_configs = _SW_CONFIGS,
99    device_brands = device_brand_config.DEVICE_BRAND_LIST,
100    components = COMPONENTS,
101    partners = device_brand_config.ODMs + device_brand_config.OEMs + COMPONENT_VENDORS,
102    brand_configs = device_brand_config.BRAND_CONFIGS,
103)
104
105design.generate(_CONFIG_BUNDLE)
106EOF
107}
108
109function write_project_components() {
110  local file="${1}"
111  local project="${2}"
112  cat << EOF > "${file}"
113# Components and Component vendors configuration for ${project^}
114
115load("//config/util/partner.star", "partner")
116load("//config/util/component.star", "comp")
117
118COMPONENT_VENDORS = []
119COMPONENTS = []
120EOF
121}
122
123function write_device_brand_config() {
124  local file="${1}"
125  local project="${2}"
126  cat << EOF > "${file}"
127# Device brands, brand configs and partner configuration for ${project^}
128
129load("//config/util/partner.star", "partner")
130load("//config/util/design.star", "design")
131load("//config/util/device_brand.star", "device_brand")
132load("//config/util/brand_config.star", "brand_config")
133
134_ODMs = []
135_OEMs = []
136
137DESIGN_ID_${project^^} = design.create_design_id("${project^}")
138
139_DESIGN_ID_LIST = [DESIGN_ID_${project^^}]
140
141DEVICE_BRAND_${project^^}_ZZCR = device_brand.create(
142    brand_name = "",
143    oem_id = None,
144    brand_code = "ZZCR",
145    design_id = DESIGN_ID_${project^^},
146)
147
148_DEVICE_BRAND_LIST = [DEVICE_BRAND_${project^^}_ZZCR]
149
150_BRAND_CONFIGS = []
151
152device_brand_config = struct(
153    ODMs = _ODMs,
154    OEMs = _OEMs,
155    DESIGN_ID_LIST = _DESIGN_ID_LIST,
156    DEVICE_BRAND_LIST = _DEVICE_BRAND_LIST,
157    BRAND_CONFIGS = _BRAND_CONFIGS,
158)
159EOF
160}
161
162function write_fw_version_config() {
163  local file="${1}"
164  local project="${2}"
165  cat << EOF > "${file}"
166# Software firmware configuration for ${project^}
167
168load("//config/util/sw_config.star", sc = "sw_config")
169
170SC_FW_CONFIG_${project^^} = sc.create_fw_payloads_by_names(
171    ap_fw_name = "",
172    ec_fw_name = "",
173    ap_ro_version = sc.create_fw_version(0, 0, 0),
174    ap_rw_a_hash = None,
175    ap_rw_version = sc.create_fw_version(0, 0, 0),
176    ec_ro_version = sc.create_fw_version(0, 0, 0),
177)
178EOF
179}
180
181function write_program_config() {
182  local file="${1}"
183  local program="${2}"
184  cat << EOF > "${file}"
185#!/usr/bin/env gen_config
186
187# Copyright $(date +%Y) The ChromiumOS Authors
188# Use of this source code is governed by a BSD-style license that can be
189# found in the LICENSE file.
190
191"""Generates a ConfigBundle proto for the ${program} program."""
192
193load("//config/util/config_bundle.star", "config_bundle")
194load("//program.star", "program")
195load("//config/util/program.star", program_util = "program")
196
197_CONFIG = config_bundle.create(
198    programs = [program.${program}],
199)
200
201program_util.generate(_CONFIG)
202EOF
203}
204
205function write_program_signer() {
206  local file="${1}"
207  cat << EOF > "${file}"
208# Copyright $(date +%Y) The ChromiumOS Authors
209# Use of this source code is governed by a BSD-style license that can be
210# found in the LICENSE file.
211
212load("//config/util/program.star", program_util = "program")
213
214_SIGNER_BRAND_CONFIGS = program_util.create_signer_configs_by_brand(
215    {
216    },
217)
218
219_SIGNER_DESIGN_CONFIGS = program_util.create_signer_configs_by_design(
220    {
221    },
222)
223
224SIGNER_CONFIGS = _SIGNER_BRAND_CONFIGS + _SIGNER_DESIGN_CONFIGS
225EOF
226}
227
228function write_program_program() {
229  local file="${1}"
230  local program="${2}"
231  cat << EOF > "${file}"
232# Copyright $(date +%Y) The ChromiumOS Authors
233# Use of this source code is governed by a BSD-style license that can be
234# found in the LICENSE file.
235
236load("//config/util/design.star", "design")
237load("//config/util/device_brand.star", device_brand = "device_brand")
238load("//config/util/hw_topology.star", "hw_topo")
239load("//config/util/program.star", program_util = "program")
240load("//program_configs/signer_config.star", "SIGNER_CONFIGS")
241
242_FEATURE_CONSTRAINTS = design.create_constraints(
243    hw_topo.create_features(),
244)  # Default for now
245
246_${program^^} = program_util.create(
247    name = "${program^}",
248    constraints = _FEATURE_CONSTRAINTS,
249    device_signer_configs = SIGNER_CONFIGS,
250)
251
252program = struct(
253    ${program} = _${program^^},
254)
255EOF
256}
257
258function write_git_ignore() {
259  cat << EOF > .gitignore
260.venv
261EOF
262}
263
264if [[ $# -ne 5 ]]; then
265  usage
266fi
267
268config_dir="$(realpath -e "${1}")"
269program="${2}"
270program_dir="$(realpath -e "${3}")"
271project="${4}"
272project_dir="$(realpath -e "${5}")"
273
274# Move to the project directory.
275cd "${project_dir}"
276
277make_relative_symlink "${config_dir}" config
278make_symlink config/presubmit/_PRESUBMIT.cfg PRESUBMIT.cfg
279make_symlink config/presubmit/_PROJECT_PRESUBMIT.py PRESUBMIT.py
280
281if [[ -e config.star ]]; then
282  echo "Project config.star already existing, skipping."
283else
284  echo "Writing project config.star."
285  write_project_config config.star "${program}" "${project}"
286  chmod 750 config.star
287fi
288if [[ -e components_config.star ]]; then
289  echo "Project components_config.star already existing, skipping."
290else
291  echo "Writing project components_config.star."
292  write_project_components components_config.star "${project}"
293fi
294if [[ -e device_brand_config.star ]]; then
295  echo "Project device_brand_config.star already existing, skipping."
296else
297  echo "Writing project device_brand_config.star."
298  write_device_brand_config device_brand_config.star "${project}"
299fi
300if [[ -e fw_version_config.star ]]; then
301  echo "Project fw_version_config.star already existing, skipping."
302else
303  echo "Writing project fw_version_config.star."
304  write_fw_version_config fw_version_config.star "${project}"
305fi
306make_relative_symlink "${program_dir}" program
307make_relative_symlink "${program_dir}/program_configs" program_configs
308make_relative_symlink "${config_dir}" program/config
309
310if [[ -e program/config.star ]]; then
311  echo "Program config.star already existing, skipping."
312else
313  echo "Writing program config.star."
314  write_program_config program/config.star "${program}"
315  chmod 750 program/config.star
316fi
317
318if [[ -e program/program.star ]]; then
319  echo "Program program.star already existing, skipping."
320else
321  echo "Writing program program.star."
322  write_program_program program/program.star "${program}"
323fi
324
325if [[ -e program/program_configs/signer_config.star ]]; then
326  echo "Program signer_config.star already existing, skipping."
327else
328  echo "Writing program signer_config.star."
329  mkdir -p program/program_configs
330  write_program_signer program/program_configs/signer_config.star
331fi
332
333write_git_ignore
334