| #!/bin/bash |
| # Copyright 2021 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. |
| |
| #### CATEGORY=Source tree |
| ### updates OWNERS files for third_party dependencies |
| |
| ## usage: fx update-3p-owners [--num-threads N] |
| ## [--rust-only | --integration-only] |
| ## [--skip-rustc-3p-update] |
| ## [--skip-existing] |
| ## |
| ## Updates OWNERS files for projects, based on gn target references. For any |
| ## given project, the tool adds as owners the owners of the projects that depend |
| ## on that project. |
| ## |
| ## By default, the tool updates OWNERS for: |
| ## - third_party/rust_crates/vendor/*, for Rust crates specified in |
| ## third_party/rust_crates/Cargo.toml |
| ## - integration third party projects specified in |
| ## integration/third_party/flower. |
| ## |
| ## Arguments: |
| ## --num-threads N: run on N threads. |
| ## |
| ## --rust-only: update OWNERS files only for Rust crates, |
| ## specified in third_party/rust_crates/Cargo.toml. |
| ## |
| ## --integration-only: update OWNERS files only for projects specified |
| ## in integration/third_party/flower. |
| ## |
| ## --skip-existing: only generate OWNERS files for projects missing |
| ## owners; does not update exiting OWNERS files. |
| ## |
| ## --skip-rustc-3p-update: skip updating rustc_library and rustc_binary |
| ## third_party dependencies. |
| ## |
| ## See https://fuchsia.dev/fuchsia-src/development/languages/rust/third_party.md |
| ## for more details. |
| |
| set -e |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/vars.sh || exit $? |
| fx-config-read |
| |
| OWNERS_TOOL_TARGET="host-tools/auto_owners" |
| OWNERS_TOOL_BIN="${FUCHSIA_BUILD_DIR}/${OWNERS_TOOL_TARGET}" |
| RUST_METADATA="--rust-metadata $FUCHSIA_BUILD_DIR/rustlang/3p-crates-metadata.json" |
| JIRI_MANIFEST="--jiri-manifest $FUCHSIA_DIR/integration/third_party/flower" |
| |
| # Parse arguments |
| while [[ $# -ge 1 ]]; do |
| case "$1" in |
| -h|--help) |
| fx-command-help |
| exit 0 |
| ;; |
| --num-threads) |
| shift |
| [[ ! $1 ]] && die "--num-threads requires an argument after it" |
| NUM_THREADS="--num-threads $1" |
| ;; |
| --rust-only) |
| RUST_ONLY="--rust-only" |
| JIRI_MANIFEST="" |
| ;; |
| --integration-only) |
| INTEGRATION_ONLY="--integration-only" |
| RUST_METADATA="" |
| # skip rustc update if not updating rust owners. |
| SKIP_RUSTC_3P_UPDATE="true" |
| ;; |
| --skip-rustc-3p-update) |
| SKIP_RUSTC_3P_UPDATE="true" |
| ;; |
| --skip-existing) |
| SKIP_EXISTING="--skip-existing" |
| ;; |
| -*) |
| echo "Cannot understand option $1" |
| exit 1 |
| ;; |
| esac |
| shift |
| done |
| |
| if [[ ! -n "$NUM_THREADS" ]]; then |
| fx-error "Must specify --num-threads. Recommended value is NCPUS / 2 or less." |
| fx-error "NOTE: using all cores can deadlock your kernel. See https://fxbug.dev/75382." |
| exit 1 |
| fi |
| |
| if [[ -n "$RUST_ONLY" && -n "$INTEGRATION_ONLY" ]]; then |
| fx-error "Argument --rust-only not allowed with --integration-only." |
| exit 1 |
| fi |
| |
| fx-command-run build ${OWNERS_TOOL_TARGET} || ( \ |
| fx-error "Failed to build owners tool."; \ |
| exit 1 |
| ) |
| |
| if [[ ! -n "$SKIP_RUSTC_3P_UPDATE" ]]; then |
| fx-command-run update-rustc-third-party || ( \ |
| fx-error "Failed to run rustc 3p update script."; \ |
| exit 1 |
| ) |
| fi |
| |
| (cd $FUCHSIA_DIR; $OWNERS_TOOL_BIN \ |
| $NUM_THREADS \ |
| $RUST_METADATA \ |
| $JIRI_MANIFEST \ |
| --overrides $FUCHSIA_DIR/third_party/rust_crates/owners.toml \ |
| --out-dir $FUCHSIA_BUILD_DIR \ |
| --gn-bin $PREBUILT_GN \ |
| $SKIP_EXISTING) |