| #!/bin/bash | |
| # Copyright 2017 The Fuchsia Authors. All rights reserved. | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| ### set build configuration | |
| ## usage: fx set x86|x86-64|arm64|aarch64|gauss|hikey960|odroidc2 | |
| ## [--release] [--packages P1,P2,...] | |
| ## [--build-dir DIR] | |
| ## [--args ARG] [--help-args [ARG]] [--variant VARIANT] | |
| ## [--goma|--no-goma] [--no-ensure-goma] | |
| ## [--goma-dir DIR] | |
| ## [--ccache|--no-ccache] | |
| ## | |
| ## x86 is accepted as an alias for x86-64. | |
| ## arm64 is accepted as an alias for aarch64. | |
| ## | |
| ## Sets build options. | |
| ## | |
| ## optional arguments: | |
| ## --release Build the release variant (e.g., more compiler | |
| ## optimizations, less debugging information). | |
| ## --packages Include the listed packages (separated by commas) in the | |
| ## system build. Defaults to the default set of packages | |
| ## for the current layer (e.g., "garnet/packages/default" | |
| ## for the Garnet layer). If the --package argument is | |
| ## given multiple times, all the specified packages are | |
| ## included in the build. | |
| ## --variant Pass --variant=VARIANT to gen.py, which itself is | |
| ## a shorthand for setting the `select_variant` GN | |
| ## build argument using a standard set of values. | |
| ## Multiple --variant arguments can be used. | |
| ## --args Additional argument to pass to gn. If the --args | |
| ## argument is given multiple times, all the specified | |
| ## arguments are passed to gn. | |
| ## --help-args Display GN arguments documentation. If --help-args | |
| ## is followed by a GN build argument identifier, just | |
| ## that argument's documentation is displayed. | |
| ## If --help-args is used alone, all GN build arguments | |
| ## are displayed (lots of output). | |
| ## --build-dir The directory (relative to FUCHSIA_DIR) into which to | |
| ## generate the build system. Defaults to | |
| ## "out/<variant>-<arch>". | |
| ## --goma|--no-goma Whether to use the goma service during the build. Goma | |
| ## attempts to make builds faster using remote build | |
| ## servers. Defaults to detecting whether goma is installed | |
| ## on your machine. | |
| ## --no-ensure-goma Skip ensuring that goma is started when using goma. | |
| ## --goma-dir The directory where goma is installed. Defaults to | |
| ## ~/goma. | |
| ## --ccache|--no-ccache Whether to use ccache during the build. Ccache attempts | |
| ## to make builds faster by caching build artifacts. | |
| ## Defaults to detecting whether the CCACHE_DIR environment | |
| ## variable is set to a directory. | |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/lib/vars.sh | |
| function main { | |
| if [[ $# -lt 1 ]]; then | |
| fx-command-help | |
| return 1 | |
| fi | |
| local arch= | |
| local zircon_project= | |
| case $1 in | |
| x86 | x86-64) | |
| arch=x86-64 | |
| zircon_project=x86 | |
| ;; | |
| arm64 | aarch64) | |
| arch=aarch64 | |
| zircon_project=arm64 | |
| ;; | |
| gauss) | |
| arch=aarch64 | |
| zircon_project=gauss | |
| ;; | |
| hikey960) | |
| arch=aarch64 | |
| zircon_project=hikey960 | |
| ;; | |
| odroidc2) | |
| arch=aarch64 | |
| zircon_project=odroidc2 | |
| ;; | |
| *) | |
| fx-command-help | |
| return 1 | |
| esac | |
| local gen_args="${gen_args} --target_cpu ${arch} --platforms ${zircon_project}" | |
| shift | |
| local variant=debug | |
| local packages= | |
| local build_dir= | |
| local use_goma | |
| local goma_dir | |
| local ensure_goma=1 | |
| local ccache | |
| while [[ $# -ne 0 ]]; do | |
| case $1 in | |
| --release) | |
| gen_args="${gen_args} --release" | |
| variant=release | |
| ;; | |
| --packages) | |
| if [[ $# -lt 2 ]]; then | |
| fx-command-help | |
| return 1 | |
| fi | |
| if [[ -z "${packages}" ]]; then | |
| packages="$2" | |
| else | |
| packages="${packages},$2" | |
| fi | |
| shift | |
| ;; | |
| --build-dir) | |
| if [[ $# -lt 2 ]]; then | |
| fx-command-help | |
| return 1 | |
| fi | |
| build_dir="$2" | |
| shift | |
| ;; | |
| --goma) | |
| use_goma=1 | |
| ;; | |
| --no-goma) | |
| use_goma=0 | |
| ;; | |
| --no-ensure-goma) | |
| ensure_goma=0 | |
| ;; | |
| --goma-dir) | |
| if [[ $# -lt 2 ]]; then | |
| fx-command-help | |
| return 1 | |
| fi | |
| goma_dir=$2 | |
| if [[ ! -d "${goma_dir}" ]]; then | |
| echo -e "error: GOMA directory does not exist: "${goma_dir}"" | |
| return 1 | |
| fi | |
| shift | |
| ;; | |
| --variant) | |
| if [[ $# -lt 2 ]]; then | |
| fx-command-help | |
| return 1 | |
| fi | |
| gen_args="${gen_args} --variant $2" | |
| shift | |
| ;; | |
| --args) | |
| if [[ $# -lt 2 ]]; then | |
| fx-command-help | |
| return 1 | |
| fi | |
| gen_args="${gen_args} --args $2" | |
| shift | |
| ;; | |
| --help-args) | |
| gen_args="${gen_args} --help-args" | |
| if [[ $# -ge 2 ]] && [[ "$2" != '--*' ]]; then | |
| gen_args="${gen_args} $2" | |
| shift | |
| fi | |
| ;; | |
| --ccache) | |
| ccache=1 | |
| ;; | |
| --no-ccache) | |
| ccache=0 | |
| ;; | |
| *) | |
| fx-command-help | |
| return 1 | |
| esac | |
| shift | |
| done | |
| if [[ -n "${packages}" ]]; then | |
| gen_args="${gen_args} --packages ${packages}" | |
| else | |
| local -r jiri_manifest="${FUCHSIA_DIR}/.jiri_manifest" | |
| # TODO(pylaligand): remove this check once the Fuchsia population has moved | |
| # away from that specific manifest. | |
| if grep -q "\"fuchsia\"" "${jiri_manifest}"; then | |
| echo -e "error: You are using the obsolete 'fuchsia' manifest." | |
| echo -e "error: Please switch to the Topaz manifest instead: fx set-layer topaz" | |
| return 1 | |
| fi | |
| # TODO(abarth): We might want to make this logic more sophisticated once we | |
| # have a mechanism for switching between layers or for selecting which | |
| # layers to build from source. | |
| # If multiple cases below trigger, gen.py will error out because gen.py | |
| # doesn't support multiple --packages arguments. However, we shouldn't get | |
| # into this situation because jiri would have already errored out due to the | |
| # conflicting version requirements of importing 2+ layers at the same time. | |
| if grep -q "manifest/garnet" "${jiri_manifest}"; then | |
| gen_args="${gen_args} --packages garnet/packages/default" | |
| fi | |
| if grep -q "manifest/peridot" "${jiri_manifest}"; then | |
| gen_args="${gen_args} --packages peridot/packages/default" | |
| fi | |
| if grep -q "manifest/topaz" "${jiri_manifest}"; then | |
| gen_args="${gen_args} --packages topaz/packages/default" | |
| fi | |
| if [[ `cat ${jiri_manifest}` =~ vendor/([a-zA-Z0-9_-]+) ]]; then | |
| local -r name="${BASH_REMATCH[1]}" | |
| gen_args="${gen_args} --packages vendor/${name}/packages/default" | |
| fi | |
| fi | |
| if [[ -n "${build_dir}" ]]; then | |
| gen_args="${gen_args} --build-dir ${build_dir}" | |
| else | |
| # gen.py defaults to determining the build directory from the variant and | |
| # the arch. We replicate that logic here rather than passing a redundant | |
| # argument to gen.py. | |
| build_dir="out/${variant}-${arch}" | |
| fi | |
| # If a goma directory wasn't specified explicitly then default to "~/goma". | |
| if [[ -z "${goma_dir}" ]]; then | |
| goma_dir="$HOME/goma" | |
| fi | |
| # Automatically detect goma and ccache if not specified explicitly. | |
| if [[ -z "${use_goma}" ]] && [[ -z "${ccache}" ]]; then | |
| if [[ -d "${goma_dir}" ]]; then | |
| use_goma=1 | |
| elif [[ -n "${CCACHE_DIR}" ]] && [[ -d "${CCACHE_DIR}" ]]; then | |
| ccache=1 | |
| fi | |
| fi | |
| # Add --goma or --ccache as appropriate. | |
| if [[ "${use_goma}" -eq 1 ]]; then | |
| gen_args="${gen_args} --goma ${goma_dir}" | |
| elif [[ "${ccache}" -eq 1 ]]; then | |
| gen_args="${gen_args} --ccache" | |
| fi | |
| # Update print-vars if you add or remove anything from this list. | |
| cat >"${FUCHSIA_CONFIG}" <<END | |
| # Generated by "fx set". | |
| FUCHSIA_BUILD_DIR="${build_dir}" | |
| FUCHSIA_VARIANT="${variant}" | |
| FUCHSIA_ARCH="${arch}" | |
| ZIRCON_PROJECT="${zircon_project}" | |
| END | |
| "${FUCHSIA_DIR}/build/gn/gen.py" ${gen_args} "$@" | |
| if [[ "${use_goma}" -eq 1 ]] && [[ "${ensure_goma}" -eq 1 ]]; then | |
| if ! [[ $("${goma_dir}/gomacc" port) =~ ^[0-9]+$ ]]; then | |
| "${goma_dir}/goma_ctl.py" ensure_start || return $? | |
| fi | |
| fi | |
| } | |
| main "$@" |