Skip to content

Commit 87a06e6

Browse files
committed
Improvements
1 parent 1ad9689 commit 87a06e6

File tree

3 files changed

+51
-63
lines changed

3 files changed

+51
-63
lines changed

src/options.nim

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ Copyright © 2018-2025 Firas Khana"""
7979
cleanBootstrap()
8080
prepareBootstrap()
8181

82-
buildPackages(
83-
parsePackage("toolchain").run.split(), resolve = false, stage = $toolchain
84-
)
82+
let stage1 = parsePackage("toolchain").run.split()
83+
buildPackages(stage1, resolve = false, stage = toolchain)
8584

8685
echo ""
8786
echo "stage 1 (toolchain) complete"
@@ -91,17 +90,17 @@ Copyright © 2018-2025 Firas Khana"""
9190
setEnvCross()
9291
prepareCross()
9392

94-
buildPackages(
95-
parsePackage("cross").run.split(), resolve = false, stage = $cross
96-
)
93+
let stage2 = parsePackage("cross").run.split()
94+
buildPackages(stage2, resolve = false, stage = cross)
9795

9896
echo ""
9997
echo "stage 2 (cross) complete"
10098
of "3", "stage3", "native":
10199
setEnvArch()
102100
setEnvNative()
103101

104-
buildPackages(parsePackage("native").run.split(), resolve = false)
102+
let stage3 = parsePackage("native").run.split()
103+
buildPackages(stage3, resolve = false)
105104

106105
echo ""
107106
echo "stage 3 (native) complete"

src/packages.nim

Lines changed: 44 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import
1414
toml_serialization
1515

1616
type Package = object
17-
nom, ver, url, sum, bld, run*, opt = "nil"
17+
ver, url, sum, bld, run*, opt = "nil"
1818

1919
proc cleanPackages*() =
2020
removeDir(pathTmp)
@@ -43,15 +43,15 @@ proc fetchPackages(packages: openArray[string]) =
4343
for idx, nom in packages:
4444
let package = parsePackage(nom)
4545

46-
printContent(idx, package.nom, package.ver, "fetch")
46+
printContent(idx, nom, package.ver, "fetch")
4747

4848
# Skip virtual packages
4949
if package.url == "nil":
5050
continue
5151

5252
let
53-
src = getEnv("SRCD") / package.nom
54-
tmp = getEnv("TMPD") / package.nom
53+
src = pathSrcCache / nom
54+
tmp = getEnv("TMPD") / nom
5555

5656
if package.sum == "nil":
5757
if not dirExists(src):
@@ -73,7 +73,7 @@ proc fetchPackages(packages: openArray[string]) =
7373
createDir(tmp)
7474
discard extractTar(archive, tmp)
7575
else:
76-
abort(&"""{"sum":8}{package:24}{package.ver:24}""")
76+
abort(&"""{"sum":8}{nom:24}{package.ver:24}""")
7777

