pantry/scripts/build.ts

68 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-08-01 22:43:40 +03:00
#!/usr/bin/env -S tea -E
/*---
dependencies:
gnu.org/tar: 1
tukaani.org/xz: 5
sourceware.org/bzip2: 1
2022-08-01 22:43:40 +03:00
args:
- deno
- run
- --allow-net
- --allow-run
2022-09-08 23:40:35 +03:00
- --allow-read
2022-09-09 16:37:26 +03:00
- --allow-write={{tea.prefix}}
2022-08-01 22:43:40 +03:00
- --allow-env
- --import-map={{ srcroot }}/import-map.json
---*/
import { useCache, usePantry } from "hooks"
2022-09-30 16:03:03 +03:00
import { Installation } from "types"
2022-09-21 10:46:24 +03:00
import { pkg as pkgutils } from "utils"
2022-09-20 18:29:21 +03:00
import { useFlags, usePrefix } from "hooks"
2022-09-28 18:14:46 +03:00
import { set_output } from "./utils/gha.ts"
import build from "./build/build.ts"
2022-09-30 16:03:03 +03:00
import * as ARGV from "./utils/args.ts"
import Path from "path"
2022-08-10 21:58:22 +03:00
2022-08-17 15:22:22 +03:00
useFlags()
2022-08-01 22:43:40 +03:00
const pantry = usePantry()
2022-09-30 16:03:03 +03:00
const dry = await ARGV.toArray(ARGV.pkgs())
2022-09-08 23:40:35 +03:00
const gha = !!Deno.env.get("GITHUB_ACTIONS")
2022-09-13 18:05:04 +03:00
const group_it = gha && dry.length > 1
const rv: InstallationPlus[] = []
2022-09-20 18:29:21 +03:00
if (usePrefix().string != "/opt") {
console.error({ TEA_PREFIX: usePrefix().string })
throw new Error("builds must be performed in /opt (try TEA_PREFIX=/opt)")
}
2022-09-21 10:46:24 +03:00
for (const rq of dry) {
const pkg = await pantry.resolve(rq)
2022-08-01 22:43:40 +03:00
2022-09-13 18:05:04 +03:00
if (group_it) {
2022-09-21 10:46:24 +03:00
console.log("::group::", pkgutils.str(pkg))
2022-09-08 23:40:35 +03:00
} else {
2022-09-21 10:46:24 +03:00
console.log({ building: pkg.project })
2022-09-08 23:40:35 +03:00
}
2022-08-01 22:43:40 +03:00
2022-09-28 18:14:46 +03:00
const install = await build(pkg)
const { url } = await pantry.getDistributable(pkg)
const extname = url.path().extname()
const src = useCache().path({ pkg, type: "src", extname })
rv.push({...install, src })
2022-09-08 23:40:35 +03:00
2022-09-13 18:05:04 +03:00
if (group_it) {
2022-09-08 23:40:35 +03:00
console.log("::endgroup::")
}
2022-08-01 22:43:40 +03:00
}
2022-09-01 20:49:14 +03:00
2022-09-28 18:14:46 +03:00
await set_output("pkgs", rv.map(x => pkgutils.str(x.pkg)))
await set_output("paths", rv.map(x => x.path), '%0A')
2022-09-29 19:07:07 +03:00
await set_output("relative-paths", rv.map(x => x.path.relative({ to: usePrefix() })))
await set_output("srcs", rv.map(x => x.src.relative({ to: usePrefix() })))
interface InstallationPlus extends Installation {
src: Path
}