From 915e9f1d82d233abe1c992d84519d858a20f9a41 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Thu, 1 Sep 2022 13:49:14 -0400 Subject: [PATCH] +wget (#111) --- .github/workflows/build.yml | 5 ++- projects/gnu.org/wget/package.yml | 29 +++++++++++++++ projects/openssl.org/package.yml | 20 ++++++---- scripts/_lib.ts | 33 ----------------- scripts/build-all.sh | 14 ------- scripts/build-deps.ts | 46 ----------------------- scripts/build.ts | 61 +++++++++---------------------- scripts/install.ts | 35 ++++++++++++++++++ scripts/sort.ts | 20 +++++++--- scripts/test.ts | 3 +- 10 files changed, 112 insertions(+), 154 deletions(-) create mode 100644 projects/gnu.org/wget/package.yml delete mode 100644 scripts/_lib.ts delete mode 100755 scripts/build-all.sh delete mode 100755 scripts/build-deps.ts create mode 100755 scripts/install.ts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a88798e0..dce9a8c6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -70,8 +70,9 @@ jobs: id: sorted run: ./scripts/sort.ts ${{ inputs.projects }} - - name: Build - run: | + - run: ./scripts/install.ts ${{ steps.sorted.outputs.pre-install }} + + - run: | ./scripts/build.ts ${{ steps.sorted.outputs.pkgs }} id: build env: diff --git a/projects/gnu.org/wget/package.yml b/projects/gnu.org/wget/package.yml new file mode 100644 index 00000000..d01d2972 --- /dev/null +++ b/projects/gnu.org/wget/package.yml @@ -0,0 +1,29 @@ +distributable: + url: https://ftp.gnu.org/gnu/wget/wget-{{version}}.tar.gz + strip-components: 1 + +versions: + - 1.21.3 + +dependencies: + openssl.org: ^1.1 + +build: + dependencies: + tea.xyz/gx/cc: c99 + tea.xyz/gx/make: '*' + freedesktop.org/pkg-config: ^0.29 + script: | + ./configure $ARGS + make --jobs {{hw.concurrency}} install + env: + ARGS: + - --prefix={{prefix}} + - --disable-pcre + - --disable-pcre2 + - --without-libps1 + - --without-included-regex + - --with-ssl=openssl + +test: + wget tea.xyz diff --git a/projects/openssl.org/package.yml b/projects/openssl.org/package.yml index d10e4cd1..7e903a90 100644 --- a/projects/openssl.org/package.yml +++ b/projects/openssl.org/package.yml @@ -17,17 +17,21 @@ build: tea.xyz/gx/cc: c99 tea.xyz/gx/make: '*' perl.org: 5 + curl.se: '*' script: | - case "X{{ hw.target }}" in - "Xaarch64-apple-darwin") ARCH="darwin64-arm64-cc";; - "Xx86_64-apple-darwin") ARCH="darwin64-x86_64-cc";; - "Xx86_64-unknown-linux-gnu") ARCH="linux-x86_64";; - "Xaarch64-unknown-linux-gnu") ARCH="linux-aarch64";; - esac - ./Configure --prefix={{ prefix }} $ARCH no-tests make --jobs {{ hw.concurrency }} - make install + make install_sw # `_sw` avoids installing docs + + #TODO needs to be a curl.se/pkg that gets updates + mkdir -p "$CERTDIR" + curl https://curl.se/ca/cacert-2022-07-19.pem -o "$CERTDIR"/cert.pem + env: + CERTDIR: ${{prefix}}/ssl + darwin/aarch64: {ARCH: 'darwin64-arm64-cc'} + darwin/x86-64: {ARCH: 'darwin64-x86_64-cc'} + linux/aarch64: {ARCH: 'linux-aarch64'} + linux/x86-64: {ARCH: 'linux-x86_64'} test: script: | diff --git a/scripts/_lib.ts b/scripts/_lib.ts deleted file mode 100644 index d406550e..00000000 --- a/scripts/_lib.ts +++ /dev/null @@ -1,33 +0,0 @@ -import usePantry from "hooks/usePantry.ts" -import { PackageRequirement } from "types" - -/// this function is poorly named and does too many things -/// sorry. Refactor is desired. - -export function get_build_deps(dry: Set) { - const pantry = usePantry() - - return async (pkg: PackageRequirement) => { - const deps = await pantry.getDeps(pkg) - if (dry.has(pkg.project)) { - // we hydrate the runtime deps of any build deps since if - // any of `dry` is a runtime dep of any build dep (obv. from another) - // pkg in the set we are building then it needs to be sorted first - const rv = [...deps.runtime, ...deps.build] - - // if we are building a test-dep then we need it to be built before we - // build `pkg` or we will not be able to test it before building the whole - // graph - for (const test_dep of deps.test) { - if (dry.has(test_dep.project)) { - rv.push(test_dep) - } - } - - return rv - - } else { - return deps.runtime - } - } -} diff --git a/scripts/build-all.sh b/scripts/build-all.sh deleted file mode 100755 index 2b9aa120..00000000 --- a/scripts/build-all.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -set -eo pipefail - -d="$(cd "$(dirname "$0")" && pwd)" -all=$($d/ls.ts | xargs $d/sort.ts) - -for x in $all -do - $d/build.ts $x - $d/test.ts $x --magic #FIXME be precise -done - -# $d/bottle.ts $all diff --git a/scripts/build-deps.ts b/scripts/build-deps.ts deleted file mode 100755 index 401387c5..00000000 --- a/scripts/build-deps.ts +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env -S tea -E - -/// deps to build the provided including building all its deps too - -/*--- -args: - - deno - - run - - --allow-net - - --allow-run - - --allow-read=/opt,/Library/Developer/CommandLineTools - - --allow-write=/opt - - --allow-env - - --import-map={{ srcroot }}/import-map.json ----*/ - -import { parsePackageRequirement } from "types" -import hydrate from "prefab/hydrate-topological.ts" -import useFlags from "hooks/useFlags.ts" -import { PackageRequirement } from "types" -import usePantry from "hooks/usePantry.ts" - -const flags = useFlags() -const pantry = usePantry() - -const dry = Deno.args.map(project => { - const match = project.match(/projects\/(.*)\/package.yml/) - return match ? match[1] : project -}).map(parsePackageRequirement) - -const wet = await hydrate(dry, get) -const gas = wet.map(x => x.project) - -if (Deno.env.get("GITHUB_ACTIONS")) { - console.log(`::set-output name=pkgs::${gas.join(" ")}`) -} else if (flags.json) { - console.log(gas) -} else { - console.log(gas.join("\n")) -} - - -async function get(pkg: PackageRequirement) { - const { build, runtime } = await pantry.getDeps(pkg) - return [...build, ...runtime] -} \ No newline at end of file diff --git a/scripts/build.ts b/scripts/build.ts index 26296548..b7786fe2 100755 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -17,13 +17,8 @@ import useCellar from "hooks/useCellar.ts" import usePantry from "hooks/usePantry.ts" import useCache from "hooks/useCache.ts" import { lvl1 as link } from "prefab/link.ts" -import install from "prefab/install.ts" import build from "prefab/build.ts" -import { semver, PackageRequirement, Package } from "types" -import { parsePackageRequirement } from "types" -import hydrate from "prefab/hydrate.ts" -import resolve from "prefab/resolve.ts" -import { get_build_deps } from "./_lib.ts" +import { Package, parsePackageRequirement, semver } from "types" import useFlags from "hooks/useFlags.ts" import usePlatform from "hooks/usePlatform.ts" @@ -37,51 +32,23 @@ const dry = Deno.args.map(project => { return match ? match[1] : project }).map(parsePackageRequirement) -const explicit_deps = new Set(dry.map(({ project }) => project)) - -const wet = await hydrate(dry, get_build_deps(explicit_deps)) -const gas = async () => { - const rv: PackageRequirement[] = [] - for (const pkg of wet) { - if (await cellar.isInstalled(pkg)) continue - if (explicit_deps.has(pkg.project)) continue - rv.push(pkg) - } - return rv -} -const plasma = await resolve(await gas()) - -for await (const pkg of plasma) { - console.log({ installing: pkg.project }) - const installation = install(pkg) - await link(installation) -} - const rv: Package[] = [] -for await (const pkg of dry) { - console.log({ building: pkg.project }) - - const versions = await pantry.getVersions(pkg) - const version = semver.maxSatisfying(versions, pkg.constraint) +for (const pkgrq of dry) { + const versions = await pantry.getVersions(pkgrq) + const version = semver.maxSatisfying(versions, pkgrq.constraint) if (!version) throw "no-version-found" - await b({ project: pkg.project, version }) + const pkg = { project: pkgrq.project, version } - rv.push({ project: pkg.project, version }) -} + if (Deno.env.get("SKIP") && await cellar.isInstalled(pkg)) { + console.log({ skipping: pkg.project }) + continue + } -const built_pkgs = rv.map(({ project, version }) => `${project}@${version}`).join(" ") -const txt = `::set-output name=pkgs::${built_pkgs}\n` -await Deno.stdout.write(new TextEncoder().encode(txt)) - -//end - - - -async function b(pkg: Package) { + console.log({ building: pkgrq.project }) // Get the source const prebuild = async () => { - const dstdir = useCellar().mkpath(pkg).join("src") + const dstdir = cellar.mkpath(pkg).join("src") const { url, stripComponents } = await pantry.getDistributable(pkg) const { download } = useCache() const zip = await download({ pkg, url, type: 'src' }) @@ -101,4 +68,10 @@ async function b(pkg: Package) { // Build and link const path = await build({ pkg, deps, prebuild, env }) await link({ path, pkg }) + + rv.push(pkg) } + +const built_pkgs = rv.map(({ project, version }) => `${project}@${version}`).join(" ") +const txt = `::set-output name=pkgs::${built_pkgs}\n` +await Deno.stdout.write(new TextEncoder().encode(txt)) diff --git a/scripts/install.ts b/scripts/install.ts new file mode 100755 index 00000000..711c8b29 --- /dev/null +++ b/scripts/install.ts @@ -0,0 +1,35 @@ +#!/usr/bin/env -S tea -E + +// returns all pantry entries as `[{ name, path }]` + +/*--- +args: + - deno + - run + - --allow-env + - --allow-read + - --allow-write + - --import-map={{ srcroot }}/import-map.json + - --allow-net + - --allow-run +---*/ + +import { lvl1 as link } from "prefab/link.ts" +import install from "prefab/install.ts" +import { parsePackageRequirement } from "types" +import resolve from "prefab/resolve.ts" +import useFlags from "hooks/useFlags.ts" + +useFlags() + +const pkgs = Deno.args.map(project => { + const match = project.match(/projects\/(.*)\/package.yml/) + return match ? match[1] : project +}).map(parsePackageRequirement) + +// resolve and install precise versions that are available in available inventories +for await (const pkg of await resolve(pkgs)) { + console.log({ installing: pkg.project }) + const installation = install(pkg) + await link(installation) +} diff --git a/scripts/sort.ts b/scripts/sort.ts index 8ba55617..f7112aef 100755 --- a/scripts/sort.ts +++ b/scripts/sort.ts @@ -12,25 +12,33 @@ args: - --import-map={{ srcroot }}/import-map.json ---*/ +// sorts input for building +// does a full hydration, but only returns ordered, dry packages + + import { parsePackageRequirement } from "types" -import hydrate from "prefab/hydrate-topological.ts" -import { get_build_deps } from "./_lib.ts" +import hydrate from "prefab/hydrate.ts" import useFlags from "hooks/useFlags.ts" +import usePantry from "../src/hooks/usePantry.ts" const flags = useFlags() +const pantry = usePantry() const dry = Deno.args.map(project => { const match = project.match(/projects\/(.*)\/package.yml/) return match ? match[1] : project }).map(parsePackageRequirement) -const set = new Set(dry.map(x => x.project)) -const wet = await hydrate(dry, get_build_deps(set)) -const gas = wet.map(x => x.project) - .filter(x => set.has(x)) // we're only sorting `dry` so reject the rest +const wet = await hydrate(dry, async (pkg, dry) => { + const deps = await pantry.getDeps(pkg) + return dry ? [...deps.build, ...deps.runtime] : deps.runtime +}) +const gas = wet.dry.map(x => x.project) if (Deno.env.get("GITHUB_ACTIONS")) { + const pre = wet.wet.map(x=>x.project) console.log(`::set-output name=pkgs::${gas.join(" ")}`) + console.log(`::set-output name=pre-install::${pre.join(" ")}`) } else if (flags.json) { console.log(gas) } else { diff --git a/scripts/test.ts b/scripts/test.ts index 0a2c54f1..d3b211f1 100755 --- a/scripts/test.ts +++ b/scripts/test.ts @@ -94,7 +94,8 @@ async function get_deps() { const rv: PackageRequirement[] = [] attempt(yml.dependencies) attempt(yml.test.dependencies) - return await hydrate(rv) + const { pkgs } = await hydrate(rv, pkg => pantry.getDeps(pkg).then(x=>x.runtime)) + return pkgs function attempt(obj: PlainObject) { if (isPlainObject(obj))