Compare commits

...

3 Commits

Author SHA1 Message Date
Ehmry - 222aea9e79 Accept short git revs
Short revisions are fine, SHA1 is broken anyway.
2023-10-31 15:36:57 +00:00
Ehmry - a904a4630c Take package path as an optional argument 2023-10-31 15:36:41 +00:00
Ehmry - a7259071b3 Update lockfile 2023-10-31 15:36:17 +00:00
3 changed files with 16 additions and 11 deletions

View File

@ -1 +1 @@
{"depends":[{"method":"fetchzip","packages":["npeg"],"path":"/nix/store/ffkxmjmigfs7zhhiiqm0iw2c34smyciy-source","ref":"1.2.1","rev":"26d62fdc40feb84c6533956dc11d5ee9ea9b6c09","sha256":"0xpzifjkfp49w76qmaylan8q181bs45anmp46l4bwr3lkrr7bpwh","srcDir":"src","url":"https://github.com/zevv/npeg/archive/26d62fdc40feb84c6533956dc11d5ee9ea9b6c09.tar.gz"},{"method":"fetchzip","packages":["preserves"],"path":"/nix/store/nrxd0z8mxmdphw49c6p4n9lmmq0iq5pq-source","ref":"20231019","rev":"a2dc5becc0596d52ab205d869b7c167c0b562fb4","sha256":"09jygr7ynzh6vp2p54dgq2qz651d3lgvypkjwjp74zzp3jgwz7g5","srcDir":"src","url":"https://git.syndicate-lang.org/ehmry/preserves-nim/archive/a2dc5becc0596d52ab205d869b7c167c0b562fb4.tar.gz"}]}
{"depends":[{"method":"fetchzip","packages":["npeg"],"path":"/nix/store/ffkxmjmigfs7zhhiiqm0iw2c34smyciy-source","ref":"1.2.1","rev":"26d62fdc40feb84c6533956dc11d5ee9ea9b6c09","sha256":"0xpzifjkfp49w76qmaylan8q181bs45anmp46l4bwr3lkrr7bpwh","srcDir":"src","url":"https://github.com/zevv/npeg/archive/26d62fdc40feb84c6533956dc11d5ee9ea9b6c09.tar.gz"},{"method":"fetchzip","packages":["preserves"],"path":"/nix/store/nrcpzf9hx70kry3gwhrdzcs3qicjncjh-source","ref":"20231021","rev":"edece399be70818208bf2263c30cb2bcf435bbff","sha256":"0xmw35wmw3a4lja9q4qvlvpxv3xk0hnkjg4fwfw6f3inh6zfiqki","srcDir":"src","url":"https://git.syndicate-lang.org/ehmry/preserves-nim/archive/edece399be70818208bf2263c30cb2bcf435bbff.tar.gz"}]}

View File

@ -3,6 +3,6 @@ bin = @["nim_lk"]
description = "Tool for generating Nim lockfiles"
license = "BSD-3-Clause"
srcDir = "src"
version = "20231021"
version = "20231031"
requires "nim >= 2.0.0", "preserves >= 20231021"

View File

@ -7,7 +7,7 @@ import nimblepkg/common,
nimblepkg/packageparser,
nimblepkg/version
import std/[algorithm, deques, httpclient, json, os, osproc, parseutils, streams, strutils, uri]
import std/[algorithm, cmdline, deques, httpclient, json, os, osproc, parseutils, streams, strutils, uri]
import preserves
const githubPackagesUrl =
@ -64,8 +64,8 @@ proc gitLsRemote(url: string; withTags: bool): seq[tuple[tag: string, rev: strin
proc matchRev(url: string; wanted: VersionRange): tuple[tag: string, rev: string] =
if wanted.kind == verSpecial:
let special = string(wanted.spe)
if special.len == 41 and special[0] == '#':
result[1] = special[1..39]
if special[0] == '#':
result[1] = special[1..special.high]
else:
quit("unhandled version " & url & " " & $wanted)
else:
@ -120,9 +120,7 @@ proc prefetchGit(uri: Uri; version: VersionRange): Preserve =
var archiveUri = uri
archiveUri.scheme = "https"
archiveUri.path.removeSuffix ".git"
archiveUri.path.add "/archive/"
archiveUri.path.add rev
archiveUri.path.add ".tar.gz"
archiveUri.path = archiveUri.path / "archive"/ rev & ".tar.gz"
let client = newHttpClient()
defer: close(client)
let
@ -217,12 +215,12 @@ proc getPackgeUri(name: string): tuple[uri: string, meth: string] =
quit("Failed to parse shit JSON " & $e)
inc i
proc generateLockfile(): Preserve =
proc generateLockfile(directoryPath: string): Preserve =
result = initDictionary()
var
deps = initSequence()
pending: Deque[PkgTuple]
collectRequires(pending, getCurrentDir())
collectRequires(pending, directoryPath)
while pending.len > 0:
let batchLen = pending.len
for i in 1..batchLen:
@ -259,9 +257,16 @@ proc generateLockfile(): Preserve =
result["depends".toPreserve] = deps
proc main =
var packagePath = getCurrentDir()
case paramCount()
of 0: discard
of 1:
packagePath = commandLineParams()[0]
else:
quit "no more than a single package path may be specified"
var
stream = newFileStream(stdout)
lockInfo = generateLockfile()
lockInfo = generateLockfile(packagePath)
cannonicalize(lockInfo)
writeText(stream, lockInfo, textJson)
writeLine(stream)