Refactoring

This commit is contained in:
Max Howell 2022-09-21 03:46:24 -04:00
parent 120cb322f4
commit 539cca9158
9 changed files with 32 additions and 45 deletions

View file

@ -14,7 +14,7 @@ args:
import { Installation } from "types"
import { useCellar, useCache, usePrefix, useFlags } from "hooks"
import { run, parse_pkg_requirement } from "utils"
import { run, pkg as pkgutils } from "utils"
import { crypto } from "deno/crypto/mod.ts"
import { encode } from "deno/encoding/hex.ts"
import Path from "path"
@ -30,7 +30,7 @@ if (import.meta.main) {
const bottles: Path[] = []
const checksums: Path[] = []
const artifacts: Path[] = []
for (const pkg of Deno.args.map(parse_pkg_requirement)) {
for (const pkg of Deno.args.map(pkgutils.parse)) {
console.log({ bottling: { pkg } })
const installation = await cellar.resolve(pkg)

View file

@ -15,14 +15,13 @@ args:
import { usePantry } from "hooks"
import build from "./build/build.ts"
import { Package } from "types"
import { parse_pkg_requirement } from "utils"
import { pkg as pkgutils } from "utils"
import { useFlags, usePrefix } from "hooks"
import * as semver from "semver"
useFlags()
const pantry = usePantry()
const dry = Deno.args.map(parse_pkg_requirement)
const dry = Deno.args.map(pkgutils.parse)
const gha = !!Deno.env.get("GITHUB_ACTIONS")
const group_it = gha && dry.length > 1
const rv: Package[] = []
@ -32,16 +31,13 @@ if (usePrefix().string != "/opt") {
throw new Error("builds must be performed in /opt (try TEA_PREFIX=/opt)")
}
for (const pkgrq of dry) {
const versions = await pantry.getVersions(pkgrq)
const version = semver.maxSatisfying(versions, pkgrq.constraint)
if (!version) throw new Error(`no-version-found: ${pkgrq.project}`)
const pkg = { project: pkgrq.project, version }
for (const rq of dry) {
const pkg = await pantry.resolve(rq)
if (group_it) {
console.log("::group::", `${pkg.project}=${pkg.version}`)
console.log("::group::", pkgutils.str(pkg))
} else {
console.log({ building: pkgrq.project })
console.log({ building: pkg.project })
}
await build(pkg)

View file

@ -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, pkg_str } from "utils"
import { run, undent, host, pkg as pkgutils } 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"
@ -50,7 +50,7 @@ export default async function _build(pkg: Package) {
// provided this package doesn't transitively depend on itself (yes this happens)
// clean out the destination prefix first
if (!wet.bootstrap_required.has(pkg.project) && !depends_on_self() && !wet_dep()) {
return await cellar.isInstalled(pkg)
return await cellar.has(pkg)
}
}
}
@ -59,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.map(pkg_str)})
console.error({uninstalled: env.pending.map(pkgutils.str)})
throw new Error("uninstalled")
}

View file

