nandi/nimstaticpublic Fork 0
5feb05094be9eb20a8a0588b44117d22c7dc3cac
Commits
Clone
git clone https://git.rickub.com/nandi/nimstatic.git
git clone ssh://git@rickub.com/nandi/nimstatic.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

sysroot.nim · 48 lines · 1.7 KBNim Blame HistoryRaw
muslkit: musl static libraries from Alpine, without Alpine 5feb050 nandi 21h ago1## The sysroot: a plain directory tree of unpacked Alpine packages, plus a
2## manifest of what was installed so `list` and re-runs are cheap.
3
4import std/[algorithm, os, sequtils, strutils]
5import ./index
6
7const manifestPath* = ".muslkit/installed.tsv"
8
9type Installed* = object
10 name*, version*, repo*: string
11
12proc manifestFile*(sysroot: string): string = sysroot / manifestPath
13
14proc readManifest*(sysroot: string): seq[Installed] =
15 let path = manifestFile(sysroot)
16 if not fileExists(path): return
17 for line in readFile(path).splitLines:
18 if line.len == 0 or line.startsWith("#"): continue
19 let f = line.split('\t')
20 if f.len >= 3:
21 result.add Installed(name: f[0], version: f[1], repo: f[2])
22
23proc writeManifest*(sysroot: string, entries: seq[Installed]) =
24 createDir manifestFile(sysroot).parentDir
25 var lines = @["# name\tversion\trepo — written by muslkit"]
26 for e in entries.sortedByIt(it.name):
27 lines.add e.name & "\t" & e.version & "\t" & e.repo
28 writeFile(manifestFile(sysroot), lines.join("\n") & "\n")
29
30proc record*(sysroot: string, pkgs: openArray[Pkg]) =
31 ## Merge freshly installed packages into the manifest, newest version winning.
32 var entries = readManifest(sysroot)
33 for pkg in pkgs:
34 entries.keepItIf(it.name != pkg.name)
35 entries.add Installed(name: pkg.name, version: pkg.version, repo: pkg.repo)
36 writeManifest(sysroot, entries)
37
38proc installed*(sysroot, name: string): bool =
39 readManifest(sysroot).anyIt(it.name == name)
40
41proc staticLibs*(sysroot: string): seq[string] =
42 ## Every .a in the sysroot, as absolute paths.
43 for dir in ["usr/lib", "lib", "usr/lib64"]:
44 let d = sysroot / dir
45 if dirExists(d):
46 for path in walkFiles(d / "*.a"):
47 result.add path
48 result.sort()