mirror of
https://github.com/ivabus/pantry
synced 2024-11-10 02:25:18 +03:00
Simplify builds by building to /opt/project/src
This commit is contained in:
parent
427986cf7e
commit
ee0275ef71
|
@ -22,9 +22,8 @@ build:
|
||||||
curl.se: '*'
|
curl.se: '*'
|
||||||
nixos.org/patchelf: ^0.15
|
nixos.org/patchelf: ^0.15
|
||||||
script: |-
|
script: |-
|
||||||
export GOROOT_BOOTSTRAP="$(cd ../.. && echo $PWD)/bootstrap"
|
export GOROOT_BOOTSTRAP="$(dirname "{{prefix}}")/bootstrap"
|
||||||
if test ! -d $GOROOT_BOOTSTRAP; then
|
if test ! -d "$GOROOT_BOOTSTRAP"; then
|
||||||
# TODO something better than this...
|
|
||||||
case "X{{ hw.target }}" in
|
case "X{{ hw.target }}" in
|
||||||
"Xaarch64-apple-darwin") GOARCH="darwin-arm64";;
|
"Xaarch64-apple-darwin") GOARCH="darwin-arm64";;
|
||||||
"Xx86_64-apple-darwin") GOARCH="darwin-amd64";;
|
"Xx86_64-apple-darwin") GOARCH="darwin-amd64";;
|
||||||
|
@ -35,22 +34,20 @@ build:
|
||||||
exit 1
|
exit 1
|
||||||
esac
|
esac
|
||||||
|
|
||||||
curl -L https://storage.googleapis.com/golang/go1.16.${GOARCH}.tar.gz | tar xzf - -C ../..
|
curl -L https://storage.googleapis.com/golang/go1.16.${GOARCH}.tar.gz | tar xzf - -C "$GOROOT_BOOTSTRAP" --strip-components=1
|
||||||
mv ../../go ../../bootstrap
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export GOROOT_FINAL="{{ prefix }}"
|
export GOROOT_FINAL="{{prefix}}"
|
||||||
cd src
|
cd src
|
||||||
./make.bash
|
./make.bash
|
||||||
|
|
||||||
# cleanup
|
# cleanup
|
||||||
cd ../..
|
cd ..
|
||||||
mv src foo
|
|
||||||
mv foo/* .
|
|
||||||
rmdir foo
|
|
||||||
rm src/*.{bash,bat,rc}
|
rm src/*.{bash,bat,rc}
|
||||||
rm src/Make.dist
|
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:
|
test:
|
||||||
script: |
|
script: |
|
||||||
|
|
|
@ -20,7 +20,6 @@ import { encode } from "deno/encoding/hex.ts"
|
||||||
import Path from "path"
|
import Path from "path"
|
||||||
|
|
||||||
const cellar = useCellar()
|
const cellar = useCellar()
|
||||||
const filesListName = 'files.txt'
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------- main
|
//-------------------------------------------------------------------------- main
|
||||||
|
@ -37,10 +36,6 @@ if (import.meta.main) {
|
||||||
const installation = await cellar.resolve(pkg)
|
const installation = await cellar.resolve(pkg)
|
||||||
const path = await bottle(installation)
|
const path = await bottle(installation)
|
||||||
const checksum = await sha256(path)
|
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 } })
|
console.log({ bottled: { path } })
|
||||||
|
|
||||||
|
@ -66,71 +61,17 @@ if (import.meta.main) {
|
||||||
|
|
||||||
//------------------------------------------------------------------------- funcs
|
//------------------------------------------------------------------------- funcs
|
||||||
export async function bottle({ path: kegdir, pkg }: Installation): Promise<Path> {
|
export async function bottle({ path: kegdir, pkg }: Installation): Promise<Path> {
|
||||||
|
|
||||||
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)
|
const tarball = useCache().bottle(pkg)
|
||||||
|
const cwd = usePrefix()
|
||||||
await run({
|
const cmd = ["tar", "zcf", tarball, kegdir.relative({ to: cwd })]
|
||||||
cmd: [
|
await run({ cmd, cwd })
|
||||||
"tar", "zcf", tarball, "--files-from", filelist
|
|
||||||
],
|
|
||||||
cwd: usePrefix()
|
|
||||||
})
|
|
||||||
|
|
||||||
return tarball
|
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<Path[]> {
|
|
||||||
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<Path> {
|
async function sha256(file: Path): Promise<Path> {
|
||||||
const sha = await Deno.open(file.string, { read: true })
|
const sha = await Deno.open(file.string, { read: true })
|
||||||
.then(file => crypto.subtle.digest("SHA-256", file.readable))
|
.then(file => crypto.subtle.digest("SHA-256", file.readable))
|
||||||
.then(buf => new TextDecoder().decode(encode(new Uint8Array(buf))))
|
.then(buf => new TextDecoder().decode(encode(new Uint8Array(buf))))
|
||||||
const text = `${sha} ${file.basename()}`
|
const text = `${sha} ${file.basename()}`
|
||||||
return new Path(`${file}.sha256sum`).write({ text })
|
return new Path(`${file}.sha256sum`).write({ text, force: true })
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { useSourceUnarchiver, useCellar, usePantry, useCache, usePrefix } from "
|
||||||
import { link, hydrate } from "prefab"
|
import { link, hydrate } from "prefab"
|
||||||
import { Installation, Package } from "types"
|
import { Installation, Package } from "types"
|
||||||
import useShellEnv, { expand } from "hooks/useShellEnv.ts"
|
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_pkg_config_files from "./fix-pkg-config-files.ts"
|
||||||
import fix_linux_rpaths from "./fix-linux-rpaths.ts"
|
import fix_linux_rpaths from "./fix-linux-rpaths.ts"
|
||||||
import Path from "path"
|
import Path from "path"
|
||||||
|
@ -16,7 +16,7 @@ export default async function _build(pkg: Package) {
|
||||||
const [deps, wet] = await calc_deps()
|
const [deps, wet] = await calc_deps()
|
||||||
await clean()
|
await clean()
|
||||||
const env = await mkenv()
|
const env = await mkenv()
|
||||||
const dst = cellar.mkpath(pkg)
|
const dst = cellar.keg(pkg)
|
||||||
const src = await fetch_src(pkg)
|
const src = await fetch_src(pkg)
|
||||||
const installation = await build()
|
const installation = await build()
|
||||||
await link(installation)
|
await link(installation)
|
||||||
|
@ -37,11 +37,9 @@ export default async function _build(pkg: Package) {
|
||||||
|
|
||||||
async function clean() {
|
async function clean() {
|
||||||
const installation = await should_clean()
|
const installation = await should_clean()
|
||||||
if (!installation) return
|
if (installation) {
|
||||||
console.log({ cleaning: installation.path })
|
console.log({ cleaning: installation.path })
|
||||||
for await (const [path, {name}] of installation.path.ls()) {
|
installation.path.rm({ recursive: true })
|
||||||
if (name == 'src') continue
|
|
||||||
path.rm({ recursive: true })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function should_clean() {
|
async function should_clean() {
|
||||||
|
@ -61,7 +59,7 @@ export default async function _build(pkg: Package) {
|
||||||
const env = await useShellEnv([...deps.runtime, ...deps.build])
|
const env = await useShellEnv([...deps.runtime, ...deps.build])
|
||||||
|
|
||||||
if (env.pending.length) {
|
if (env.pending.length) {
|
||||||
console.error({uninstalled: env.pending})
|
console.error({uninstalled: env.pending.map(pkg_str)})
|
||||||
throw new Error("uninstalled")
|
throw new Error("uninstalled")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +73,7 @@ export default async function _build(pkg: Package) {
|
||||||
async function build() {
|
async function build() {
|
||||||
const sh = await pantry.getScript(pkg, '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
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
@ -110,15 +108,10 @@ export default async function _build(pkg: Package) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetch_src(pkg: Package): Promise<Path> {
|
async function fetch_src(pkg: Package): Promise<Path> {
|
||||||
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 { url, stripComponents } = await pantry.getDistributable(pkg)
|
||||||
const { download } = useCache()
|
const zipfile = await useCache().download({ pkg, url, type: 'src' })
|
||||||
const zip = await download({ pkg, url, type: 'src' })
|
await useSourceUnarchiver().unarchive({ dstdir, zipfile, stripComponents })
|
||||||
await useSourceUnarchiver().unarchive({
|
|
||||||
dstdir,
|
|
||||||
zipfile: zip,
|
|
||||||
stripComponents
|
|
||||||
})
|
|
||||||
return dstdir
|
return dstdir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue