Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-sync with internal repository #58

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading