|
| 1 | +#!/bin/sh |
| 2 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | +# |
| 4 | +# This source code is licensed under the LICENSE file found in the root |
| 5 | +# directory of this source tree. |
| 6 | + |
| 7 | +if [ -z "$INSTALL_COMMAND" ]; then |
| 8 | + if [ -f /etc/os-release ]; then |
| 9 | + . /etc/os-release; |
| 10 | + fi |
| 11 | + |
| 12 | + if command -v brew >/dev/null; then |
| 13 | + ID="homebrew"; |
| 14 | + fi |
| 15 | + |
| 16 | + if [ -f "$BUCK_DEFAULT_RUNTIME_RESOURCES/repos/$ID" ]; then |
| 17 | + # shellcheck disable=SC1090 |
| 18 | + . "$BUCK_DEFAULT_RUNTIME_RESOURCES/repos/$ID"; |
| 19 | + else |
| 20 | + echo "Unable to determine platform id / install commands"; |
| 21 | + return 1; |
| 22 | + fi |
| 23 | +fi |
| 24 | + |
| 25 | +if [ -z "${BUCK2_COMMAND}" ]; then |
| 26 | + if command -v buck2 >/dev/null; then |
| 27 | + BUCK2_COMMAND="buck2" |
| 28 | + elif command -v dotslash >/dev/null && [ -f ./buck2 ]; then |
| 29 | + BUCK2_COMMAND="dotslash ./buck2" |
| 30 | + else |
| 31 | + echo "Unable to determine buck2 command"; |
| 32 | + return 1; |
| 33 | + fi |
| 34 | +fi |
| 35 | + |
| 36 | +__confirm() { |
| 37 | + echo "Press \"y\" to continue" |
| 38 | + read -r REPLY |
| 39 | + expr "X$REPLY" : '^X[Yy]$' >/dev/null |
| 40 | +} |
| 41 | + |
| 42 | +PKG_FILE=$(mktemp /tmp/buck2-install-pkgs.XXXXXX) |
| 43 | + |
| 44 | +if ! command -v jq >/dev/null; then |
| 45 | + echo "Failed to find jq command, attempting to install with" |
| 46 | + echo |
| 47 | + echo "$INSTALL_COMMAND" jq |
| 48 | + echo |
| 49 | + if __confirm; then |
| 50 | + eval "$INSTALL_COMMAND jq" |
| 51 | + else |
| 52 | + echo "Not confirmed, exiting"; |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | +fi |
| 56 | + |
| 57 | +eval "$BUCK2_COMMAND cquery 'kind(system_packages, deps(//...))' \\ |
| 58 | + --output-attribute=packages --modifier $ID --json 2>/dev/null \\ |
| 59 | + | jq -r '.[].packages[]' \\ |
| 60 | + | sort \\ |
| 61 | + | uniq \\ |
| 62 | + > $PKG_FILE" |
| 63 | + |
| 64 | +echo "About to install the project dependencies with the following command:" |
| 65 | +echo |
| 66 | +eval "cat $PKG_FILE | xargs echo $INSTALL_COMMAND" |
| 67 | +echo |
| 68 | +if __confirm; then |
| 69 | + eval "cat $PKG_FILE | xargs -r $INSTALL_COMMAND" |
| 70 | +else |
| 71 | + echo "Not installing dependencies" |
| 72 | +fi |
| 73 | + |
| 74 | +rm "$PKG_FILE" |
0 commit comments