| #!/usr/bin/env bash | |
| # Copyright 2024 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 | |
| ### Finds the nearest OWNERS file corresponding to the provided path, or the | |
| ### current working directory. | |
| ## usage: fx list-owners src/devices/pci/drivers/pci/bus.cc | |
| ## fx list-owners src/connectivity | |
| ## fx list-owners (. is implied) | |
| ## | |
| ## This command attempts to list the nearest OWNERS file corresponding to a | |
| ## target file or directory, or current directory if not otherwise specificed. | |
| ## | |
| ## It does not handle files that have file-specific mention in an OWNERS file | |
| ## outside of file's directory. | |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/vars.sh || exit $? | |
| fx-config-read | |
| # Search for the OWNERS current directory, or of the file provided. Use the full | |
| # path to avoid issues with `.` that can crop up when giving relative paths. | |
| dir=$(realpath "${1:-$PWD}") | |
| # IF we were given a file then lets figure out where it is. | |
| if [[ -f "${dir}" ]]; then | |
| dir=$(dirname "${dir}/") | |
| fi | |
| if [[ ! "${dir}" == *"${FUCHSIA_DIR}"* ]]; then | |
| echo "Error: Did not find \$FUCHSIA_DIR (${FUCHSIA_DIR}) in ${dir}" | |
| exit 1 | |
| fi | |
| pushd "${dir}" >/dev/null || exit | |
| until [[ -f OWNERS || $PWD == "${FUCHSIA_DIR}" ]]; do | |
| cd .. | |
| done | |
| if [ -f OWNERS ]; then | |
| echo "/${PWD#"$FUCHSIA_DIR"}/OWNERS:" | |
| cat OWNERS | |
| else | |
| echo "Couldn't find OWNERS file for $dir (This shouldn't happen because FUCHSIA_DIR should have one!)" | |
| fi | |
| popd >/dev/null || exit |