33import { parseFlags } from "cliffy/flags/mod.ts"
44import { hooks , utils , Path } from "pkgx"
55import undent from "outdent"
6+ import host from "libpkgx/utils/host.ts" ;
67
78const { usePantry, useCellar, useConfig, useShellEnv } = hooks
89const { pkg : pkgutils , panic } = utils
@@ -31,10 +32,20 @@ const deps = await (() => {
3132 return Promise . all ( pp )
3233} ) ( )
3334const dstdir = new Path ( flags . dstdir )
34- const yml = await pantry . project ( pkg ) . yaml ( )
35+ const project = pantry . project ( pkg )
36+ const yml = await project . yaml ( )
3537const installations = [ ...deps ]
3638if ( deps . find ( x => x . pkg . project == self . pkg . project ) === undefined ) installations . push ( self )
3739
40+ /// try to find `pkgx` since we deliberately withold it from the PATH for tests
41+ /// since it needs to be an explicit dependency
42+ const pkgx = ( PATH => {
43+ for ( const path of PATH . split ( ":" ) ) {
44+ const f = Path . abs ( path ) ?. join ( "pkgx" ) . isExecutableFile ( )
45+ if ( f ) return f . string
46+ }
47+ } ) ( Deno . env . get ( "PATH" ) ?? '' ) ?? 'pkgx'
48+
3849Deno . env . set ( "HOME" , dstdir . string ) //lol side-effects beware!
3950const env = await useShellEnv ( ) . map ( { installations } )
4051
@@ -43,44 +54,20 @@ if (!yml.test) throw "no `test` node in package.yml"
4354env [ 'PATH' ] ??= [ ]
4455env [ 'PATH' ] . push ( "/usr/bin:/bin" )
4556
46- if ( ! deps . find ( ( { pkg} ) => pkg . project == 'llvm.org' || pkg . project == 'gnu.org/gcc' ) ) {
47- /// add our helper cc toolchain unless the package has picked its own toolchain
48- env [ 'PATH' ] . unshift ( new Path ( new URL ( import . meta. url ) . pathname ) . parent ( ) . parent ( ) . join ( "share/toolchain/bin" ) . string )
49-
50- //COPY PASTA from stage.ts
51- const d = dstdir . join ( 'dev.pkgx.bin' ) . mkdir ( )
52- const symlink = ( names : string [ ] , { to} : { to : string } ) => {
53- for ( const name of names ) {
54- const path = d . join ( name )
55- if ( path . exists ( ) ) continue
56- const target = useConfig ( ) . prefix . join ( 'llvm.org/v*/bin' , to )
57- path . ln ( 's' , { target } )
58- }
59- }
60-
61- symlink ( [ "ar" ] , { to : "llvm-ar" } )
62- symlink ( [ "as" ] , { to : "llvm-as" } )
63- symlink ( [ "cc" , "gcc" , "clang" ] , { to : "clang" } )
64- symlink ( [ "c++" , "g++" , "clang++" ] , { to : "clang++" } )
65- symlink ( [ "cpp" ] , { to : "clang-cpp" } )
66- symlink ( [ "ld" ] , { to : "lld" } )
67- symlink ( [ "lld" ] , { to : "lld" } )
68- symlink ( [ "ld64.lld" ] , { to : "ld64.lld" } )
69- symlink ( [ "lld-link" ] , { to : "lld-link" } )
70- symlink ( [ "objcopy" ] , { to : "llvm-objcopy" } )
71- symlink ( [ "readelf" ] , { to : "llvm-readelf" } )
72- symlink ( [ "strip" ] , { to : "llvm-strip" } )
73- symlink ( [ "nm" ] , { to : "llvm-nm" } )
74- symlink ( [ "ranlib" ] , { to : "llvm-ranlib" } )
75- symlink ( [ "strings" ] , { to : "llvm-strings" } )
76- }
77-
7857let text = undent `
79- #!/usr/bin/env bash
80-
81- set -e
82- set -o pipefail
83- set -x
58+ #!/usr/bin/env -S pkgx bash
59+
60+ set -exo pipefail
61+
62+ command_not_found_handle() {
63+ echo "::warning::\\\`$1\\\` is not an explicit dependency!"
64+ case $1 in
65+ cc|c++|ld)
66+ ${ pkgx } +llvm.org -- "$@";;
67+ *)
68+ ${ pkgx } -- "$@";;
69+ esac
70+ }
8471
8572 export PKGX_DIR="${ useConfig ( ) . prefix } "
8673 export HOME="${ dstdir } "
0 commit comments