| #!/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. |
| |
| ### build Fuchsia |
| |
| ## usage: fx build [ninja option,...] [target,...] |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/lib/vars.sh |
| fx-config-read |
| |
| function main { |
| # macOS needs a lower value of -j parameter, because it has a limit on the |
| # number of open file descriptors. Use 4 * cpu_count, which works well in |
| # practice. |
| local concurrency_args= |
| if grep -q "use_goma = true" "${FUCHSIA_BUILD_DIR}/args.gn"; then |
| if [[ "$(uname -s)" = "Darwin" ]]; then |
| numjobs=$(( $(sysctl -n hw.ncpu) * 4 )) |
| concurrency_args="-j ${numjobs}" |
| else |
| concurrency_args="-j 1000" |
| fi |
| fi |
| |
| local env_args= |
| |
| # PATH is required to find a number of tools on the host system. |
| if [[ -n "${PATH}" ]]; then |
| env_args="${env_args} PATH=${PATH}" |
| fi |
| |
| # TERM is required by ninja to print status messages on the same line. |
| if [[ -n "${TERM}" ]]; then |
| env_args="${env_args} TERM=${TERM}" |
| fi |
| |
| # TMPDIR is required by goma on Mac OS X. |
| if [[ -n "${TMPDIR}" ]]; then |
| env_args="${env_args} TMPDIR=${TMPDIR}" |
| fi |
| |
| env -i ${env_args} \ |
| "${FUCHSIA_DIR}/buildtools/ninja" ${concurrency_args} -C "${FUCHSIA_BUILD_DIR}" "$@" |
| } |
| |
| main "$@" |