Skip to content

Commit

Permalink
mv to pkg build etc.
Browse files Browse the repository at this point in the history
some symlinks to make transitioning easier
  • Loading branch information
mxcl committed Feb 12, 2023
1 parent 8f23d11 commit 37ae553
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 134 deletions.
65 changes: 58 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,69 @@

# BrewKit

The BrewKit builds packages.
BrewKit is build infrastructure for tea.

```sh
tea +tea.xyz/brewkit build zlib.net
tea +tea.xyz/brewkit pkg build zlib.net
```

If you are inside a pantry and tea magic is installed you can omit package
names, BrewKit will figure out what packages you are editing and build them.
If you are inside a pantry and tea magic is installed you can omit the `tea`
preamable and package names, BrewKit will figure out what packages you are
editing and build them.

```sh
xc build
$ pkg build
tea.xyz/brewkit: building zlib.net
```

Here [`xc`](xcfile.dev) reads the instructions from the pantry README to know
to call the full command.
You can build for Linux (via Docker) using `-L`, eg:

```sh
pkg -L build
```

## Without Magic

If you don’t have tea’s magic installed you need to explicitly add brewkit to
the environment:

```sh
tea +tea.xyz/brewkit pkg build
```

## Outside a Pantry Checkout

Outside a pantry checkout you need to both ask `tea` to add brewkit to the
environment and specify which package to operate on. Outside a pantry checkout
we operate against your tea installation (which defaults to `~/.tea`).

```sh
tea +tea.xyz/brewkit pkg build zlib.net
```

## Additions

This repo is for tooling built on top of the tea primitives with the purpose
of generalized building and testing of open source packages.

If you have an idea for an addition open a [discussion]!

[discussion]: https://github.com/orgs/teaxyz/discussions

# Stuff That Needs to be Added

Getting the `rpath` out of a macOS binary:

```sh
lsrpath() {
otool -l "$@" |
awk '
/^[^ ]/ {f = 0}
$2 == "LC_RPATH" && $1 == "cmd" {f = 1}
f && gsub(/^ *path | \(offset [0-9]+\)$/, "") == 2
'
}
```

This should be added to a `pkg doctor` type thing I reckon. eg.
`pkg doctor zlib.net -Q:rpath`.
88 changes: 0 additions & 88 deletions bin/build

This file was deleted.

1 change: 1 addition & 0 deletions bin/build
52 changes: 52 additions & 0 deletions bin/pkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh

set -e

arg="$1"
shift

if test "$arg" = "-L"; then

if test -z "$TEA_PREFIX"; then
echo "tea.xyz/brewkit: error: TEA_PREFIX unset" >&2
exit 1
fi

if test -z "$GITHUB_TOKEN"; then
GITHUB_TOKEN=$(tea gh auth token)
fi

if test -n "$SRCROOT"; then
docker run \
--name tea \
--rm \
--volume "$SRCROOT/tea.linux/home":/root \
--volume "$SRCROOT/tea.linux":/root/.tea \
--volume "$TEA_PREFIX/tea.xyz/var/www":/root/.tea/tea.xyz/var/www \
--volume /root/.tea/tea.xyz/var/pantry \
--volume /root/.tea/tea.xyz/var/pantries \
--volume "$SRCROOT"/projects:/pantry/projects \
--env GITHUB_TOKEN=$GITHUB_TOKEN \
--env TEA_PANTRY_PATH=/pantry \
ghcr.io/teaxyz/infuser \
tea +tea.xyz/brewkit "$@"
else
docker run \
--name tea \
--rm \
--volume "$TEA_PREFIX/tea.xyz/brewkit/mnt":/root \
--volume "$TEA_PREFIX/tea.xyz/var/www":/root/.tea/tea.xyz/var/www \
--volume /root/.tea/tea.xyz/var/pantries \
--volume /root/.tea/tea.xyz/var/pantry \
--env GITHUB_TOKEN=$GITHUB_TOKEN \
ghcr.io/teaxyz/infuser \
tea +tea.xyz/brewkit "$@"
fi
elif test -n "$arg"; then
d="$(cd "$(dirname "$0")" && pwd)"
export PATH="$d:$PATH"
exec pkg-"$arg" "$@"
else
echo "tea.xyz/brewkit: error: invalid usage" >&2
exit 1
fi
88 changes: 88 additions & 0 deletions bin/pkg-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/bash

set -e

if test -n "$RUNNER_DEBUG" -a -n "$GITHUB_ACTIONS" -o -n "$VERBOSE"; then
set -x
fi

