Skip to content

Commit

Permalink
consequences of llvm/gcc getting cc symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Oct 5, 2023
1 parent 4acc450 commit e52f320
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 85 deletions.
6 changes: 4 additions & 2 deletions bin/pkg-build
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion bin/pkg-clean
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion bin/pkg-docker
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions bin/pkg-edit
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 3 additions & 1 deletion bin/pkg-fetch
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
4 changes: 3 additions & 1 deletion bin/pkg-fixup
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
4 changes: 3 additions & 1 deletion bin/pkg-test
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
10 changes: 7 additions & 3 deletions libexec/find.ts
Original file line number Diff line number Diff line change
@@ -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(' '))
Expand All @@ -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))
}
}
63 changes: 25 additions & 38 deletions libexec/stage-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 })

Expand All @@ -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}"
Expand Down
32 changes: 1 addition & 31 deletions libexec/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion scripts/publish-release.sh
Original file line number Diff line number Diff line change
@@ -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 😒
Expand Down
9 changes: 8 additions & 1 deletion share/toolchain/bin/make
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 9 additions & 2 deletions share/toolchain/shim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e52f320

Please sign in to comment.