diff --git a/docs/development/benchmarking/running_on_ci.md b/docs/development/benchmarking/running_on_ci.md index 82639b866ebc1c5fb7b1909143d8e05ab9e9afcf..4ac0ebc18e2264f2e7b114b13618c70c826cda59 100644 --- a/docs/development/benchmarking/running_on_ci.md +++ b/docs/development/benchmarking/running_on_ci.md @@ -46,11 +46,10 @@ At this point, you're ready to build Fuchsia and test that your benchmark runs successfully. Run the following in a shell: ```sh -fx set-petal $layer jiri update -gc # Benchmarks are not included in production packages, so use $layer/packages/kitchen_sink # or they will not be built. -fx set <arch> --monolith $layer/packages/kitchen_sink +fx set core.<board> --with //bundles:kitchen_sink fx full-build && fx run ``` diff --git a/docs/development/build/build_information.md b/docs/development/build/build_information.md index a2f9b3447364654c534213ec6d1560ca204ccaec..667b949be3258347dd5614d124d6d17459fb5de1 100644 --- a/docs/development/build/build_information.md +++ b/docs/development/build/build_information.md @@ -10,16 +10,16 @@ To access this data, add the feature "build-info" to the [component manifest](.. `/config/build-info/product` ## Description -String describing the product configuration used at build time. Defaults to the value passed to “--products†in fx set. -Example: “garnet/products/default.gniâ€, “topaz/products/dashboard.gni†+String describing the product configuration used at build time. Defaults to the value passed as PRODUCT in fx set. +Example: “products/core.gniâ€, “products/workstation.gni†# Board ## Location `/config/build-info/board` ## Description -String describing the board configuration used at build time to specify the target hardware. Defaults to the value passed to “--boards†in fx set. -Example: “garnet/boards/x64.gni†+String describing the board configuration used at build time to specify the target hardware. Defaults to the value passed as BOARD in fx set. +Example: “boards/x64.gni†# Version ## Location diff --git a/docs/development/build/overview.md b/docs/development/build/overview.md index 12d36efae4a6aef783d5e3b46d0bc901208ae86b..325707dfb3d0642fc2dc4c8e067c984bed0a6e9d 100644 --- a/docs/development/build/overview.md +++ b/docs/development/build/overview.md @@ -81,19 +81,17 @@ For a list of all options, run `build-zircon.sh -h`. See Zircon's Then configure the content of the generated image by choosing the top level product to build: ``` -# --product can be omitted to use the defaults, which is -# $layer/products/default.gni. -$ buildtools/gn gen out/x64 --args='import("//products/core.gni") monolith+=["garnet/packages/my_stuff"]' +$ buildtools/gn gen out/default --args='import("//boards/x64.gni") import("//products/core.gni")' ``` -This will create an `out/x64` directory containing Ninja files. +This will create an `out/default` directory containing Ninja files. The equivalent fx set command is: ``` -$ scripts/fx set x64 --product core --monolith garnet/packages/my_stuff +$ scripts/fx set core.x64 ``` -For a list of all GN build arguments, run `buildtools/gn args out/x64 --list`. +For a list of all GN build arguments, run `buildtools/gn args out/default --list`. For documentation on the `select_variant` argument, see [Variants](variants.md). ### C @@ -136,13 +134,13 @@ $ dot -Tpng tree.dot -o tree.png ### Inspecting the content of a GN target ```bash -$ buildtools/gn desc out/x64 //path/to/my:target +$ buildtools/gn desc out/default //path/to/my:target ``` ### Finding references to a GN target ```bash -$ buildtools/gn refs out/x64 //path/to/my:target +$ buildtools/gn refs out/default //path/to/my:target ``` ### Referencing targets for the build host @@ -165,7 +163,7 @@ file: If a target is defined in a GN build file as `//foo/bar/blah:dash`, that target (and its dependencies) can be built with: ```bash -$ buildtools/ninja -C out/x64 -j64 foo/bar/blah:dash +$ buildtools/ninja -C out/default -j64 foo/bar/blah:dash ``` Note that this only works for targets in the default toolchain. @@ -180,7 +178,7 @@ $ buildtools/gn help ninja_rules You can also browse the set of Ninja targets currently defined in your output directory with: ```bash -$ buildtools/ninja -C out/x64 -t browse +$ buildtools/ninja -C out/default -t browse ``` Note that the presence of a Ninja target does not mean it will be built - for that it needs to depend on the “default†target. diff --git a/docs/development/build/variants.md b/docs/development/build/variants.md index 27271e3c3f76eef86901ff18869c9c0233a43282..52ed629f3cdccee9917a6b96fa349663c142ca8e 100644 --- a/docs/development/build/variants.md +++ b/docs/development/build/variants.md @@ -19,15 +19,15 @@ detailed GN syntax. For simple cases, this can just be a list of strings. Using `fx set`: ```sh -fx set x64 --variant={host_asan,asan/cat,asan/ledger} --board=topaz/boards/x64.gni +fx set core.x64 --variant={host_asan,asan/cat,asan/ledger} ``` Alternatively, you can add or modify the variants on an existing build by editing the GN args (substituting your build's GN output directory -for `out/x64` as necessary): +for `out/default` as necessary): ```sh -./buildtools/gn args out/x64 +./buildtools/gn args out/default ``` That command will bring up an editor. Append to that file: diff --git a/docs/development/languages/rust/README.md b/docs/development/languages/rust/README.md index b666e0f3a8df5069bb1774f21314263a0bea082d..3899f9d59929b50a02128ded7e74aa9e59ba2753 100644 --- a/docs/development/languages/rust/README.md +++ b/docs/development/languages/rust/README.md @@ -19,7 +19,7 @@ If you want to test out Fuchsia with your own custom-built versions of rustc or cargo, you can set the `rustc_prefix` argument to `fx set`, like this: ``` -fx set x64 --release --args "rustc_prefix=\"/path/to/bin/dir\"" +fx set core.x64 --release --args "rustc_prefix=\"/path/to/bin/dir\"" ``` ## Cargo.toml diff --git a/docs/development/sdk/README.md b/docs/development/sdk/README.md index 52086ed818663a369239d1588d7dfbfdf9b8ba80..2414964ac1f953e3e4017d086e6ae4923e08a2b9 100644 --- a/docs/development/sdk/README.md +++ b/docs/development/sdk/README.md @@ -107,13 +107,13 @@ under `//out/<build-type>/sdk/archive/<sdk-name>.tar.gz`. For example, to build the topaz SDK for x64: ```sh -$ fx set x64 --product sdk_image --available //topaz/packages/sdk:topaz \ +$ fx set sdk_image.x64 --with //topaz/packages/sdk:topaz \ --args build_sdk_archives=true $ fx build-zircon $ fx build topaz/public/sdk:topaz ``` -Then the archive file will be in `out/x64/sdk/archive/topaz.tar.gz`. +Then the archive file will be in `out/default/sdk/archive/topaz.tar.gz`. ### Adding content to an SDK diff --git a/docs/development/workflows/build_and_pave_quickstart.md b/docs/development/workflows/build_and_pave_quickstart.md index 2ea1eb9227e64f08af520b0577c0ef24530952b0..ee5dfc2ebddd82b5a5010266f7dc4f28935a7196 100644 --- a/docs/development/workflows/build_and_pave_quickstart.md +++ b/docs/development/workflows/build_and_pave_quickstart.md @@ -8,8 +8,10 @@ have options for less common situations; see `fx help <command>` for details. The initial build and deploy workflow using `fx` is as follows: -1. `fx set <arch>` - Configures the build for <arch>: one of [x64, arm64]. +1. `fx set core.x64` + Configures the build to build the "core" product on a generic x64 board. + See `fx list-products` and `fx list-boards` for lists of available products + and boards, respectively. 1. `fx full-build` Builds Zircon, then the rest of Fuchsia. 1. `fx mkzedboot <usb_drive_device_path>` diff --git a/docs/development/workflows/fx.md b/docs/development/workflows/fx.md index bf7bf0744e452f1e97f137bea571c9d68f164fde..350b3d0f3bbf21ef4a8bae26ce28bfd3b91ade58 100644 --- a/docs/development/workflows/fx.md +++ b/docs/development/workflows/fx.md @@ -53,7 +53,6 @@ build Fuchsia, and then get it onto a device. `fx` has some commands to help with this: * `fx set` [configure a build](#configure-a-build) -* `fx set2` [configure a build (BETA)](#configure-a-build-beta) * `fx full-build` [execute a build](#execute-a-build) * `fx flash ; fx mkzedboot` [flash a target; or prepare a zedboot USB key](#flash-a-board) * `fx serve` [serve a build](#serve-a-build) @@ -72,15 +71,6 @@ First let's configure the build. To do this we need to make a few choices: ## Configure a build -Armed with our above choices (if you didn't read above, do so now), you are -ready to configure your build: - -```shell -$ fx set x64 --product workstation --board x64 --preinstall bundles/tools --available bundles/tests -``` - -## Configure a build (BETA) - *We are working on a new command for configuring a build. This section describes the new command, which is currently being beta-tested.* @@ -88,7 +78,7 @@ Armed with our above choices (if you didn't read above, do so now), you are ready to configure your build: ```shell -$ fx set2 workstation.x64 --with //bundles:tools,//bundles:tests +$ fx set workstation.x64 --with //bundles:tools,//bundles:tests ``` This command stores the configuration in an `args.gn` file in the build @@ -449,11 +439,11 @@ keep several different devices in several build configurations, and could be setup as follows: ```shell -$ fx set x64 out/workstation --product workstation +$ fx set workstation.x64 --build-dir out/workstation $ fx full-build $ fx set-device <workstation-node-name> -$ fx set arm64 out/core --product core +$ fx set core.arm64 --build-dir out/core $ fx full-build $ fx set-device <core-node-name> @@ -465,14 +455,6 @@ $ fx use out/core $ fx shell ``` -If you are using the `fx set2` command, which will eventually replace `fx set`, -the corresponding commands are below: - -```shell -$ fx set2 workstation.x64 --build-dir out/workstation -$ fx set2 core.arm64 --build-dir out/core -``` - Additionally, for users who wish to execute a command against a single Fuchsia device from the current default build directory, as a one-off command, the `fx` global flag `-d` allows overriding the target node name for diff --git a/docs/development/workflows/libfuzzer.md b/docs/development/workflows/libfuzzer.md index fa41c0705ac9553c28b6ae3f72a83517b5bbe739..4ace92ce7ceb385e8d5ee664cef5730fda6206bc 100644 --- a/docs/development/workflows/libfuzzer.md +++ b/docs/development/workflows/libfuzzer.md @@ -8,7 +8,7 @@ data to your library. * Fuchsia: Add a [`fuzz-target`][gn fuzz target] and [`fuzz-package`][gn fuzz package] to the library's BUILD.gn * Zircon: Add a [`fuzztest`](#q-how-do-i-create-a-zircon-fuzzer-) to the library's rules.mk. -1. `fx set --fuzz-with asan`, `fx build`, and boot. +1. `fx set core.x64 --fuzz-with asan`, `fx build`, and boot. 1. Run `fx fuzz list` to display fuzzers. 1. Run `fx fuzz start <fuzzer>` to start a fuzzer. 1. Run `fx fuzz check <fuzzer>` to see if the fuzzer found crashes. @@ -260,7 +260,7 @@ __IMPORTANT__: The build system will build the fuzz targets __only__ if it is ex instrument them for fuzzing with an appropriate sanitizer. The easiest way to achieve this is using the `--fuzz-with <sanitizer>` flag with `fx set`, e.g: ``` -$ fx set x64 --fuzz-with asan --monolith garnet/packages/tests/all +$ fx set core.x64 --fuzz-with asan --with //bundles:tests $ fx full-build ``` @@ -328,7 +328,7 @@ Build this package as you would any other fuzz package, and finally use the `fx include the correct dependencies for you Zircon fuzzer in a Fuchsia build: ```sh -$ fx set x64 --fuzz-with asan --monolith garnet/packages/garnet --monolith garnet/packages/tests/zircon +$ fx set core.x64 --fuzz-with asan --with //garnet/packages/tests:zircon $ fx full-build $ fx fuzz zbi ``` diff --git a/docs/development/workflows/paving.md b/docs/development/workflows/paving.md index 8ba99d96ec56cfdbab5c4585fdf724f2ffa7be71..dc64ccfe1f1e8a39c4d5d65205fc2eb2068c0101 100644 --- a/docs/development/workflows/paving.md +++ b/docs/development/workflows/paving.md @@ -99,4 +99,4 @@ system paved on the target between local booting and Zedboot for network booting. By default the system boots locally with a 1-second delay in Gigaboot to allow you to select a different mode. To change this default to Zedboot, supply the `always_zedboot` argument when calling your set command, for example -`fx set <target_type> --args "always_zedboot=true"`. +`fx set <goal> --args "always_zedboot=true"`. diff --git a/docs/development/workflows/workflow_tips_and_faq.md b/docs/development/workflows/workflow_tips_and_faq.md index b5788ad1d96984d76dce08a335ccc245b4ab12cf..6442a827910eac4bdeea832400b1e759c45082be 100644 --- a/docs/development/workflows/workflow_tips_and_faq.md +++ b/docs/development/workflows/workflow_tips_and_faq.md @@ -280,20 +280,20 @@ combination you pick, we just need to start building Zircon. ```shell # We start with bringup, because it's small, but it doesn't matter which you start with: -$ fx set x64 out/bringup.x64 --product bringup +$ fx set bringup.x64 out/bringup.x64 $ fx --dir=out/bringup.x64 full-build ``` Now you have Zircon built, you can start building several other builds concurrently: ```shell -$ fx set x64 out/workstation.x64 --product workstation +$ fx set workstation.x64 out/workstation.x64 $ fx --dir out/workstation.x64 full-build > workstation.x64.build.log & -$ fx set arm64 out/core.vim2 --product core +$ fx set core.arm64 out/core.vim2 $ fx --dir out/core.vim2 full-build > core.vim2.build.log & -$ fx set arm64 out/workstation.vim2 --product workstation +$ fx set workstation.arm64 out/workstation.vim2 $ fx --dir out/workstation.vim2 full-build > workstation.vim2.build.log & ``` diff --git a/docs/getting_started.md b/docs/getting_started.md index 394d002c8270e2ea56d02e7be43208f989259d48..42c74becc59247e8e1ea97c60c66e0f5dbdc4f8a 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -54,7 +54,7 @@ the `fx` command should already be in your path. If not, the command is also available as `scripts/fx`. ``` -fx set x64 --available bundles/kitchen_sink +fx set core.x64 --with //bundles:kitchen_sink fx full-build ``` @@ -79,9 +79,9 @@ you want something else. Run `fx set` to see a list of build options. Some examples: ``` -fx set x64 # x64 debug build -fx set arm64 # arm64 debug build -fx set x64 --release # x64 release build +fx set workstation.x64 # x64 debug build +fx set core.arm64 # arm64 debug build +fx set core.x64 --release # x64 release build ``` #### [optional] Accelerate builds with `ccache` and `goma` diff --git a/scripts/devshell/list-boards b/scripts/devshell/list-boards index 1ebe0303221ff7f96787e13f5e097b52f787fdac..56e293d05fe547797116e14733dfac144d19f856 100755 --- a/scripts/devshell/list-boards +++ b/scripts/devshell/list-boards @@ -8,7 +8,7 @@ ## usage: fx list-boards ## ## Lists all boards that are available for building. These are names that -## can be passed to `fx set --board` +## can be passed to `fx set` source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? diff --git a/scripts/devshell/list-products b/scripts/devshell/list-products index 9c462ee0a856c513d1ca3d56a685b1d8b14b922e..17f4dbd0bbd992fcef91d78b7a6ff5ab7cd64af2 100755 --- a/scripts/devshell/list-products +++ b/scripts/devshell/list-products @@ -8,7 +8,7 @@ ## usage: fx list-products ## ## Lists all products that are available for building. These are names that -## can be passed to `fx set --product` +## can be passed to `fx set` source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? diff --git a/scripts/devshell/oldset b/scripts/devshell/oldset new file mode 100755 index 0000000000000000000000000000000000000000..b6be026e6e2d8703b57702d0e981c7f52730e501 --- /dev/null +++ b/scripts/devshell/oldset @@ -0,0 +1,489 @@ +#!/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 up a build directory + +## usage: fx oldset TARGET [OUTDIR] +## [--board NAME|PATH] +## [--product NAME|PATH] +## [--monolith PATH] +## [--preinstall PATH] +## [--available PATH] +## [--netboot] +## [--args ARG] [--help-args [ARG]] [--variant VARIANT] +## [--goma|--no-goma] [--no-ensure-goma] +## [--goma-dir DIR] +## [--ccache|--no-ccache] +## [--release] +## [--zircon-arg ARG] +## +## where TARGET is x64 or arm64 +## +## OUTDIR is the directory where the build output goes. +## If it begins with `//` or `out/` then it's taken as relative to FUCHSIA_DIR. +## Otherwise it should be an absolute path or a path relative to the current +## working directory that winds up in `FUCHSIA_DIR/out`. +## It defaults to `out/TARGET`. +## +## This is a wrapper around running `gn gen --check OUTDIR --args ...`. +## If GN fails with an error, `fx oldset` does not change anything. +## If GN succeeds, this also points subsequent `fx` commands at OUTDIR, +## just as `fx use` does and ensures Goma is ready (if enabled). +## +## NAME|PATH can be provided as arguments to --board and --product. In the +## case of NAME the name is searched for in //layer/board/NAME.gni, otherwise it +## is treated as a PATH. +## +## optional arguments: +## --board Use the given board target definition. Board +## configurations are used to modulate hardware specific +## behavior, such as configuring the set of drivers +## included, or adding peripheral specific configurations. +## If no board is given, a default board for the architecture +## is selected from the current layer, e.g. +## garnet/boards/x64.gni. +## --product Include the given product in the build. Defaults to +## the default product for the current layer (e.g., +## "garnet/products/default.gni" for the Garnet layer). +## Product configurations define a set of packages to be +## included in the monolith, preinstall and available +## package sets, as well as product oriented configurations. +## --monolith Additional packages to be built and included in the +## monolithic system image. Monolith is the set of packages +## that make up an OTA image. +## If the --monolith argument is given multiple times, +## all the specified packages are included in this set. +## These packages are added to the available set defined +## by the board and product specifications. +## --preinstall Additional packages to be built and included in the +## system image alongside the monolithic system image. +## Packages in preinstall are not part of OTA updates, +## instead they are updated dynamically. +## If the --preinstall argument is given multiple times, +## all the specified packages are included in this set. +## These packages are added to the available set defined +## by the board and product specifications. +## --available Additional packages to be built and included in the +## set of packages available for pushing dynamically. +## If the --available argument is given multiple times, +## all the specified available are included in this set. +## These packages are added to the available set defined +## by the board and product specifications. +## --netboot Ensure that a network ramboot image is always built. +## --variant Pass a `select_variant=[VARIANT*,...]` GN build argument +## collecting all the --variant arguments in order. +## --fuzz-with Pass a sanitizer name, e.g. "--fuzz-with asan" to +## enable ALL supporting fuzzers. Use --variant for +## individual fuzzers, e.g. "--variant asan-fuzzer/foo". +## --args Additional argument to pass to gn. If the --args +## argument is given multiple times, all the specified +## arguments are passed to gn. +## N.B. Arguments must be expressed using GN's syntax. +## In particular this means that for strings they must +## be quoted with double-quotes, and the quoting must +## survive, for example, the shell. Thus when passing +## an argument that takes a string, pass it with +## something like --args=foo='"bar"'. E.g., +## bash$ fx oldset x64 --args=foo='"bar"' +## More complicated arguments, e.g., lists, require +## their own special syntax. See GN documentation +## for the syntax of each kind of argument. +## --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). +## This option requires an existing build directory. +## --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. +## --ide Pass --ide=VALUE to gn when generating to create project +## files usable with that IDE. Useful values include "vs" +## for Visual Studio or "xcode" for Xcode. +## --release an alias for "--args=is_debug=false" +## +## Deprecated flags: +## +## --zircon-arg ARG Additional arguments to pass to build-zircon.sh. +## Can be given multiple times. +## +## Example: +## +## $ fx oldset x64 kitchensink --product ermine --available topaz/packages/kitchen_sink +## -> architecture: x64 +## build directory: out/kitchensink +## board: topaz/boards/x64.gni +## product: products/ermine.gni +## available: topaz/packages/kitchen_sink (all other packages) + +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? + +function guess_config_location { + local config_type="$1" + local config_name="$2" + local __resultvar="$3" + + # If there is a vendor repository checked out, look there. + local vendor_repo + vendor_repo="$(${FUCHSIA_DIR}/build/gn/find_vendor_repo.py)" || return 1 + readonly vendor_repo + + if [[ -n "${vendor_repo}" ]]; then + guessed_config="${vendor_repo}/${config_type}/${config_name}.gni" + if [[ -a "${FUCHSIA_DIR}/${guessed_config}" ]]; then + eval "${__resultvar}"="${guessed_config}" + return + fi + fi + + # Otherwise look at the top level location + # Check if the configuration is in the top-level location + guessed_config="${config_type}/${config_name}.gni" + if [[ -a "${FUCHSIA_DIR}/${guessed_config}" ]]; then + eval "${__resultvar}"="${guessed_config}" + return + fi + + fx-error "Could not guess a ${config_type} configuration matching \"${config_name}\"" + fx-error "Please specify the full path from the root of the checkout such as" + fx-error "${config_type}/core.gni" + exit 1 +} + + +function main { + fx-standard-switches "$@" + set -- "${FX_ARGV[@]}" + + if [[ $# -lt 1 ]]; then + fx-command-help + return 1 + fi + + local arch= + case $1 in + x64 | x86 | x64-64) + arch=x64 + ;; + arm64 | aarch64) + arch=arm64 + ;; + *) + # TODO(alainv): Add support for extracting arch from board configs. + fx-error Unknown target \"$1\" + fx-command-help + return 1 + ;; + esac + shift + + cd "${FUCHSIA_DIR}" + + local gn_cmd='gen' + local -a gn_switches=(--check) + local gn_args="target_cpu=\"${arch}\"" + local gn_after_args="" + local boards=() + local products=() + local available=() + local preinstall=() + local monolith=() + local zircon_args=(-v -g -t "$arch") + local build_dir= + local variant= + local use_goma + local goma_dir + local ensure_goma=1 + local ccache + while [[ $# -ne 0 ]]; do + case "$1" in + --board) + if [[ $# -lt 2 ]]; then + fx-command-help + return 1 + fi + boards+=("$2") + shift + ;; + --product) + if [[ $# -lt 2 ]]; then + fx-command-help + return 1 + fi + products+=("$2") + shift + ;; + --available) + if [[ $# -lt 2 ]]; then + fx-command-help + return 1 + fi + IFS=, available+=("$2") + shift + ;; + --preinstall) + if [[ $# -lt 2 ]]; then + fx-command-help + return 1 + fi + IFS=, preinstall+=("$2") + shift + ;; + --monolith) + if [[ $# -lt 2 ]]; then + fx-command-help + return 1 + fi + IFS=, monolith+=("$2") + shift + ;; + --zircon-arg) + fx-warn "--zircon-arg is deprecated, common use case is no longer required" + if [[ $# -lt 2 ]]; then + fx-command-help + return 1 + fi + zircon_args+=("$2") + shift + ;; + --netboot) + gn_after_args+=" enable_netboot=true" + ;; + --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 + fx-error "GOMA directory does not exist: "${goma_dir}"" + return 1 + fi + shift + ;; + --release) + gn_args+=" is_debug=false" + ;; + --variant) + if [[ $# -lt 2 ]]; then + fx-command-help + return 1 + fi + variant+="\"$2\"," + shift + ;; + --fuzz-with) + if [[ $# -lt 2 ]]; then + fx-command-help + return 1 + fi + variant+="{variant=\"$2-fuzzer\" target_type=[\"fuzzed_executable\"]}," + shift + ;; + --args) + if [[ $# -lt 2 ]]; then + fx-command-help + return 1 + fi + gn_args+=" $2" + shift + ;; + --help-args) + gn_cmd=args + if [[ $# -ge 2 ]] && [[ "$2" != '--*' ]]; then + gn_switches+=("--list=$2") + shift + else + gn_switches+=(--list) + fi + ;; + --ccache) + ccache=1 + ;; + --no-ccache) + ccache=0 + ;; + --ide) + if [[ $# -lt 2 ]]; then + fx-command-help + return 1 + fi + gn_switches+=("--ide=$2") + shift + ;; + --*) + fx-command-help + return 1 + ;; + *) + # A non-option argument is the build_dir, but there can be only one. + if [[ -n "$build_dir" ]]; then + fx-command-help + return 1 + fi + build_dir="$1" + ;; + esac + shift + done + + if [[ -z "${products}" ]]; then + # This is the default logic GN would use, but if a user specified --netboot + # we would short-circuit the logic, so repeat it here. + local vendor_repo + vendor_repo="$(${FUCHSIA_DIR}/build/gn/find_vendor_repo.py)" || return 1 + readonly vendor_repo + if [[ -n "${vendor_repo}" ]]; then + products+="${vendor_repo}/products/default.gni" + else + products+="products/core.gni" + fi + fi + + if [[ -z "${boards}" ]]; then + boards="boards/$arch.gni" + fi + + # Remove any trailing slash from build directory name. + build_dir="${build_dir%/}" + + local config_build_dir + case "$build_dir" in + '') + # Default is "//out/$target_cpu". Store it as relative. + config_build_dir="out/${arch}" + build_dir="${FUCHSIA_DIR}/${config_build_dir}" + ;; + //*|out/*) + # GN-style "source-relative" path or relative out/something. + config_build_dir="${build_dir#//}" + build_dir="${FUCHSIA_DIR}/${config_build_dir}" + ;; + *) + # Absolute or relative path. Canonicalize it to source-relative. + local abs_build_dir + abs_build_dir="$(cd "${build_dir%/*}" >/dev/null 2>&1; pwd)/${build_dir##*/}" || { + fx-error "Missing parent directories for ${build_dir}" + return 1 + } + if [[ "$abs_build_dir" == "${FUCHSIA_DIR}"/out/* ]]; then + config_build_dir="${abs_build_dir#${FUCHSIA_DIR}/}" + else + fx-warn "${abs_build_dir} is not a subdirectory of ${FUCHSIA_DIR}/out" + config_build_dir="$abs_build_dir" + fi + ;; + esac + + # 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 + + if [[ -z "${boards}" ]]; then + guess_config_within_layer "boards" "${arch}" boards + fi + + for board in ${boards[@]}; do + if [[ ! -f "${FUCHSIA_DIR}/${board}" ]]; then + local guessed_board="" + guess_config_location "boards" "${board}" guessed_board + board="${guessed_board}" + fi + gn_args+=" import(\"//${board}\")" + done + + # Add goma or ccache settings as appropriate. + if [[ "${use_goma}" -eq 1 ]]; then + gn_args+=" use_goma=true goma_dir=\"${goma_dir}\"" + zircon_args+=(use_goma=true "goma_dir=\"${goma_dir}\"") + elif [[ "${ccache}" -eq 1 ]]; then + gn_args+=" use_ccache=true" + fi + + for product in ${products[@]}; do + if [[ ! -a "${FUCHSIA_DIR}/${product}" ]]; then + local guessed_product="" + guess_config_location "products" "${product}" guessed_product + product="${guessed_product}" + fi + gn_args+=" import(\"//${product}\")" + done + + gn_args+=" if (!defined(available)) { available = [] }" + gn_args+=" available+=[" + for package in ${available[@]}; do + gn_args+="\"${package}\"," + done + gn_args+="]" + + gn_args+=" if (!defined(preinstall)) { preinstall = [] }" + gn_args+=" preinstall+=[" + for package in ${preinstall[@]}; do + gn_args+="\"${package}\"," + done + gn_args+="]" + gn_args+=" if (!defined(monolith)) { monolith = [] }" + gn_args+=" monolith+=[" + for package in ${monolith[@]}; do + gn_args+="\"${package}\"," + done + gn_args+="]" + + if [[ -n "${variant}" ]]; then + gn_args+=" select_variant=[${variant}]" + fi + + gn_args+="${gn_after_args}" + + # Using a subshell with -x prints out the gn command precisely with shell + # quoting so a cut&paste to the command line works. Always show the real + # meaning of what this script does so everyone learns how GN works. + ( + set -x -e + # Zircon's `gn gen` phase has to be done before Fuchsia's `gn gen`. + # The former produces the legacy-$cpu.json file consumed by the latter. + "${FUCHSIA_DIR}/scripts/build-zircon.sh" "${zircon_args[@]}" + "${FUCHSIA_DIR}/buildtools/gn" ${gn_cmd} "${build_dir}" \ + "${gn_switches[@]}" --args="${gn_args}" "$@" + # If GN failed, don't update .config. + ) || return + + fx-config-write "${config_build_dir}" + + 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 "$@" diff --git a/scripts/devshell/set b/scripts/devshell/set index ce4d4ff5b442a32cac5a2d39faa4644bc078de82..d936a7c9716d53681db0686082d72e41f3bb18e2 100755 --- a/scripts/devshell/set +++ b/scripts/devshell/set @@ -1,79 +1,53 @@ #!/bin/bash -# Copyright 2017 The Fuchsia Authors. All rights reserved. +# Copyright 2019 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 up a build directory +### set up a build directory (EXPERIMENTAL) -## usage: fx set TARGET [OUTDIR] -## [--board NAME|PATH] -## [--product NAME|PATH] -## [--monolith PATH] -## [--preinstall PATH] -## [--available PATH] -## [--netboot] +## usage: fx set PRODUCT.BOARD [--with GNLABEL1,GNLABEL2,...] +## [--release] [--build-dir BUILDDIR] ## [--args ARG] [--help-args [ARG]] [--variant VARIANT] -## [--goma|--no-goma] [--no-ensure-goma] -## [--goma-dir DIR] -## [--ccache|--no-ccache] -## [--release] -## [--zircon-arg ARG] +## [--with-base GNLABEL1,GNLABEL2,...] ## -## where TARGET is x64 or arm64 +## where PRODUCT is an entry from `//products` or `//vendor/*/products` and +## BOARD is an entry from `//boards` or `//vendor/*/boards`. Use the +## `fx list-products` and `fx list-boards` commands to see a list of +## possible products and boards (respectively). See the README.md in those +## directories for a description of the various options. ## -## OUTDIR is the directory where the build output goes. +## BUILDDIR is the directory where the build output goes. ## If it begins with `//` or `out/` then it's taken as relative to FUCHSIA_DIR. ## Otherwise it should be an absolute path or a path relative to the current ## working directory that winds up in `FUCHSIA_DIR/out`. -## It defaults to `out/TARGET`. +## It defaults to `out/default`. ## -## This is a wrapper around running `gn gen --check OUTDIR --args ...`. -## If GN fails with an error, `fx set` does not change anything. -## If GN succeeds, this also points subsequent `fx` commands at OUTDIR, -## just as `fx use` does and ensures Goma is ready (if enabled). +## This command store the location of the build directory in the //.config file, +## which causes subsequent `fx` commands to use that build directory. Use +## `fx use` to switch build directories. +## +## Ensures Goma is ready (if Goma is enabled). ## -## NAME|PATH can be provided as arguments to --board and --product. In the -## case of NAME the name is searched for in //layer/board/NAME.gni, otherwise it -## is treated as a PATH. +## This is a wrapper around running `gn gen --check BUILDDIR --args ...`. +## If GN fails with an error, `fx set` does not change anything. ## ## optional arguments: -## --board Use the given board target definition. Board -## configurations are used to modulate hardware specific -## behavior, such as configuring the set of drivers -## included, or adding peripheral specific configurations. -## If no board is given, a default board for the architecture -## is selected from the current layer, e.g. -## garnet/boards/x64.gni. -## --product Include the given product in the build. Defaults to -## the default product for the current layer (e.g., -## "garnet/products/default.gni" for the Garnet layer). -## Product configurations define a set of packages to be -## included in the monolith, preinstall and available -## package sets, as well as product oriented configurations. -## --monolith Additional packages to be built and included in the -## monolithic system image. Monolith is the set of packages -## that make up an OTA image. -## If the --monolith argument is given multiple times, -## all the specified packages are included in this set. -## These packages are added to the available set defined -## by the board and product specifications. -## --preinstall Additional packages to be built and included in the -## system image alongside the monolithic system image. -## Packages in preinstall are not part of OTA updates, -## instead they are updated dynamically. -## If the --preinstall argument is given multiple times, -## all the specified packages are included in this set. -## These packages are added to the available set defined -## by the board and product specifications. -## --available Additional packages to be built and included in the -## set of packages available for pushing dynamically. -## If the --available argument is given multiple times, -## all the specified available are included in this set. -## These packages are added to the available set defined -## by the board and product specifications. -## --netboot Ensure that a network ramboot image is always built. -## --variant Pass a `select_variant=[VARIANT*,...]` GN build argument -## collecting all the --variant arguments in order. +## --with GNLABEL Labels of additional packages to include in the +## universe of available packages. These packages can +## be run ephemerally. Multiple labels can be provided +## delimited by commas or the --with argument can be +## provided multiple times. +## --variant Selects which runtime variant to use (e.g., asan) by +## passing a `select_variant=[VARIANT*,...]` argument +## to gn that collects all the --variant arguments in +## order. Variants are normal builds in most respects, +## but allow users to test different runtime settings +## for either the whole build or for a specific target. +## This can be specified by passing the variant name +## to this argument (e.g. `--variant asan`) for the +## former, or the variant name and the target name +## separated by a slash (e.g. `--variant asan/my_test`) +## for the latter. ## --fuzz-with Pass a sanitizer name, e.g. "--fuzz-with asan" to ## enable ALL supporting fuzzers. Use --variant for ## individual fuzzers, e.g. "--variant asan-fuzzer/foo". @@ -86,10 +60,11 @@ ## survive, for example, the shell. Thus when passing ## an argument that takes a string, pass it with ## something like --args=foo='"bar"'. E.g., -## bash$ fx set x64 --args=foo='"bar"' +## bash$ fx set core.x64 --args=foo='"bar"' ## More complicated arguments, e.g., lists, require ## their own special syntax. See GN documentation ## for the syntax of each kind of argument. +## --netboot Ensure that a network ramboot image is always built. ## --help-args Display GN arguments documentation. If --help-args ## is followed by a GN build argument identifier, just ## that argument's documentation is displayed. @@ -111,94 +86,94 @@ ## files usable with that IDE. Useful values include "vs" ## for Visual Studio or "xcode" for Xcode. ## --release an alias for "--args=is_debug=false" -## -## Deprecated flags: -## -## --zircon-arg ARG Additional arguments to pass to build-zircon.sh. -## Can be given multiple times. +## --with-base GNLABEL Labels of additional packages to include in the +## base set of packages. These packages are included in +## the system image and can be updated only with an OTA. +## Multiple labels can be provided delimited by commas +## or the --with-base argument can be provided multiple +## times. ## ## Example: ## -## $ fx set x64 kitchensink --product ermine --available topaz/packages/kitchen_sink -## -> architecture: x64 -## build directory: out/kitchensink -## board: topaz/boards/x64.gni -## product: products/ermine.gni -## available: topaz/packages/kitchen_sink (all other packages) +## $ fx set core.x64 --with //bundles:tests +## -> build directory: out/default +## board: //boards/x64.gni +## product: //products/core.gni +## universe: //bundles:tests (all test packages) source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? -function guess_config_location { +set -e + +function find_config { local config_type="$1" local config_name="$2" - local __resultvar="$3" - # If there is a vendor repository checked out, look there. - local vendor_repo - vendor_repo="$(${FUCHSIA_DIR}/build/gn/find_vendor_repo.py)" || return 1 - readonly vendor_repo - - if [[ -n "${vendor_repo}" ]]; then - guessed_config="${vendor_repo}/${config_type}/${config_name}.gni" - if [[ -a "${FUCHSIA_DIR}/${guessed_config}" ]]; then - eval "${__resultvar}"="${guessed_config}" + for directory in vendor/*/"${config_type}" "${config_type}"; do + local guessed_config="${directory}/${config_name}.gni" + if [[ -a "${guessed_config}" ]]; then + echo "${guessed_config}" return fi - fi - - # Otherwise look at the top level location - # Check if the configuration is in the top-level location - guessed_config="${config_type}/${config_name}.gni" - if [[ -a "${FUCHSIA_DIR}/${guessed_config}" ]]; then - eval "${__resultvar}"="${guessed_config}" - return - fi + done - fx-error "Could not guess a ${config_type} configuration matching \"${config_name}\"" - fx-error "Please specify the full path from the root of the checkout such as" - fx-error "${config_type}/core.gni" + fx-error "Could not find a ${config_type} configuration matching \"${config_name}\"" + fx-error "Checked:" + for directory in vendor/*/"${config_type}" "${config_type}"; do + local guessed_config="${directory}/${config_name}.gni" + fx-error " ${guessed_config}" + done exit 1 } +function explain-goal-argument { + fx-error You must specify which product and which board you wish to build. + fx-error Example: + fx-error " fx set core.x64" + fx-error + fx-error Run \"fx list-products\" to see the available products. + fx-error Run \"fx list-boards\" to see the available boards. + fx-error Run \"fx set --help\" to see full usage. + return 0 +} function main { fx-standard-switches "$@" set -- "${FX_ARGV[@]}" if [[ $# -lt 1 ]]; then - fx-command-help - return 1 + fx-error Missing an explicit PRODUCT.BOARD goal. + explain-goal-argument + return 1 fi - local arch= - case $1 in - x64 | x86 | x64-64) - arch=x64 - ;; - arm64 | aarch64) - arch=arm64 + cd "${FUCHSIA_DIR}" + + local gn_args="" + case "$1" in + *.*) + local product_name="${1%.*}" + local board_name="${1##*.}" + local product="$(find_config "products" "${product_name}")" + local board="$(find_config "boards" "${board_name}")" + gn_args+=" import(\"//${board}\") import(\"//${product}\")" ;; *) - # TODO(alainv): Add support for extracting arch from board configs. - fx-error Unknown target \"$1\" - fx-command-help + fx-error Unable to parse PRODUCT.BOARD goal \"$1\" + explain-goal-argument return 1 ;; esac shift - cd "${FUCHSIA_DIR}" + local gn_args+=" allow_layer_guesswork=false" local gn_cmd='gen' local -a gn_switches=(--check) - local gn_args="target_cpu=\"${arch}\"" local gn_after_args="" - local boards=() - local products=() - local available=() - local preinstall=() - local monolith=() - local zircon_args=(-v -g -t "$arch") + local base=() + local universe=() + local zircon_args=(-v -g) local build_dir= local variant= local use_goma @@ -207,53 +182,20 @@ function main { local ccache while [[ $# -ne 0 ]]; do case "$1" in - --board) - if [[ $# -lt 2 ]]; then - fx-command-help - return 1 - fi - boards+=("$2") - shift - ;; - --product) - if [[ $# -lt 2 ]]; then - fx-command-help - return 1 - fi - products+=("$2") - shift - ;; - --available) - if [[ $# -lt 2 ]]; then - fx-command-help - return 1 - fi - IFS=, available+=("$2") - shift - ;; - --preinstall) + --with-base) if [[ $# -lt 2 ]]; then fx-command-help return 1 fi - IFS=, preinstall+=("$2") + IFS=, base+=("$2") shift ;; - --monolith) + --with) if [[ $# -lt 2 ]]; then fx-command-help return 1 fi - IFS=, monolith+=("$2") - shift - ;; - --zircon-arg) - fx-warn "--zircon-arg is deprecated, common use case is no longer required" - if [[ $# -lt 2 ]]; then - fx-command-help - return 1 - fi - zircon_args+=("$2") + IFS=, universe+=("$2") shift ;; --netboot) @@ -275,11 +217,19 @@ function main { fi goma_dir=$2 if [[ ! -d "${goma_dir}" ]]; then - fx-error "GOMA directory does not exist: "${goma_dir}"" + fx-error "GOMA directory does not exist: ${goma_dir}" return 1 fi shift ;; + --build-dir) + if [[ $# -lt 2 ]]; then + fx-command-help + return 1 + fi + build_dir="$2" + shift + ;; --release) gn_args+=" is_debug=false" ;; @@ -330,47 +280,23 @@ function main { gn_switches+=("--ide=$2") shift ;; - --*) + *) + fx-error "Unknown argument \"$1\"" fx-command-help return 1 ;; - *) - # A non-option argument is the build_dir, but there can be only one. - if [[ -n "$build_dir" ]]; then - fx-command-help - return 1 - fi - build_dir="$1" - ;; esac shift done - if [[ -z "${products}" ]]; then - # This is the default logic GN would use, but if a user specified --netboot - # we would short-circuit the logic, so repeat it here. - local vendor_repo - vendor_repo="$(${FUCHSIA_DIR}/build/gn/find_vendor_repo.py)" || return 1 - readonly vendor_repo - if [[ -n "${vendor_repo}" ]]; then - products+="${vendor_repo}/products/default.gni" - else - products+="products/core.gni" - fi - fi - - if [[ -z "${boards}" ]]; then - boards="boards/$arch.gni" - fi - # Remove any trailing slash from build directory name. build_dir="${build_dir%/}" local config_build_dir case "$build_dir" in '') - # Default is "//out/$target_cpu". Store it as relative. - config_build_dir="out/${arch}" + # Default is "//out/default". Store it as relative. + config_build_dir="out/default" build_dir="${FUCHSIA_DIR}/${config_build_dir}" ;; //*|out/*) @@ -379,18 +305,9 @@ function main { build_dir="${FUCHSIA_DIR}/${config_build_dir}" ;; *) - # Absolute or relative path. Canonicalize it to source-relative. - local abs_build_dir - abs_build_dir="$(cd "${build_dir%/*}" >/dev/null 2>&1; pwd)/${build_dir##*/}" || { - fx-error "Missing parent directories for ${build_dir}" - return 1 - } - if [[ "$abs_build_dir" == "${FUCHSIA_DIR}"/out/* ]]; then - config_build_dir="${abs_build_dir#${FUCHSIA_DIR}/}" - else - fx-warn "${abs_build_dir} is not a subdirectory of ${FUCHSIA_DIR}/out" - config_build_dir="$abs_build_dir" - fi + fx-error "Invalid build directory: ${build_dir}" + fx-error "Please specify a build directory as \"out/something\"." + exit 1 ;; esac @@ -408,19 +325,6 @@ function main { fi fi - if [[ -z "${boards}" ]]; then - guess_config_within_layer "boards" "${arch}" boards - fi - - for board in ${boards[@]}; do - if [[ ! -f "${FUCHSIA_DIR}/${board}" ]]; then - local guessed_board="" - guess_config_location "boards" "${board}" guessed_board - board="${guessed_board}" - fi - gn_args+=" import(\"//${board}\")" - done - # Add goma or ccache settings as appropriate. if [[ "${use_goma}" -eq 1 ]]; then gn_args+=" use_goma=true goma_dir=\"${goma_dir}\"" @@ -429,31 +333,22 @@ function main { gn_args+=" use_ccache=true" fi - for product in ${products[@]}; do - if [[ ! -a "${FUCHSIA_DIR}/${product}" ]]; then - local guessed_product="" - guess_config_location "products" "${product}" guessed_product - product="${guessed_product}" - fi - gn_args+=" import(\"//${product}\")" - done + gn_args+=" +# See: fx args --list=base_package_labels +base_package_labels+=[" - gn_args+=" if (!defined(available)) { available = [] }" - gn_args+=" available+=[" - for package in ${available[@]}; do + for package in ${base[@]}; do gn_args+="\"${package}\"," done - gn_args+="]" + gn_args+="] - gn_args+=" if (!defined(preinstall)) { preinstall = [] }" - gn_args+=" preinstall+=[" - for package in ${preinstall[@]}; do - gn_args+="\"${package}\"," - done - gn_args+="]" - gn_args+=" if (!defined(monolith)) { monolith = [] }" - gn_args+=" monolith+=[" - for package in ${monolith[@]}; do +# See: fx args --list=cache_package_labels +cache_package_labels+=[] + +# See: fx args --list=universe_package_labels +universe_package_labels+=[" + + for package in ${universe[@]}; do gn_args+="\"${package}\"," done gn_args+="]" @@ -464,18 +359,11 @@ function main { gn_args+="${gn_after_args}" - # Using a subshell with -x prints out the gn command precisely with shell - # quoting so a cut&paste to the command line works. Always show the real - # meaning of what this script does so everyone learns how GN works. - ( - set -x -e - # Zircon's `gn gen` phase has to be done before Fuchsia's `gn gen`. - # The former produces the legacy-$cpu.json file consumed by the latter. - "${FUCHSIA_DIR}/scripts/build-zircon.sh" "${zircon_args[@]}" - "${FUCHSIA_DIR}/buildtools/gn" ${gn_cmd} "${build_dir}" \ - "${gn_switches[@]}" --args="${gn_args}" "$@" - # If GN failed, don't update .config. - ) || return + # Zircon's `gn gen` phase has to be done before Fuchsia's `gn gen`. + # The former produces the legacy-$cpu.json file consumed by the latter. + "${FUCHSIA_DIR}/scripts/build-zircon.sh" "${zircon_args[@]}" + "${FUCHSIA_DIR}/buildtools/gn" ${gn_cmd} "${build_dir}" \ + "${gn_switches[@]}" --args="${gn_args}" "$@" fx-config-write "${config_build_dir}" diff --git a/scripts/devshell/set-petal b/scripts/devshell/set-petal index f2dc9880c4c6a35945720239cf2846d6b5cb8715..0694254ed35af10416bfdc274ff8883b5bf9f186 100755 --- a/scripts/devshell/set-petal +++ b/scripts/devshell/set-petal @@ -42,11 +42,9 @@ rm -f -- "${FUCHSIA_DIR}/.jiri_manifest" "${jiri}" import -name=integration flower https://fuchsia.googlesource.com/integration "${jiri}" override "${petal}" "https://fuchsia.googlesource.com/${petal}" -echo "Configured jiri for ${petal}. Run these commands to update your build:" +echo "Configured jiri for ${petal}. Run these commands to update your tree:" cat <<END * jiri update -gc # Updates your source tree to contain ${petal} and # removes unneeded repositories. - * fx set x64 # Updates your build directory to build ${petal}. - * fx full-build # Actually builds ${petal} END diff --git a/scripts/devshell/set2 b/scripts/devshell/set2 deleted file mode 100755 index c7ef16fd647cab8940308e3ea31eea6ce4250a10..0000000000000000000000000000000000000000 --- a/scripts/devshell/set2 +++ /dev/null @@ -1,377 +0,0 @@ -#!/bin/bash -# Copyright 2019 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 up a build directory (EXPERIMENTAL) - -## usage: fx set2 PRODUCT.BOARD [--with GNLABEL1,GNLABEL2,...] -## [--release] [--build-dir BUILDDIR] -## [--args ARG] [--help-args [ARG]] [--variant VARIANT] -## [--with-base GNLABEL1,GNLABEL2,...] -## -## where PRODUCT is an entry from `//products` or `//vendor/*/products` and -## BOARD is an entry from `//boards` or `//vendor/*/boards`. Use the -## `fx list-products` and `fx list-boards` commands to see a list of -## possible products and boards (respectively). See the README.md in those -## directories for a description of the various options. -## -## BUILDDIR is the directory where the build output goes. -## If it begins with `//` or `out/` then it's taken as relative to FUCHSIA_DIR. -## Otherwise it should be an absolute path or a path relative to the current -## working directory that winds up in `FUCHSIA_DIR/out`. -## It defaults to `out/default`. -## -## This command store the location of the build directory in the //.config file, -## which causes subsequent `fx` commands to use that build directory. Use -## `fx use` to switch build directories. -## -## Ensures Goma is ready (if Goma is enabled). -## -## This is a wrapper around running `gn gen --check BUILDDIR --args ...`. -## If GN fails with an error, `fx set` does not change anything. -## -## optional arguments: -## --with GNLABEL Labels of additional packages to include in the -## universe of available packages. These packages can -## be run ephemerally. Multiple labels can be provided -## delimited by commas or the --with argument can be -## provided multiple times. -## --variant Selects which runtime variant to use (e.g., asan) by -## passing a `select_variant=[VARIANT*,...]` argument -## to gn that collects all the --variant arguments in -## order. Variants are normal builds in most respects, -## but allow users to test different runtime settings -## for either the whole build or for a specific target. -## This can be specified by passing the variant name -## to this argument (e.g. `--variant asan`) for the -## former, or the variant name and the target name -## separated by a slash (e.g. `--variant asan/my_test`) -## for the latter. -## --fuzz-with Pass a sanitizer name, e.g. "--fuzz-with asan" to -## enable ALL supporting fuzzers. Use --variant for -## individual fuzzers, e.g. "--variant asan-fuzzer/foo". -## --args Additional argument to pass to gn. If the --args -## argument is given multiple times, all the specified -## arguments are passed to gn. -## N.B. Arguments must be expressed using GN's syntax. -## In particular this means that for strings they must -## be quoted with double-quotes, and the quoting must -## survive, for example, the shell. Thus when passing -## an argument that takes a string, pass it with -## something like --args=foo='"bar"'. E.g., -## bash$ fx set x64 --args=foo='"bar"' -## More complicated arguments, e.g., lists, require -## their own special syntax. See GN documentation -## for the syntax of each kind of argument. -## --netboot Ensure that a network ramboot image is always built. -## --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). -## This option requires an existing build directory. -## --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. -## --ide Pass --ide=VALUE to gn when generating to create project -## files usable with that IDE. Useful values include "vs" -## for Visual Studio or "xcode" for Xcode. -## --release an alias for "--args=is_debug=false" -## --with-base GNLABEL Labels of additional packages to include in the -## base set of packages. These packages are included in -## the system image and can be updated only with an OTA. -## Multiple labels can be provided delimited by commas -## or the --with-base argument can be provided multiple -## times. -## -## Example: -## -## $ fx set2 core.x64 --with //bundles:tests -## -> build directory: out/default -## board: //boards/x64.gni -## product: //products/core.gni -## universe: //bundles:tests (all test packages) - -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? - -set -e - -function find_config { - local config_type="$1" - local config_name="$2" - - for directory in vendor/*/"${config_type}" "${config_type}"; do - local guessed_config="${directory}/${config_name}.gni" - if [[ -a "${guessed_config}" ]]; then - echo "${guessed_config}" - return - fi - done - - fx-error "Could not find a ${config_type} configuration matching \"${config_name}\"" - fx-error "Checked:" - for directory in vendor/*/"${config_type}" "${config_type}"; do - local guessed_config="${directory}/${config_name}.gni" - fx-error " ${guessed_config}" - done - exit 1 -} - -function explain-goal-argument { - fx-error You must specify which product and which board you wish to build. - fx-error Example: - fx-error " fx set2 core.x64" - fx-error - fx-error Run \"fx list-products\" to see the available products. - fx-error Run \"fx list-boards\" to see the available boards. - fx-error Run \"fx set2 --help\" to see full usage. - return 0 -} - -function main { - fx-standard-switches "$@" - set -- "${FX_ARGV[@]}" - - if [[ $# -lt 1 ]]; then - fx-error Missing an explicit PRODUCT.BOARD goal. - explain-goal-argument - return 1 - fi - - cd "${FUCHSIA_DIR}" - - local gn_args="" - case "$1" in - *.*) - local product_name="${1%.*}" - local board_name="${1##*.}" - local product="$(find_config "products" "${product_name}")" - local board="$(find_config "boards" "${board_name}")" - gn_args+=" import(\"//${board}\") import(\"//${product}\")" - ;; - *) - fx-error Unable to parse PRODUCT.BOARD goal \"$1\" - explain-goal-argument - return 1 - ;; - esac - shift - - local gn_args+=" allow_layer_guesswork=false" - - local gn_cmd='gen' - local -a gn_switches=(--check) - local gn_after_args="" - local base=() - local universe=() - local zircon_args=(-v -g) - local build_dir= - local variant= - local use_goma - local goma_dir - local ensure_goma=1 - local ccache - while [[ $# -ne 0 ]]; do - case "$1" in - --with-base) - if [[ $# -lt 2 ]]; then - fx-command-help - return 1 - fi - IFS=, base+=("$2") - shift - ;; - --with) - if [[ $# -lt 2 ]]; then - fx-command-help - return 1 - fi - IFS=, universe+=("$2") - shift - ;; - --netboot) - gn_after_args+=" enable_netboot=true" - ;; - --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 - fx-error "GOMA directory does not exist: ${goma_dir}" - return 1 - fi - shift - ;; - --build-dir) - if [[ $# -lt 2 ]]; then - fx-command-help - return 1 - fi - build_dir="$2" - shift - ;; - --release) - gn_args+=" is_debug=false" - ;; - --variant) - if [[ $# -lt 2 ]]; then - fx-command-help - return 1 - fi - variant+="\"$2\"," - shift - ;; - --fuzz-with) - if [[ $# -lt 2 ]]; then - fx-command-help - return 1 - fi - variant+="{variant=\"$2-fuzzer\" target_type=[\"fuzzed_executable\"]}," - shift - ;; - --args) - if [[ $# -lt 2 ]]; then - fx-command-help - return 1 - fi - gn_args+=" $2" - shift - ;; - --help-args) - gn_cmd=args - if [[ $# -ge 2 ]] && [[ "$2" != '--*' ]]; then - gn_switches+=("--list=$2") - shift - else - gn_switches+=(--list) - fi - ;; - --ccache) - ccache=1 - ;; - --no-ccache) - ccache=0 - ;; - --ide) - if [[ $# -lt 2 ]]; then - fx-command-help - return 1 - fi - gn_switches+=("--ide=$2") - shift - ;; - *) - fx-error "Unknown argument \"$1\"" - fx-command-help - return 1 - ;; - esac - shift - done - - # Remove any trailing slash from build directory name. - build_dir="${build_dir%/}" - - local config_build_dir - case "$build_dir" in - '') - # Default is "//out/default". Store it as relative. - config_build_dir="out/default" - build_dir="${FUCHSIA_DIR}/${config_build_dir}" - ;; - //*|out/*) - # GN-style "source-relative" path or relative out/something. - config_build_dir="${build_dir#//}" - build_dir="${FUCHSIA_DIR}/${config_build_dir}" - ;; - *) - fx-error "Invalid build directory: ${build_dir}" - fx-error "Please specify a build directory as \"out/something\"." - exit 1 - ;; - esac - - # 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 settings as appropriate. - if [[ "${use_goma}" -eq 1 ]]; then - gn_args+=" use_goma=true goma_dir=\"${goma_dir}\"" - zircon_args+=(use_goma=true "goma_dir=\"${goma_dir}\"") - elif [[ "${ccache}" -eq 1 ]]; then - gn_args+=" use_ccache=true" - fi - - gn_args+=" -# See: fx args --list=base_package_labels -base_package_labels+=[" - - for package in ${base[@]}; do - gn_args+="\"${package}\"," - done - gn_args+="] - -# See: fx args --list=cache_package_labels -cache_package_labels+=[] - -# See: fx args --list=universe_package_labels -universe_package_labels+=[" - - for package in ${universe[@]}; do - gn_args+="\"${package}\"," - done - gn_args+="]" - - if [[ -n "${variant}" ]]; then - gn_args+=" select_variant=[${variant}]" - fi - - gn_args+="${gn_after_args}" - - # Zircon's `gn gen` phase has to be done before Fuchsia's `gn gen`. - # The former produces the legacy-$cpu.json file consumed by the latter. - "${FUCHSIA_DIR}/scripts/build-zircon.sh" "${zircon_args[@]}" - "${FUCHSIA_DIR}/buildtools/gn" ${gn_cmd} "${build_dir}" \ - "${gn_switches[@]}" --args="${gn_args}" "$@" - - fx-config-write "${config_build_dir}" - - 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 "$@" diff --git a/scripts/gce/README.md b/scripts/gce/README.md index 98e19aaf17521240e6064b52c3b2f784113aee27..2f066dfe7f3b633087d0000192283ab596627cc4 100644 --- a/scripts/gce/README.md +++ b/scripts/gce/README.md @@ -25,7 +25,7 @@ Fuchsia instance: ``` cd $FUCHSIA_ROOT -fx set x64 --release +fx set core.x64 --release fx full-build fx gce create-fuchsia-image fx gce create-instance diff --git a/scripts/vim/README.md b/scripts/vim/README.md index 844357f01d9cbd29ed8eb14e01265d5c319f0347..d17f14f7cadb498ec50ca064b3c4e3a037142d2a 100644 --- a/scripts/vim/README.md +++ b/scripts/vim/README.md @@ -16,7 +16,7 @@ ```shell export FUCHSIA_DIR=/path/to/fuchsia-dir - fx set x64 + fx set core.x64 ``` 1. Update your vim startup file