d="$(cd $(dirname $0)/.. && pwd)"
PATH="$d/libexec:$PATH"

if test -z "$1"; then
if test -z "$TEA_PANTRY_PATH"; then
echo "error: TEA_PANTRY_PATH is not set" >&2
exit 1
fi
for x in $(echo "$TEA_PANTRY_PATH" | tr ':' '\n'); do
if test -d "$x"/.git; then
PKGS="$(GIT_DIR="$x"/.git peek.sh) $PKGS"
fi
done
else
PKGS="$@"
fi

if test -z "$GITHUB_TOKEN"; then
export GITHUB_TOKEN=$(tea gh auth token)
fi

# should one of these depend on the other:
# ensure they are build in the correct order
PKGS="$(sort.ts $PKGS --delimiter ' ')"

for PKG in $PKGS; do
PKG="$(resolve.ts $PKG)"
ZIP="$(query.ts $PKG --src)"
PREFIX="$(query.ts $PKG --prefix)"
SRCDIR="$(query.ts $PKG --srcdir)"

if test -n "$ZIP"; then
fetch.ts $PKG -o "$ZIP"
fi

if test -f "$ZIP"; then
extract.ts "$ZIP" --pkg $PKG --output-dir "$SRCDIR"
else
mkdir -p "$SRCDIR"
fi

DEPS=$(deps.ts $PKG --build) # eg. nodejs.org^4
DEPS=$(install.ts $DEPS) # eg. ~/.tea/nodejs.org/v4.3.2

mkdir -p "$SRCDIR"
BUILD_SCRIPT="$(stage.ts $PKG --srcdir "$SRCDIR" --prefix "$PREFIX" --deps "$DEPS")"

if command -v bash 2>/dev/null; then
BASH=bash
else
BASH="tea bash"
fi

$BASH -e "$BUILD_SCRIPT"

PATH="$d/share/brewkit:$PATH" fixup.ts "$PREFIX" --deps "$DEPS"

find "$PREFIX" -type f -name \*.la -delete

link.ts "$PREFIX" $PKG

if test -n "$GITHUB_ACTIONS"; then
GH_PKGS="$PKG $GH_PKGS"
GH_RELATIVE_PATHS="$GH_RELATIVE_PATHS ${PREFIX#$TEA_PREFIX/}"

if test -f "$ZIP"; then
GH_SRCS="$GH_SRCS ${ZIP#$TEA_PREFIX/}"
GH_SRCS_RELATIVE_PATHS="$GH_SRCS_RELATIVE_PATHS ${ZIP#$TEA_PREFIX/}"
else
GH_SRCS="$GH_SRCS ~"
fi
fi
done

if test -n "$GITHUB_ACTIONS"; then
echo "pkgs=$GH_PKGS" >> $GITHUB_OUTPUT
echo "relative-paths=$GH_RELATIVE_PATHS" >> $GITHUB_OUTPUT
echo "srcs=$GH_SRCS" >> $GITHUB_OUTPUT
echo "srcs-relative-paths=$GH_SRCS_RELATIVE_PATHS" >> $GITHUB_OUTPUT
fi
File renamed without changes.
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions bin/pkg-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh

set -e

d="$(cd $(dirname $0)/.. && pwd)"
PATH="$d/libexec:$PATH"

if test -z "$1"; then
if test -z "$TEA_PANTRY_PATH"; then
echo "error: TEA_PANTRY_PATH is not set" >&2
exit 1
fi
for x in $(echo "$TEA_PANTRY_PATH" | tr ':' '\n'); do
if test -d "$x"/.git; then
PKGS="$(GIT_DIR="$x"/.git peek.sh) $PKGS"
fi
done
else
PKGS="$1"
fi

for PKG in $PKGS; do
PKG="$(resolve.ts $PKG --cellar)"
DEPS="$(deps.ts $PKG --test)"
DEPS="$(install.ts $DEPS)"
DSTDIR="$(query.ts $PKG --testdir)"

mkdir -p "$DSTDIR"

stage-test.ts $PKG --deps "$DEPS" --dstdir "$DSTDIR"

if command -v bash 2>/dev/null; then
BASH=bash
else
BASH="tea bash"
fi

$BASH -e "$DSTDIR"/xyz.tea.test.sh
done
39 changes: 0 additions & 39 deletions bin/test

This file was deleted.

1 change: 1 addition & 0 deletions bin/test

0 comments on commit 37ae553

Please sign in to comment.