diff --git a/bin/pkg-build b/bin/pkg-build index 725cfb6c..2ad321a2 100755 --- a/bin/pkg-build +++ b/bin/pkg-build @@ -1,6 +1,8 @@ -#!/usr/bin/env -S pkgx bash -eo pipefail +#!/usr/bin/env -S pkgx bash # shellcheck shell=bash +set -eo pipefail + PKGX_DIR=${PKGX_DIR:-"$HOME/.pkgx"} if pwd | grep -q ' '; then @@ -32,7 +34,7 @@ if test -n "$PKGX_DOCKER"; then exec "$d"/bin/pkg-docker build "$PKGS" fi -if ! available.ts "$PKGS"; then +if ! available.ts $PKGS; then echo "warning: not supported on current platform" >&2 exit 0 fi diff --git a/bin/pkg-clean b/bin/pkg-clean index 59ada6ff..4931132c 100755 --- a/bin/pkg-clean +++ b/bin/pkg-clean @@ -1,6 +1,8 @@ -#!/usr/bin/env -S pkgx bash -eo pipefail +#!/usr/bin/env -S pkgx bash # shellcheck shell=bash +set -eo pipefail + d="$(cd "$(dirname "$0")"/.. && pwd)" PATH="$d/libexec:$PATH" diff --git a/bin/pkg-docker b/bin/pkg-docker index 72ce01ac..4f5dae1f 100755 --- a/bin/pkg-docker +++ b/bin/pkg-docker @@ -18,7 +18,7 @@ if test "$arg0" = docker; then exit 1 elif shift; then # ensure this brewkit is used - CMD="pkgx +deno.land ""$d/bin/pkg-$arg0" + CMD="$d/bin/pkg-$arg0" ADDARGS="--volume ""$d"":""$d" else # we were invoked as `pkg -L` by itself diff --git a/bin/pkg-edit b/bin/pkg-edit index c92cb46f..3a6e271a 100755 --- a/bin/pkg-edit +++ b/bin/pkg-edit @@ -1,7 +1,7 @@ -#!/usr/bin/env -S pkgx bash -eo pipefail +#!/usr/bin/env -S pkgx bash # shellcheck shell=bash -set -e +set -eo pipefail d="$(cd "$(dirname "$0")"/.. && pwd)" PATH="$d/libexec:$PATH" diff --git a/bin/pkg-fetch b/bin/pkg-fetch index 2c17b792..4b7d7047 100755 --- a/bin/pkg-fetch +++ b/bin/pkg-fetch @@ -1,6 +1,8 @@ -#!/usr/bin/env -S pkgx bash -eo pipefail +#!/usr/bin/env -S pkgx bash # shellcheck shell=bash +set -eo pipefail + d="$(cd "$(dirname "$0")"/.. && pwd)" PATH="$d/libexec:$PATH" diff --git a/bin/pkg-fixup b/bin/pkg-fixup index 90da6eed..d3bbc46b 100755 --- a/bin/pkg-fixup +++ b/bin/pkg-fixup @@ -1,6 +1,8 @@ -#!/usr/bin/env -S pkgx bash -eo pipefail +#!/usr/bin/env -S pkgx bash # shellcheck shell=bash +set -eo pipefail + d="$(cd "$(dirname "$0")"/.. && pwd)" PATH="$d/libexec:$PATH" diff --git a/bin/pkg-test b/bin/pkg-test index 402e7593..180a5945 100755 --- a/bin/pkg-test +++ b/bin/pkg-test @@ -1,6 +1,8 @@ -#!/usr/bin/env -S pkgx bash -eo pipefail +#!/usr/bin/env -S pkgx bash # shellcheck shell=bash +set -eo pipefail + d="$(cd "$(dirname "$0")"/.. && pwd)" PATH="$d/libexec:$PATH" diff --git a/libexec/find.ts b/libexec/find.ts index 4e4c659e..4f4c7f4b 100755 --- a/libexec/find.ts +++ b/libexec/find.ts @@ -1,10 +1,13 @@ #!/usr/bin/env -S pkgx deno run --allow-read --allow-env -import { hooks } from "pkgx" +import { hooks, utils } from "pkgx" const { find } = hooks.usePantry() for (const arg of Deno.args) { - const rv = await find(arg) + + const {project, constraint} = utils.pkg.parse(arg) + + const rv = await find(project) if (rv.length > 1) { console.error("multiple matches: " + rv.map(({project}) => project).join(' ')) @@ -18,6 +21,7 @@ for (const arg of Deno.args) { if (Deno.env.get("_PATHS")) { console.info(rv[0].path.string) } else { - console.info(rv[0].project) + const pkg = {project: rv[0].project, constraint} + console.info(utils.pkg.str(pkg)) } } diff --git a/libexec/stage-test.ts b/libexec/stage-test.ts index 6f041fa4..df7c5634 100755 --- a/libexec/stage-test.ts +++ b/libexec/stage-test.ts @@ -3,6 +3,7 @@ import { parseFlags } from "cliffy/flags/mod.ts" import { hooks, utils, Path } from "pkgx" import undent from "outdent" +import host from "libpkgx/utils/host.ts"; const { usePantry, useCellar, useConfig, useShellEnv } = hooks const { pkg: pkgutils, panic } = utils @@ -31,10 +32,20 @@ const deps = await (() => { return Promise.all(pp) })() const dstdir = new Path(flags.dstdir) -const yml = await pantry.project(pkg).yaml() +const project = pantry.project(pkg) +const yml = await project.yaml() const installations = [...deps] if (deps.find(x => x.pkg.project == self.pkg.project) === undefined) installations.push(self) +/// try to find `pkgx` since we deliberately withold it from the PATH for tests +/// since it needs to be an explicit dependency +const pkgx = (PATH => { + for (const path of PATH.split(":")) { + const f = Path.abs(path)?.join("pkgx").isExecutableFile() + if (f) return f.string + } +})(Deno.env.get("PATH") ?? '') ?? 'pkgx' + Deno.env.set("HOME", dstdir.string) //lol side-effects beware! const env = await useShellEnv().map({ installations }) @@ -43,44 +54,20 @@ if (!yml.test) throw "no `test` node in package.yml" env['PATH'] ??= [] env['PATH'].push("/usr/bin:/bin") -if (!deps.find(({pkg}) => pkg.project == 'llvm.org' || pkg.project == 'gnu.org/gcc')) { - /// add our helper cc toolchain unless the package has picked its own toolchain - env['PATH'].unshift(new Path(new URL(import.meta.url).pathname).parent().parent().join("share/toolchain/bin").string) - - //COPY PASTA from stage.ts - const d = dstdir.join('dev.pkgx.bin').mkdir() - const symlink = (names: string[], {to}: {to: string}) => { - for (const name of names) { - const path = d.join(name) - if (path.exists()) continue - const target = useConfig().prefix.join('llvm.org/v*/bin', to) - path.ln('s', { target }) - } - } - - symlink(["ar"], {to: "llvm-ar"}) - symlink(["as"], {to: "llvm-as"}) - symlink(["cc", "gcc", "clang"], {to: "clang"}) - symlink(["c++", "g++", "clang++"], {to: "clang++"}) - symlink(["cpp"], {to: "clang-cpp"}) - symlink(["ld"], {to: "lld"}) - symlink(["lld"], {to: "lld"}) - symlink(["ld64.lld"], {to: "ld64.lld"}) - symlink(["lld-link"], {to: "lld-link"}) - symlink(["objcopy"], {to: "llvm-objcopy"}) - symlink(["readelf"], {to: "llvm-readelf"}) - symlink(["strip"], {to: "llvm-strip"}) - symlink(["nm"], {to: "llvm-nm"}) - symlink(["ranlib"], {to: "llvm-ranlib"}) - symlink(["strings"], {to: "llvm-strings"}) -} - let text = undent` - #!/usr/bin/env bash - - set -e - set -o pipefail - set -x + #!/usr/bin/env -S pkgx bash + + set -exo pipefail + + command_not_found_handler() { + echo "::warning::\\\`$1\\\` is not an explicit dependency!" + case $1 in + cc|c++|ld) + ${pkgx} +llvm.org -- "$@";; + *) + ${pkgx} -- "$@";; + esac + } export PKGX_DIR="${useConfig().prefix}" export HOME="${dstdir}" diff --git a/libexec/stage.ts b/libexec/stage.ts index c15541b4..4cc0b40c 100755 --- a/libexec/stage.ts +++ b/libexec/stage.ts @@ -61,36 +61,6 @@ const sup_PATH = [new Path(new URL(import.meta.url).pathname).parent().parent(). if (!deps.find(({pkg}) => pkg.project == 'llvm.org' || pkg.project == 'gnu.org/gcc')) { /// add our helper cc toolchain unless the package has picked its own toolchain sup_PATH.push(new Path(new URL(import.meta.url).pathname).parent().parent().join("share/toolchain/bin")) - - if (host().platform != "darwin") { - const symlink = (names: string[], {to}: {to: string}) => { - const d = blddir.join('dev.pkgx.bin').mkdir() - for (const name of names) { - const path = d.join(name) - if (path.exists()) continue - const target = prefix.join('llvm.org/v*/bin', to) - path.ln('s', { target }) - } - } - - symlink(["cc", "gcc", "clang"], {to: "clang"}) - symlink(["c++", "g++", "clang++"], {to: "clang++"}) - symlink(["cpp"], {to: "clang-cpp"}) - - symlink(["ld"], {to: "lld"}) - symlink(["lld"], {to: "lld"}) - symlink(["ld64.lld"], {to: "ld64.lld"}) - symlink(["lld-link"], {to: "lld-link"}) - - symlink(["ar"], {to: "llvm-ar"}) - symlink(["as"], {to: "llvm-as"}) - symlink(["nm"], {to: "llvm-nm"}) - symlink(["objcopy"], {to: "llvm-objcopy"}) - symlink(["ranlib"], {to: "llvm-ranlib"}) - symlink(["readelf"], {to: "llvm-readelf"}) - symlink(["strings"], {to: "llvm-strings"}) - symlink(["strip"], {to: "llvm-strip"}) - } } /// calc env @@ -112,7 +82,7 @@ if (host().platform == 'linux' && host().arch == 'x86-64') { } const text = undent` - #!/bin/bash + #!/usr/bin/env -S pkgx bash set -exo pipefail diff --git a/scripts/publish-release.sh b/scripts/publish-release.sh index 508050c8..4806fbf2 100755 --- a/scripts/publish-release.sh +++ b/scripts/publish-release.sh @@ -1,4 +1,6 @@ -#!/usr/bin/env -S pkgx +git +gh +jq +gum +npx +deno bash -eo pipefail +#!/usr/bin/env -S pkgx +git +gh +jq +gum +npx +deno bash + +set -eo pipefail # the back and forth here is because draft releases cannot trigger # GitHub Actions 😒 diff --git a/share/toolchain/bin/make b/share/toolchain/bin/make index f8642019..133d337e 100755 --- a/share/toolchain/bin/make +++ b/share/toolchain/bin/make @@ -3,5 +3,12 @@ if [ $(uname) = Darwin ]; then exec /usr/bin/make "$@" else - exec pkgx +gnu.org/make make "$@" + if [ -x /usr/local/bin/pkgx ]; then + # removed from PATH deliberately + pkgx=/usr/local/bin/pkgx + else + # probs this is running in pkgx CI/CD + pkgx="${PKGX_DIR:-$HOME/.pkgx}/pkgx.sh/v*/bin/pkgx" + fi + exec "$pkgx" +gnu.org/make make "$@" fi diff --git a/share/toolchain/shim b/share/toolchain/shim index 4c0381c3..3e3014e7 100755 --- a/share/toolchain/shim +++ b/share/toolchain/shim @@ -3,8 +3,15 @@ tool=$(basename $0) if [ $(uname) != Darwin ]; then - "${PKGX_DIR:-$HOME/.pkgx}/pkgx.sh/v*/bin/pkgx" --silent +llvm.org - exec "${SRCROOT:-$HOME}/dev.pkgx.bin/$tool" "$@" + if [ -x /usr/local/bin/pkgx ]; then + # removed from PATH deliberately + #TODO like, probs we should set PKGX or something before removing it from PATH + pkgx=/usr/local/bin/pkgx + else + # if not the above probs this is running in pkgx CI/CD + pkgx="${PKGX_DIR:-$HOME/.pkgx}/pkgx.sh/v*/bin/pkgx" + fi + "$pkgx" --silent +llvm.org "$@" fi case $tool in