Skip to content

Commit

Permalink
Mods required to build white-paper
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Jul 7, 2022
1 parent d504eaa commit a0dd762
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 12 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Change how your team works.

tea is a universal virtual‑environment manager:

```
```sh
$ deno
zsh: command not found: deno

Expand All @@ -39,6 +39,18 @@ VERSION=…
```

You need 34 dependencies to compile our white-paper but with tea there’s
nothing to think about:

```sh
$ git clone https://github.com/teaxyz/white-paper
$ cd white-paper
$ make
tea: installing dependencies…
$ open tea.white-paper.pdf
```

> <details><summary><i>What is this sourcery?</i></summary><br>
>
> tea uses a shell hook to insert the precise tooling your project needs into
Expand Down
4 changes: 2 additions & 2 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ args:
- --allow-run
- --allow-read=/opt
- --allow-write=/opt
- --allow-env=VERBOSE,DEBUG,MAGIC,PATH,MANPATH,PKG_CONFIG_PATH,GITHUB_TOKEN
- --allow-env=VERBOSE,DEBUG,MAGIC,PATH,MANPATH,PKG_CONFIG_PATH,GITHUB_TOKEN,CPATH,LIBRARY_PATH,XDG_DATA_DIRS
- --import-map={{ srcroot }}/import-map.json
---*/

Expand All @@ -33,7 +33,7 @@ const pantry = usePantry()
//TODO skip untar, skip download etc. flags

for (const req of args[0].map(parsePackageRequirement)) {
console.debug({hi: req})
console.debug({ req })
const versions = await pantry.getVersions(req)
const version = semver.maxSatisfying(versions, req.constraint)
if (!version) throw "no-version-found"
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/usePantry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ const prefix = new Path("/opt/tea.xyz/var/pantry/projects")
export default function usePantry(): Response {
const getVersions = async (pkg: PackageRequirement) => {
const files = entry(pkg)
let rv: SemVer[]
if (await txt()) return rv!
if (await github()) return rv!.sort()
const foo = (await files.yml()).versions
if (isArray(foo)) {
if (foo.length > 5) throw "use-versions.txt-if-more-than-5-versions"
return foo.map(x => new SemVer(x))
}
let rv: SemVer[]
if (await txt()) return rv!
if (await github()) return rv!.sort()
throw "no-versions"

async function txt(): Promise<boolean> {
Expand Down
15 changes: 14 additions & 1 deletion src/hooks/useShellEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PackageRequirement } from "types"
import useCellar from "hooks/useCellar.ts"

type Env = Record<string, string[]>
export const EnvKeys = ['PATH', 'MANPATH', 'PKG_CONFIG_PATH']
export const EnvKeys = ['PATH', 'MANPATH', 'PKG_CONFIG_PATH', "LIBRARY_PATH", "CPATH", "XDG_DATA_DIRS"]

interface Response {
vars: Env
Expand All @@ -29,6 +29,14 @@ export default async function useShellEnv(requirements: PackageRequirement[]): P
if (!vars[key]) vars[key] = []
vars[key].compactUnshift(installation.path.join(suffix).compact()?.string)
}

// if the tool provides no pkg-config files then fall back on old-school specification methods
if (!vars.PKG_CONFIG_PATH?.chuzzle()) {
vars.LIBRARY_PATH = []
vars.CPATH = []
vars.LIBRARY_PATH.compactUnshift(installation.path.join("lib").compact()?.string)
vars.CPATH.compactUnshift(installation.path.join("include").compact()?.string)
}
}

const defaults: Env = {}
Expand All @@ -54,5 +62,10 @@ function suffixes(key: string) {
return ["share/man"]
case 'PKG_CONFIG_PATH':
return ['share/pkgconfig', 'lib/pkgconfig']
case 'LIBRARY_PATH':
case 'CPATH':
return [] // we handle these specially
case 'XDG_DATA_DIRS':
return ['share']
}
}
2 changes: 1 addition & 1 deletion src/prefab/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function expand(env: Record<string, string[]>) {
let rv = ''
for (let [key, value] of Object.entries(env)) {
if (key == 'PATH') value = value.concat("/usr/bin:/bin:/usr/sbin:/sbin") //FIXME
rv += `export ${key}="${value.join(":")}"\n`
rv += `export ${key}='${value.join(":")}'\n`
}
return rv
}
1 change: 1 addition & 0 deletions src/prefab/hydrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default async function hydrate(reqs: PackageRequirement[]): Promise<Packa
// ^^ adjust our constraint
} else {
stack.unshift(dep)
set[dep.project] = dep.constraint
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type DistributableType = BinaryType[] | 'source-code'
export type Platform = 'darwin' | 'linux' | 'windows'

export function parsePackageRequirement(input: string): PackageRequirement {
const splat = input.split('@')
const splat = input.split('@') //FIXME we do specs with eg. foo^1
switch (splat.length) {
case 1:
return {
Expand All @@ -57,10 +57,9 @@ export function parsePackageRequirement(input: string): PackageRequirement {
/////////////////////////////////////////////////////////////////////// semver
import SemVer, * as semver from "semver"

//TODO I expect this is inefficient AF
//FIXME strictly this isn’t valid since ranges can have holes, but we don’t allow holes
function semver_intersection(a: semver.Range, b: semver.Range): semver.Range {
throw new Error("unimpl")
if (a.raw == b.raw) return a
throw "unimpl" //TODO
}

export { SemVer, semver, semver_intersection }
Expand Down

0 comments on commit a0dd762

Please sign in to comment.