From 8450756aec964f262d5c4e8dd1a621730bf17476 Mon Sep 17 00:00:00 2001 From: Facebook Community Bot Date: Tue, 24 Sep 2024 14:33:43 -0700 Subject: [PATCH] Re-sync with internal repository (#353) The internal and external repositories are out of sync. This Pull Request attempts to brings them back in sync by patching the GitHub repository. Please carefully review this patch. You must disable ShipIt for your project in order to merge this pull request. DO NOT IMPORT this pull request. Instead, merge it directly on GitHub using the MERGE BUTTON. Re-enable ShipIt after merging. --- build/buck2/README.md | 16 +++++++ build/buck2/install_deps/BUCK | 15 ++++++ build/buck2/install_deps/install_deps.sh | 58 ++++++++++++++++++++++++ build/buck2/install_deps/repos/fedora | 1 + build/buck2/install_deps/repos/homebrew | 1 + build/buck2/install_deps/repos/ubuntu | 1 + 6 files changed, 92 insertions(+) create mode 100644 build/buck2/README.md create mode 100644 build/buck2/install_deps/BUCK create mode 100755 build/buck2/install_deps/install_deps.sh create mode 100755 build/buck2/install_deps/repos/fedora create mode 100755 build/buck2/install_deps/repos/homebrew create mode 100755 build/buck2/install_deps/repos/ubuntu diff --git a/build/buck2/README.md b/build/buck2/README.md new file mode 100644 index 000000000..c4237b1ab --- /dev/null +++ b/build/buck2/README.md @@ -0,0 +1,16 @@ +# Easy buck2 builds for Facebook projects + +This directory contains buck2 targets designed to simplify buck2 builds of +Meta open source projects. + +The most notable target is `//build/buck2/install_deps`, which will attempt to +discover and install necessary third party packages from apt / dnf / etc. +See the "repos" directory for the currently supported platforms. + +## Deployment + +This directory is copied literally into a number of different Facebook open +source repositories. Any change made to code in this directory will be +automatically be replicated by our open source tooling into all GitHub hosted +repositories that use `buck2`. Typically this directory is copied +into the open source repositories as `build/buck2/`. diff --git a/build/buck2/install_deps/BUCK b/build/buck2/install_deps/BUCK new file mode 100644 index 000000000..99bab33a7 --- /dev/null +++ b/build/buck2/install_deps/BUCK @@ -0,0 +1,15 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under both the MIT license found in the +# LICENSE-MIT file in the root directory of this source tree and the Apache +# License, Version 2.0 found in the LICENSE-APACHE file in the root directory +# of this source tree. +load("@fbcode_macros//build_defs:native_rules.bzl", "buck_sh_binary") + +oncall("open_source") + +buck_sh_binary( + name = "install_deps", + main = "install_deps.sh", + resources = glob(["repos/*"]), +) diff --git a/build/buck2/install_deps/install_deps.sh b/build/buck2/install_deps/install_deps.sh new file mode 100755 index 000000000..9cb370e50 --- /dev/null +++ b/build/buck2/install_deps/install_deps.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. + +if [ -z "$INSTALL_COMMAND" ]; then + if [ -f /etc/os-release ]; then + . /etc/os-release; + fi + + if command -v brew >/dev/null; then + ID="homebrew"; + fi + + if [ -f "$BUCK_DEFAULT_RUNTIME_RESOURCES/repos/$ID" ]; then + # shellcheck disable=SC1090 + . "$BUCK_DEFAULT_RUNTIME_RESOURCES/repos/$ID"; + else + echo "Unable to determine platform id / install commands"; + return 1; + fi +fi + +if [ -z "${BUCK2_COMMAND}" ]; then + if command -v buck2 >/dev/null; then + BUCK2_COMMAND="buck2" + elif command -v dotslash >/dev/null && [ -f ./buck2 ]; then + BUCK2_COMMAND="dotslash ./buck2" + else + echo "Unable to determine buck2 command"; + return 1; + fi +fi + +PKG_FILE=$(mktemp /tmp/buck2-install-pkgs.XXXXXX) + +eval "$BUCK2_COMMAND \\ + cquery \"attrregexfilter(labels, 'third-party:$ID:', deps(//...))\" \\ + --json --output-attribute=labels 2>/dev/null \\ + | grep -o \"third-party:$ID:[^\\\"]*\" \\ + | sort \\ + | uniq \\ + | sed \"s/third-party:$ID://\" \\ + > $PKG_FILE" + +echo "About to install the project dependencies with the following command:" +echo +eval "cat $PKG_FILE | xargs echo $INSTALL_COMMAND" +echo +echo "Press \"y\" to continue" +read -r REPLY +echo + +if expr "X$REPLY" : '^X[Yy]$' >/dev/null; then + eval "cat $PKG_FILE | xargs -r $INSTALL_COMMAND" +else + echo "Not installing dependencies" +fi + +rm "$PKG_FILE" diff --git a/build/buck2/install_deps/repos/fedora b/build/buck2/install_deps/repos/fedora new file mode 100755 index 000000000..6182343bd --- /dev/null +++ b/build/buck2/install_deps/repos/fedora @@ -0,0 +1 @@ +INSTALL_COMMAND="sudo -E dnf install -y" diff --git a/build/buck2/install_deps/repos/homebrew b/build/buck2/install_deps/repos/homebrew new file mode 100755 index 000000000..5d1dafb82 --- /dev/null +++ b/build/buck2/install_deps/repos/homebrew @@ -0,0 +1 @@ +INSTALL_COMMAND="brew install" diff --git a/build/buck2/install_deps/repos/ubuntu b/build/buck2/install_deps/repos/ubuntu new file mode 100755 index 000000000..b1ce68000 --- /dev/null +++ b/build/buck2/install_deps/repos/ubuntu @@ -0,0 +1 @@ +INSTALL_COMMAND="sudo -E apt-get install -y"