| #!/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 | |
| #### DEPRECATED | |
| ### run various checks to determine the health of a Fuchsia checkout | |
| ## usage: fx doctor | |
| # The goal of this script is to detect common issues with a Fuchsia | |
| # checkout and potential conflicts in the user's shell environment. | |
| # | |
| # For example, on OS X the xcode command line tool | |
| # installation often lapses. Ensuring that `xcode select --install` is | |
| # run as part of a checkout or build is problematic: the step involves | |
| # manual input. Detecting that it needs to be run, however, is | |
| # perfectly mechanizable. | |
| # | |
| # For potential issues in the user's shell initialization script | |
| # (such as ~/.bashrc), this script will also run a shell checkup | |
| # script (for example, devshell/lib/bashrc_checkup.sh) | |
| # under the user's bash "${SHELL}" (if different from /bin/bash), | |
| # load the user's shell settings, and check for any known issues. | |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? | |
| source "${FUCHSIA_DIR}/tools/devshell/lib/style.sh" || exit $? | |
| source "${FUCHSIA_DIR}/tools/devshell/lib/common_term_styles.sh" || exit $? | |
| fx-config-read || exit $? | |
| dr_mac() { | |
| local status=0 | |
| local xcode_path=$(xcode-select --print-path) | |
| local expected_path='/Library/Developer/CommandLineTools' | |
| local required_subpath='usr/include/c++' | |
| if [[ ! -d "${xcode_path}/${required_subpath}" ]]; then | |
| if [[ "${xcode_path}" != "${expected_path}" ]] && \ | |
| [[ -d "${expected_path}/${required_subpath}" ]]; then | |
| warn "You may need to run \`sudo xcode-select --switch \"${expected_path}\"\`" | |
| else | |
| warn "Make sure you've run \`sudo xcode-select --install\`" | |
| fi | |
| details << EOF | |
| A common issue with Fuchsia development on macOS is needing to | |
| re-run the \`xcode-select\` command. The typical symptom is | |
| failure to find system C or C++ headers after a reboot or update. | |
| If the XCode Command Line Tools are missing, install them with: | |
| EOF | |
| code << EOF | |
| sudo xcode-select --install | |
| EOF | |
| details << EOF | |
| If the XCode Command Line Tools are already installed, but XCode | |
| is configured to use the wrong path (e.g., an Xcode application | |
| directory, instead of the "CommandLineTools", which you can | |
| verify with \`xcode-select --print-path\`) then you may need to | |
| "switch" to the CommandLineTools, using: | |
| EOF | |
| code << EOF | |
| sudo xcode-select --switch "${expected_path}" | |
| EOF | |
| details << EOF | |
| See $(link 'https://fuchsia.dev/fuchsia-src/getting_started#macos') | |
| for more details. | |
| EOF | |
| fi | |
| return ${status} | |
| } | |
| dr_linux() { | |
| local status=0 | |
| return ${status} | |
| } | |
| shell_checkup() { | |
| local status=0 | |
| # If the user is using bash, their default interactive "${SHELL}" | |
| # may differ from the script-standard "/bin/bash", and their ~/.bashrc | |
| # may depend on features of their shell that are not present in | |
| # /bin/bash, so launch the shell checkup script using "${SHELL}". | |
| # | |
| # For example, since MacOS includes only bash version 3, Homebrew users | |
| # may install bash 4 in /usr/local/bin/bash, and then select | |
| # bash 4 by adding it to /etc/shells, and running the "chsh" command. | |
| local shell_type="$(basename "${SHELL}")" | |
| case "${shell_type}" in | |
| bash) | |
| local current_debug_flag="$(echo $-|sed -n 's/.*x.*/-x/p')" | |
| eval "${SHELL}" "${current_debug_flag}" "${FUCHSIA_DIR}/tools/devshell/lib/bashrc_checkup.sh" || status=$? | |
| ;; | |
| *) | |
| info "No shell checkup for ${shell_type}" | |
| ;; | |
| esac | |
| return ${status} | |
| } | |
| dr_all() { | |
| local status=0 | |
| shell_checkup || status=$? | |
| return ${status} | |
| } | |
| main() { | |
| local status=0 | |
| case $(uname) in | |
| Darwin) | |
| dr_mac || status=$? | |
| ;; | |
| Linux) | |
| dr_linux || status=$? | |
| ;; | |
| esac | |
| dr_all || status=$? | |
| if (( ${status} == 0 )); then | |
| info "No known issues were found. You appear to be in good health!" | |
| fi | |
| return ${status} | |
| } | |
| main "$@" || exit $? |