@ -12,7 +12,7 @@ args:
import { PackageRequirement } from "types"
import { usePantry, useFlags } from "hooks"
import { hydrate } from "prefab"
import { parse_pkg_requirement } from "utils"
import { pkg } from "utils"
const pantry = usePantry()
@ -29,10 +29,10 @@ const get_deps = async (pkg: PackageRequirement) => {
}
}
const dry = Deno.args.compact_map(arg => !arg.startsWith('-') && parse_pkg_requirement(arg))
const dry = Deno.args.compact(arg => !arg.startsWith('-') && pkg.parse(arg))
const explicit = new Set(dry.map(x=>x.project))
const wet = await hydrate(dry, get_deps)
const gas = wet.pkgs.compact_map(({project}) => {
const gas = wet.pkgs.compact(({project}) => {
if (Deno.args.includes('-i')) {
return project
} else if (!explicit.has(project)){

View file

@ -14,8 +14,7 @@ args:
import { usePantry, useCache, useCellar, useSourceUnarchiver } from "hooks"
import { Command } from "cliffy/command/mod.ts"
import { print, parse_pkg_requirement } from "utils"
import * as semver from "semver"
import { print, pkg as pkgutils } from "utils"
const { args } = await new Command()
.name("tea-fetch-src")
@ -23,20 +22,13 @@ const { args } = await new Command()
.parse(Deno.args)
const pantry = usePantry()
const req = parse_pkg_requirement(args[0])
const versions = await pantry.getVersions(req)
const version = semver.maxSatisfying(versions, req.constraint)
if (!version) throw "no-version-found"
const pkg = { project: req.project, version }; console.debug(pkg)
const req = pkgutils.parse(args[0])
const pkg = await pantry.resolve(req); console.debug(pkg)
const dstdir = useCellar().mkpath(pkg).join("src")
const dstdir = useCellar().keg(pkg).join("src")
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 download({ pkg, url, type: 'src' })
await useSourceUnarchiver().unarchive({ dstdir, zipfile, stripComponents })
await print(`${dstdir}\n`)

View file

@ -9,7 +9,7 @@ args:
- --import-map={{ srcroot }}/import-map.json
---*/
import { parse_pkg_requirement } from "utils"
import { pkg as pkgutils } from "utils"
import { useCellar, useFlags } from "hooks"
useFlags()
@ -20,8 +20,8 @@ const cellar = useCellar()
const desired_filter = !!Deno.env.get("INVERT")
const rv: string[] = []
for (const pkg of Deno.args.map(parse_pkg_requirement)) {
const isInstalled = !!await cellar.isInstalled(pkg)
for (const pkg of Deno.args.map(pkgutils.parse)) {
const isInstalled = !!await cellar.has(pkg)
if (isInstalled == desired_filter) {
rv.push(pkg.project)
}

View file

@ -16,7 +16,7 @@ args:
// does a full hydration, but only returns ordered, dry packages
import { parse_pkg_requirement } from "utils"
import { pkg } from "utils"
import { usePantry, useFlags } from "hooks"
import { hydrate } from "prefab"
@ -26,7 +26,7 @@ const pantry = usePantry()
const dry = Deno.args.map(project => {
const match = project.match(/projects\/(.*)\/package.yml/)
return match ? match[1] : project
}).map(parse_pkg_requirement)
}).map(pkg.parse)
const wet = await hydrate(dry, async (pkg, dry) => {
const deps = await pantry.getDeps(pkg)

View file

@ -15,7 +15,7 @@ args:
import { PackageRequirement } from "types"
import { usePantry, useCellar, useFlags } from "hooks"
import useShellEnv, { expand } from "hooks/useShellEnv.ts"
import { run, undent, parse_pkg_requirement } from "utils"
import { run, undent, pkg as pkgutils } from "utils"
import { resolve, install, hydrate, link } from "prefab"
import Path from "path"
import * as semver from "semver"
@ -28,7 +28,7 @@ const pkg = await (async () => {
const project = Deno.args[0]
const match = project.match(/projects\/(.+)\/package.yml/)
const parsable = match ? match[1] : project
const pkg = parse_pkg_requirement(parsable)
const pkg = pkgutils.parse(parsable)
const installed = await cellar.resolve(pkg)
return installed.pkg
})()
@ -90,7 +90,7 @@ try {
async function install_if_needed(deps: PackageRequirement[]) {
const needed: PackageRequirement[] = []
for await (const rq of deps) {
if (await cellar.isInstalled(rq)) continue
if (await cellar.has(rq)) continue
needed.push(rq)
}
const wet = await resolve(needed)

View file

@ -11,7 +11,7 @@ args:
---*/
import { S3 } from "s3"
import { parse_pkg } from "utils"
import { panic, pkg as pkgutils } from "utils"
import { useCache, useFlags } from "hooks"
import { Package } from "types"
import SemVer, * as semver from "semver"
@ -28,10 +28,9 @@ const s3 = new S3({
})
const bucket = s3.getBucket(Deno.env.get("AWS_S3_BUCKET")!)
const encode = (() => { const e = new TextEncoder(); return e.encode.bind(e) })()
const pkgs = args_get("pkgs").map(parse_pkg)
const pkgs = args_get("pkgs").map(pkgutils.parse).map(x => "version" in x ? x : panic<Package>())
const bottles = args_get("bottles")
const checksums = args_get("checksums")
@ -80,9 +79,9 @@ async function get_versions(pkg: Package): Promise<SemVer[]> {
//NOTE if this is a new package then some empty results is expected
const got = rsp
?.contents
?.compact_map(x => x.key)
?.compact(x => x.key)
.map(x => basename(x))
.compact_map(semver.coerce) //FIXME coerce is too loose
.compact(semver.coerce) //FIXME coerce is too loose
?? []
// have to add pkg.version as put and get are not atomic