diff --git a/projects/go.dev/package.yml b/projects/go.dev/package.yml index aba07ab2..b41c02b1 100644 --- a/projects/go.dev/package.yml +++ b/projects/go.dev/package.yml @@ -22,9 +22,8 @@ build: curl.se: '*' nixos.org/patchelf: ^0.15 script: |- - export GOROOT_BOOTSTRAP="$(cd ../.. && echo $PWD)/bootstrap" - if test ! -d $GOROOT_BOOTSTRAP; then - # TODO something better than this... + export GOROOT_BOOTSTRAP="$(dirname "{{prefix}}")/bootstrap" + if test ! -d "$GOROOT_BOOTSTRAP"; then case "X{{ hw.target }}" in "Xaarch64-apple-darwin") GOARCH="darwin-arm64";; "Xx86_64-apple-darwin") GOARCH="darwin-amd64";; @@ -35,22 +34,20 @@ build: exit 1 esac - curl -L https://storage.googleapis.com/golang/go1.16.${GOARCH}.tar.gz | tar xzf - -C ../.. - mv ../../go ../../bootstrap + curl -L https://storage.googleapis.com/golang/go1.16.${GOARCH}.tar.gz | tar xzf - -C "$GOROOT_BOOTSTRAP" --strip-components=1 fi - export GOROOT_FINAL="{{ prefix }}" + export GOROOT_FINAL="{{prefix}}" cd src ./make.bash # cleanup - cd ../.. - mv src foo - mv foo/* . - rmdir foo + cd .. rm src/*.{bash,bat,rc} rm src/Make.dist - find . -mindepth 1 -maxdepth 1 -type f -delete -not -name build.sh + mkdir "{{prefix}}" + mv * "{{prefix}}" + find "{{prefix}}" -mindepth 1 -maxdepth 1 -type f -delete -not -name build.sh test: script: | diff --git a/scripts/bottle.ts b/scripts/bottle.ts index b0ab332f..a9b1ffbe 100755 --- a/scripts/bottle.ts +++ b/scripts/bottle.ts @@ -20,7 +20,6 @@ import { encode } from "deno/encoding/hex.ts" import Path from "path" const cellar = useCellar() -const filesListName = 'files.txt' //-------------------------------------------------------------------------- main @@ -37,10 +36,6 @@ if (import.meta.main) { const installation = await cellar.resolve(pkg) const path = await bottle(installation) const checksum = await sha256(path) - artifacts.push(installation.path.join(filesListName)) - - if (!path) throw new Error("wtf: bottle already exists") - if (!checksum) throw new Error("failed to compute checksum") console.log({ bottled: { path } }) @@ -66,71 +61,17 @@ if (import.meta.main) { //------------------------------------------------------------------------- funcs export async function bottle({ path: kegdir, pkg }: Installation): Promise { - - const files = await walk(kegdir, path => { - /// HACK: `go` requires including the `src` dir - const isGo = kegdir.string.match(/\/go.dev\//) - switch (path.relative({ to: kegdir })) { - case 'src': - return isGo ? 'accumulate' : 'skip' - case 'build.sh': - case filesListName: - return 'skip' - default: - return 'accumulate' - } - }) - const relativePaths = files.map(x => x.relative({ to: usePrefix() })) - const filelist = kegdir - .join(filesListName) - .write({ - text: relativePaths.join("\n"), - force: true - }) const tarball = useCache().bottle(pkg) - - await run({ - cmd: [ - "tar", "zcf", tarball, "--files-from", filelist - ], - cwd: usePrefix() - }) - + const cwd = usePrefix() + const cmd = ["tar", "zcf", tarball, kegdir.relative({ to: cwd })] + await run({ cmd, cwd }) return tarball } -// using our own because of: https://github.com/denoland/deno_std/issues/1359 -// but frankly this also is more suitable for our needs here -type Continuation = 'accumulate' | 'skip' - -export async function walk(root: Path, body: (entry: Path) => Continuation): Promise { - const rv: Path[] = [] - const stack: Path[] = [root] - - do { - root = stack.pop()! - for await (const [path, entry] of root.ls()) { - switch (body(path)) { - case 'accumulate': - if (entry.isDirectory) { - stack.push(path) - } else { - rv.push(path) - } - break - case 'skip': - continue - } - } - } while (stack.length > 0) - - return rv -} - async function sha256(file: Path): Promise { const sha = await Deno.open(file.string, { read: true }) .then(file => crypto.subtle.digest("SHA-256", file.readable)) .then(buf => new TextDecoder().decode(encode(new Uint8Array(buf)))) const text = `${sha} ${file.basename()}` - return new Path(`${file}.sha256sum`).write({ text }) + return new Path(`${file}.sha256sum`).write({ text, force: true }) } diff --git a/scripts/build/build.ts b/scripts/build/build.ts index 6cac1c77..abe8e50a 100644 --- a/scripts/build/build.ts +++ b/scripts/build/build.ts @@ -2,7 +2,7 @@ import { useSourceUnarchiver, useCellar, usePantry, useCache, usePrefix } from " import { link, hydrate } from "prefab" import { Installation, Package } from "types" import useShellEnv, { expand } from "hooks/useShellEnv.ts" -import { run, undent, host } from "utils" +import { run, undent, host, pkg_str } from "utils" import fix_pkg_config_files from "./fix-pkg-config-files.ts" import fix_linux_rpaths from "./fix-linux-rpaths.ts" import Path from "path" @@ -16,7 +16,7 @@ export default async function _build(pkg: Package) { const [deps, wet] = await calc_deps() await clean() const env = await mkenv() - const dst = cellar.mkpath(pkg) + const dst = cellar.keg(pkg) const src = await fetch_src(pkg) const installation = await build() await link(installation) @@ -37,11 +37,9 @@ export default async function _build(pkg: Package) { async function clean() { const installation = await should_clean() - if (!installation) return - console.log({ cleaning: installation.path }) - for await (const [path, {name}] of installation.path.ls()) { - if (name == 'src') continue - path.rm({ recursive: true }) + if (installation) { + console.log({ cleaning: installation.path }) + installation.path.rm({ recursive: true }) } async function should_clean() { @@ -61,7 +59,7 @@ export default async function _build(pkg: Package) { const env = await useShellEnv([...deps.runtime, ...deps.build]) if (env.pending.length) { - console.error({uninstalled: env.pending}) + console.error({uninstalled: env.pending.map(pkg_str)}) throw new Error("uninstalled") } @@ -75,7 +73,7 @@ export default async function _build(pkg: Package) { async function build() { const sh = await pantry.getScript(pkg, 'build') - const cmd = dst.join("build.sh").write({ force: true, text: undent` + const cmd = src.parent().join("build.sh").write({ force: true, text: undent` #!/bin/bash set -e @@ -110,15 +108,10 @@ export default async function _build(pkg: Package) { } async function fetch_src(pkg: Package): Promise { - const dstdir = cellar.mkpath(pkg).join("src") + const dstdir = usePrefix().join(pkg.project, "src", `v${pkg.version}`) const { url, stripComponents } = await pantry.getDistributable(pkg) - const { download } = useCache() - const zip = await download({ pkg, url, type: 'src' }) - await useSourceUnarchiver().unarchive({ - dstdir, - zipfile: zip, - stripComponents - }) + const zipfile = await useCache().download({ pkg, url, type: 'src' }) + await useSourceUnarchiver().unarchive({ dstdir, zipfile, stripComponents }) return dstdir }