7878
proc resolveDeps(
7979
nom: string,
@@ -88,13 +88,13 @@ proc resolveDeps(
8888
package = parsePackage(nom)
8989
dep = if run: package.run else: package.bld
9090

91-
deps[package.nom] =
91+
deps[nom] =
9292
if dep == "nil":
9393
@[]
9494
else:
9595
dep.split()
9696

97-
for nom in deps[package.nom]:
97+
for nom in deps[nom]:
9898
resolveDeps(nom, cluster, deps, run)
9999

100100
cluster &= nom
@@ -121,22 +121,18 @@ proc installPackage(
121121
skel = parsePackage("skel").run
122122

123123
discard extractTar(
124-
pkgCache / package.nom / package.nom &
124+
pkgCache / nom / nom &
125125
(if package.url == "nil": ""
126126
else: '-' & package.ver & ".tar.zst"),
127127
fs,
128128
)
129129

130-
createDir(pkgLib / package.nom)
131-
copyFileWithPermissions(
132-
pkgCache / package.nom / "contents", pkgLib / package.nom / "contents"
133-
)
134-
copyFileWithPermissions(
135-
pkgCache / package.nom / "info", pkgLib / package.nom / "info"
136-
)
130+
createDir(pkgLib / nom)
131+
copyFileWithPermissions(pkgCache / nom / "contents", pkgLib / nom / "contents")
132+
copyFileWithPermissions(pkgCache / nom / "info", pkgLib / nom / "info")
137133

138-
if implicit and package.nom notin skel:
139-
writeFile(pkgLib / package.nom / "implicit", "")
134+
if implicit and nom notin skel:
135+
writeFile(pkgLib / nom / "implicit", "")
140136

141137
if package.run.len() > 0:
142138
for dep in package.run.split():
@@ -150,44 +146,44 @@ proc buildPackages*(
150146
pkgCache = pathPkgCache,
151147
pkgLib = pathLocalLib,
152148
resolve = true,
153-
stage = $native,
149+
stage = native,
154150
implicit = false,
155151
) =
156-
let cluster = sortPackages(packages, false)
152+
let sorted = sortPackages(packages, false)
157153

158-
fetchPackages(cluster)
154+
fetchPackages(sorted)
159155

160156
echo ""
161157

162158
printHeader()
163159

164-
for idx, nom in (if resolve: cluster else: packages.toSeq()):
160+
for idx, nom in (if resolve: sorted else: packages.toSeq()):
165161
let
166162
package = parsePackage(nom)
167163
archive =
168-
$pkgCache / package.nom / package.nom &
164+
pkgCache / nom / nom &
169165
(if package.url == "nil": ""
170166
else: '-' & package.ver & ".tar.zst")
171-
tmp = getEnv("TMPD") / package.nom
167+
tmp = getEnv("TMPD") / nom
172168

173-
printContent(idx, package.nom, package.ver, "build")
169+
printContent(idx, nom, package.ver, "build")
174170

175-
if stage == $native:
171+
if stage == native:
176172
# Skip installed packages
177-
if dirExists(pkgLib / package.nom):
173+
if dirExists(pkgLib / nom):
178174
continue
179175

180176
# Skip package if archive exists
181177
if fileExists(archive):
182178
# Install build-time dependency (if not installed)
183179
if implicit:
184-
installPackage(package.nom, implicit = true)
180+
installPackage(nom, implicit = true)
185181
continue
186182

187-
putEnv("DSTD", pkgCache / package.nom / "dst")
183+
putEnv("DSTD", pkgCache / nom / "dst")
188184
createDir(getEnv("DSTD"))
189185

190-
if stage != $toolchain:
186+
if stage != toolchain:
191187
setEnvFlags()
192188

193189
if "no-lto" in package.opt:
@@ -203,7 +199,7 @@ proc buildPackages*(
203199

204200
let shell = execCmdEx(
205201
&"""sh -efu -c '
206-
nom={package.nom} ver={package.ver} . {pathCoreRepo / package.nom / (if stage == $native: "build" else: "build" & '-' & stage)}
202+
nom={nom} ver={package.ver} . {pathCoreRepo / nom / (if stage == native: "build" else: "build" & '-' & $stage)}
207203
208204
for i in prepare configure build; do
209205
if command -v $i {shellRedirect}; then
@@ -216,14 +212,13 @@ proc buildPackages*(
216212
)
217213

218214
writeFile(
219-
getEnv("LOGD") / package.nom & (if stage == $native: "" else: stage),
220-
shell.output.strip(),
215+
getEnv("LOGD") / nom & (if stage == native: "" else: $stage), shell.output.strip()
221216
)
222217

223218
if shell.exitCode != QuitSuccess:
224-
abort(&"{shell.exitCode:<8}{package:24}{package.ver:24}")
219+
abort(&"{shell.exitCode:<8}{nom:24}{package.ver:24}")
225220

226-
if stage == $native:
221+
if stage == native:
227222
let
228223
dst = getEnv("DSTD")
229224
status = createTarZst(archive, dst)
@@ -232,15 +227,13 @@ proc buildPackages*(
232227
# if "empty" notin package.opt:
233228

234229
if status == QuitSuccess:
235-
genContents(dst, $pkgCache / package.nom / "contents")
230+
genContents(dst, $pkgCache / nom / "contents")
236231
removeDir(dst)
237232

238-
copyFileWithPermissions(
239-
pathCoreRepo / package.nom / "info", pkgCache / package.nom / "info"
240-
)
233+
copyFileWithPermissions(pathCoreRepo / nom / "info", pkgCache / nom / "info")
241234

242235
if "bootstrap" in package.opt or implicit:
243-
installPackage(package.nom, implicit = true)
236+
installPackage(nom, implicit = true)
244237

245238
proc installPackages*(
246239
packages: openArray[string],
@@ -257,12 +250,12 @@ proc installPackages*(
257250
let
258251
package = parsePackage(nom)
259252
archive =
260-
pkgCache / package.nom / package.nom &
253+
pkgCache / nom / nom &
261254
(if package.url == "nil": ""
262255
else: '-' & package.ver & ".tar.zst")
263256

264257
if not fileExists(archive):
265-
notBuilt &= package.nom
258+
notBuilt &= nom
266259

267260
if notBuilt.len() > 0:
268261
buildPackages(notBuilt, implicit = true)
@@ -274,32 +267,28 @@ proc installPackages*(
274267
for idx, nom in cluster:
275268
let package = parsePackage(nom)
276269

277-
printContent(idx, package.nom, package.ver, "install")
270+
printContent(idx, nom, package.ver, "install")
278271

279272
# Skip installed packages
280-
if dirExists(pkgLib / package.nom):
281-
if package.nom notin packages and package.nom notin skel:
282-
writeFile(pkgLib / package.nom / "implicit", "")
273+
if dirExists(pkgLib / nom):
274+
if nom notin packages and nom notin skel:
275+
writeFile(pkgLib / nom / "implicit", "")
283276

284277
for nom in packages:
285278
removeFile(pkgLib / nom / "implicit")
286279

287280
continue
288281

289282
discard extractTar(
290-
pkgCache / package.nom / package.nom &
283+
pkgCache / nom / nom &
291284
(if package.url == "nil": ""
292285
else: '-' & package.ver & ".tar.zst"),
293286
fs,
294287
)
295288

296-
createDir(pkgLib / package.nom)
297-
copyFileWithPermissions(
298-
pkgCache / package.nom / "contents", pkgLib / package.nom / "contents"
299-
)
300-
copyFileWithPermissions(
301-
pkgCache / package.nom / "info", pkgLib / package.nom / "info"
302-
)
289+
createDir(pkgLib / nom)
290+
copyFileWithPermissions(pkgCache / nom / "contents", pkgLib / nom / "contents")
291+
copyFileWithPermissions(pkgCache / nom / "info", pkgLib / nom / "info")
303292

304293
if package.run.len() > 0:
305294
for dep in package.run.split():
@@ -312,7 +301,7 @@ proc showInfo*(packages: openArray[string]) =
312301
let package = parsePackage(nom)
313302

314303
echo &"""
315-
nom :: {package}
304+
nom :: {nom}
316305
ver :: {package.ver}
317306
url :: {package.url}
318307
sum :: {package.sum}
@@ -328,7 +317,7 @@ proc listContents*(packages: openArray[string]) =
328317
for nom in packages.deduplicate():
329318
let package = parsePackage(nom)
330319

331-
for line in lines(pathLocalLib / package.nom / "contents"):
320+
for line in lines(pathLocalLib / nom / "contents"):
332321
echo &"/{line}"
333322

334323
proc searchPackages*(pattern: openArray[string]) =

src/tools.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ proc createTarZst*(ar, dir: string): int =
1212
execCmd(&"tar --use-compress-program 'zstd -3 -T0' -cP -f {ar} -C {dir} .")
1313

1414
proc downloadFile*(dir, url: string): int =
15-
execCmd(&"curl -fL --output-dir {dir} -JOs {url}")
15+
execCmd(&"curl -fL --output-dir {dir} -Os {url}")
1616

1717
proc exit*(msg = "", status = QuitSuccess) =
1818
removeFile(pathTmpLock)

0 commit comments

Comments
 (0)