plumbing/porcelain for build.ts

This commit is contained in:
Max Howell 2022-11-07 11:43:48 -05:00
parent 996ece5c50
commit 62c838d2e1
No known key found for this signature in database
GPG key ID: 741BB84EF5BB9EEC
10 changed files with 83 additions and 60 deletions

View file

@ -76,7 +76,7 @@ jobs:
- run: cli/scripts/install.ts ${{ steps.sorted.outputs.pre-install }}
# running out of /opt because only pantry.core has these scripts
- run: /opt/tea.xyz/var/pantry/scripts/build.ts ${{ steps.sorted.outputs.pkgs }}
- run: /opt/tea.xyz/var/pantry/scripts/build.plumbing.ts ${{ steps.sorted.outputs.pkgs }}
id: build
env:
# GITHUB_TOKEN doesn't have private access to teaxyz/cli.

View file

@ -21,4 +21,4 @@ test:
OUT=$(echo "$INPUT" | ./a.out | ./a.out -d)
test "$OUT" = "$INPUT"
env:
INPUT: Hello, World!
INPUT: Hello, World!

View file

@ -14,8 +14,6 @@ args:
- --allow-read
- --allow-write
- --import-map={{ srcroot }}/import-map.json
env:
TEA_PANTRY_PATH: "{{srcroot}}"
--- */
import { Installation } from "types"

61
scripts/build.plumbing.ts Executable file
View file

@ -0,0 +1,61 @@
#!/usr/bin/env -S tea -E
/*---
dependencies:
gnu.org/tar: 1
tukaani.org/xz: 5
sourceware.org/bzip2: 1
args:
- deno
- run
- --allow-net
- --allow-run
- --allow-read
- --allow-write={{tea.prefix}}
- --allow-env
- --import-map={{ srcroot }}/import-map.json
---*/
import { usePantry } from "hooks"
import { Installation } from "types"
import { pkg as pkgutils } from "utils"
import { useFlags, usePrefix } from "hooks"
import { set_output } from "./utils/gha.ts"
import build, { BuildResult } from "./build/build.ts"
import * as ARGV from "./utils/args.ts"
import Path from "path"
useFlags()
const pantry = usePantry()
const dry = await ARGV.toArray(ARGV.pkgs())
const gha = !!Deno.env.get("GITHUB_ACTIONS")
const group_it = gha && dry.length > 1
const rv: BuildResult[] = []
for (const rq of dry) {
const pkg = await pantry.resolve(rq)
if (group_it) {
console.log("::group::", pkgutils.str(pkg))
} else {
console.log({ building: pkg.project })
}
rv.push(await build(pkg))
if (group_it) {
console.log("::endgroup::")
}
}
const to = usePrefix()
await set_output("pkgs", rv.map(x => pkgutils.str(x.installation.pkg)))
await set_output("paths", rv.map(x => x.installation.path), '%0A')
await set_output("relative-paths", rv.map(x => x.installation.path.relative({ to })))
await set_output("srcs", rv.map(x => x.src?.relative({ to }) ?? "~"))
await set_output("srcs-relative-paths", rv.compact(x => x.src?.relative({ to })))
interface InstallationPlus extends Installation {
src: Path
}

View file

@ -1,10 +1,6 @@
#!/usr/bin/env -S tea -E
/*---
dependencies:
gnu.org/tar: 1
tukaani.org/xz: 5
sourceware.org/bzip2: 1
args:
- deno
- run
@ -13,51 +9,36 @@ args:
- --allow-read
- --allow-write={{tea.prefix}}
- --allow-env
- --unstable
- --import-map={{ srcroot }}/import-map.json
env:
TEA_PANTRY_PATH: "{{srcroot}}"
---*/
import { usePantry } from "hooks"
import { Installation } from "types"
import { pkg as pkgutils } from "utils"
import { useFlags, usePrefix } from "hooks"
import { set_output } from "./utils/gha.ts"
import build, { BuildResult } from "./build/build.ts"
import { usePantry, useFlags, useCellar, useInventory } from "hooks"
import { hydrate, install, link } from "prefab"
import * as ARGV from "./utils/args.ts"
import Path from "path"
import { panic } from "utils/error.ts"
import build from "./build/build.ts"
useFlags()
const pantry = usePantry()
const cellar = useCellar()
const inventory = useInventory()
const dry = await ARGV.toArray(ARGV.pkgs())
const gha = !!Deno.env.get("GITHUB_ACTIONS")
const group_it = gha && dry.length > 1
const rv: BuildResult[] = []
const wet = await hydrate(dry, async (pkg, dry) => {
const deps = await pantry.getDeps(pkg)
return dry ? [...deps.build, ...deps.runtime] : deps.runtime
})
for (const pkg of wet.wet) {
if (!await cellar.has(pkg)) {
const version = await inventory.select(pkg) ?? panic()
await install({ project: pkg.project, version })
}
}
for (const rq of dry) {
const pkg = await pantry.resolve(rq)
if (group_it) {
console.log("::group::", pkgutils.str(pkg))
} else {
console.log({ building: pkg.project })
}
rv.push(await build(pkg))
if (group_it) {
console.log("::endgroup::")
}
}
const to = usePrefix()
await set_output("pkgs", rv.map(x => pkgutils.str(x.installation.pkg)))
await set_output("paths", rv.map(x => x.installation.path), '%0A')
await set_output("relative-paths", rv.map(x => x.installation.path.relative({ to })))
await set_output("srcs", rv.map(x => x.src?.relative({ to }) ?? "~"))
await set_output("srcs-relative-paths", rv.compact(x => x.src?.relative({ to })))
interface InstallationPlus extends Installation {
src: Path
await build(pkg)
await link(pkg)
}

View file

@ -7,8 +7,6 @@ args:
- --allow-read
- --allow-env
- --import-map={{ srcroot }}/import-map.json
env:
TEA_PANTRY_PATH: "{{srcroot}}"
---*/
import { PackageRequirement } from "types"

View file

@ -10,8 +10,6 @@ args:
- --allow-write={{ tea.prefix }}
- --allow-env
- --import-map={{ srcroot }}/import-map.json
env:
TEA_PANTRY_PATH: "{{srcroot}}"
---*/
//TODO verify the sha

View file

@ -7,8 +7,6 @@ args:
- --allow-read
- --allow-env
- --import-map={{ srcroot }}/import-map.json
env:
TEA_PANTRY_PATH: "{{srcroot}}"
---*/
// sorts input for building

View file

@ -11,8 +11,6 @@ args:
- --allow-env
- --unstable
- --import-map={{ srcroot }}/import-map.json
env:
TEA_PANTRY_PATH: "{{srcroot}}"
---*/
import { Installation, Package, PackageRequirement } from "types"

View file

@ -1,9 +0,0 @@
export function overlay_this_pantry() {
const self = new URL(import.meta.url).path().parent().parent().parent().join("projects")
// if unset just assume the user wants this
// this is magic in a bad way, but for now is what we're doing
if (!!Deno.env.get("TEA_PANTRY_PATH")) {
Deno.env.set("TEA_PANTRY_PATH", self.string)
}
}