| #!/bin/bash |
| # Copyright 2026 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=Developer Tools |
| ### sets up the jj tool (if installed) for use with Fuchsia. |
| ## Will also set up the watchman config file if watchman is installed and |
| ## a watchman config file does not exist already. |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/vars.sh || exit $? |
| fx-config-read |
| |
| if ! command -v jj &> /dev/null; then |
| fx-error "jj is not installed. Please install it first (e.g., 'cargo install jj-cli')." |
| exit 1 |
| fi |
| |
| if [[ ! -d "$FUCHSIA_DIR/.jj" ]]; then |
| fx-info "Initializing jj in $FUCHSIA_DIR..." |
| if ! jj git init --colocate "$FUCHSIA_DIR"; then |
| fx-error "Failed to initialize jj in $FUCHSIA_DIR" |
| exit 1 |
| fi |
| fi |
| |
| # NOTE: at some point in the future `jj` will be migrating to "Secure Config" |
| # aka "Configuration that is stored outside of the repository structure" |
| # |
| # See: https://docs.jj-vcs.dev/latest/design/secure-config/ for details |
| # |
| # As such, assuming the path to the configuration file is |
| # ${FUCHSIA_DIR}/.jj/repo/config.toml is bound to break at some point. |
| # When the migration happens there may be some intermittent breakage where |
| # users may need to re-run this script. |
| JJ_CONFIG_FILE=$(jj config path --repo) |
| JJ_CONFIG_DIR=$(dirname JJ_CONFIG_FILE) |
| mkdir -p "$JJ_CONFIG_DIR" |
| |
| fx-info "Linking tools/jj/config.toml to $JJ_CONFIG_FILE..." |
| # Use a relative (-r) symbolic (-s) link so that if FUCHSIA_DIR ever gets |
| # moved the link doesnt break. Use -f to force creation. |
| if ! (ln -sfr $FUCHSIA_DIR/tools/jj/config.toml $JJ_CONFIG_FILE); then |
| fx-error "Failed to create jj config symlink." |
| exit 1 |
| fi |
| |
| if ! command -v watchman &> /dev/null; then |
| fx-warn "Watchman is not installed. It is recommended for better performance with jj." |
| fx-warn "See https://facebook.github.io/watchman/docs/install.html for installation instructions." |
| else |
| if [[ ! -f "$FUCHSIA_DIR/.watchmanconfig" ]]; then |
| fx-info ".watchmanconfig not found. Running gen-watchman-config..." |
| fx-command-run gen-watchman-config || fx-warn "gen-watchman-config failed. jj may be slower as a result." |
| fi |
| fi |