blob: 5fa1d61b9a3819e93063d7c73080bdae2d8575ea [file]
#!/bin/bash
# Copyright 2018 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
#### PREBUILTS=${PREBUILT_BLACK_DIR} ${PREBUILT_BUILDIFIER} ${PREBUILT_CLANG_DIR} ${PREBUILT_DART_DIR} ${PREBUILT_GN} ${PREBUILT_GO_DIR} ${PREBUILT_KEEP_SORTED} ${PREBUILT_PYTHON3} ${PREBUILT_RUST_DIR} ${PREBUILT_SHAC}
### runs source formatters on modified files via SHAC
## Usage: fx format-code [options] [files...] [-- shac_args...]
##
## Runs source formatters registered in SHAC on modified source files
## (or on explicit files if specified).
##
## Options:
## --emit Emit formatted output to stdout instead of modifying files.
## --all Format all tracked files in the repository.
## --only <check> Run only the specified formatter(s) (comma-separated or repeated).
## --skip <check> Skip the specified formatter(s) (comma-separated or repeated).
## --files <files> Comma-separated list of specific files to format.
## -v, --verbose Print verbose command execution output.
## --dry-run Print shac commands without executing.
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
fx-config-read
if [[ -z "${JIRI_PACKAGES_DIR}" ]]; then
if git_common_dir=$(git -C "${FUCHSIA_DIR}" rev-parse --git-common-dir 2>/dev/null) && [[ -d "${git_common_dir}" ]]; then
parent_root=$(cd "${git_common_dir}/.." 2>/dev/null && pwd)
packages_dir="${parent_root}/.jiri_root/packages"
if [[ -d "${packages_dir}" ]]; then
export JIRI_PACKAGES_DIR="${packages_dir}"
fi
fi
fi
export PREBUILT_SHAC
export PYTHONPATH="${FUCHSIA_DIR}/tools/devshell/lib${PYTHONPATH:+:${PYTHONPATH}}"
exec "${PREBUILT_PYTHON3}" "${FUCHSIA_DIR}/tools/devshell/format_code.py" "$@"