Skip to content

Commit

Permalink
Re-sync with internal repository
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
facebook-github-bot committed Sep 24, 2024
1 parent 24d281b commit f0c3671
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
16 changes: 16 additions & 0 deletions build/buck2/README.md
Original file line number Diff line number Diff line change
@@ -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/`.
15 changes: 15 additions & 0 deletions build/buck2/install_deps/BUCK
Original file line number Diff line number Diff line change
@@ -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/*"]),
)
58 changes: 58 additions & 0 deletions build/buck2/install_deps/install_deps.sh
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions build/buck2/install_deps/repos/fedora
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSTALL_COMMAND="sudo -E dnf install -y"
1 change: 1 addition & 0 deletions build/buck2/install_deps/repos/homebrew
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSTALL_COMMAND="brew install"
1 change: 1 addition & 0 deletions build/buck2/install_deps/repos/ubuntu
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSTALL_COMMAND="sudo -E apt-get install -y"

0 comments on commit f0c3671

Please sign in to comment.