@@ -5,7 +5,7 @@ import std/strutils
5
5
6
6
import compiler/ [ast, idents, msgs, syntaxes, options, pathutils, lineinfos]
7
7
import version, packageinfotypes, packageinfo, options, packageparser
8
- import std/ [tables, sequtils, strscans]
8
+ import std/ [tables, sequtils, strscans, strformat ]
9
9
10
10
type NimbleFileInfo* = object
11
11
nimbleFile* : string
@@ -14,6 +14,7 @@ type NimbleFileInfo* = object
14
14
version* : string
15
15
tasks* : seq [(string , string )]
16
16
features* : Table[string , seq [string ]]
17
+ bin* : Table[string , string ]
17
18
hasInstallHooks* : bool
18
19
hasErrors* : bool
19
20
@@ -31,6 +32,20 @@ proc extractRequires(n: PNode, conf: ConfigRef, result: var seq[string], hasErro
31
32
localError(conf, ch.info, " 'requires' takes string literals" )
32
33
hasErrors = true
33
34
35
+ proc extractSeqLiteral(n: PNode, conf: ConfigRef, varName: string ): seq [string ] =
36
+ # # Extracts a sequence literal of the form @["item1", "item2"]
37
+ if n.kind == nkPrefix and n[0 ].kind == nkIdent and n[0 ].ident.s == " @" :
38
+ if n[1 ].kind == nkBracket:
39
+ for item in n[1 ]:
40
+ if item.kind in {nkStrLit .. nkTripleStrLit}:
41
+ result .add item.strVal
42
+ else :
43
+ localError(conf, item.info, & " '{ varName} ' sequence items must be string literals " )
44
+ else :
45
+ localError(conf, n.info, & " '{ varName} ' must be assigned a sequence of strings " )
46
+ else :
47
+ localError(conf, n.info, & " '{ varName} ' must be assigned a sequence with @ prefix " )
48
+
34
49
proc extract(n: PNode, conf: ConfigRef, result : var NimbleFileInfo) =
35
50
case n.kind
36
51
of nkStmtList, nkStmtListExpr:
@@ -83,6 +98,12 @@ proc extract(n: PNode, conf: ConfigRef, result: var NimbleFileInfo) =
83
98
else :
84
99
localError(conf, n[1 ].info, " assignments to 'version' must be string literals" )
85
100
result .hasErrors = true
101
+ elif n[0 ].kind == nkIdent and eqIdent(n[0 ].ident.s, " bin" ):
102
+ let binSeq = extractSeqLiteral(n[1 ], conf, " bin" )
103
+ for bin in binSeq:
104
+ result .bin[bin] = bin
105
+ else :
106
+ discard
86
107
else :
87
108
discard
88
109
@@ -216,13 +237,14 @@ proc toRequiresInfo*(pkgInfo: PackageInfo, options: Options): PackageInfo =
216
237
# we need to use the vm to get the version. Another option could be to use the binary and ask for the version
217
238
if pkgInfo.basicInfo.name.isNim:
218
239
return pkgInfo.toFullInfo(options)
219
-
240
+
220
241
let nimbleFileInfo = extractRequiresInfo(pkgInfo.myPath)
221
242
result = pkgInfo
222
243
result .requires = getRequires(nimbleFileInfo, result .activeFeatures)
223
244
if pkgInfo.infoKind != pikFull: # dont update as full implies pik requires
224
245
result .infoKind = pikRequires
225
246
result .features = getFeatures(nimbleFileInfo)
247
+ result .bin = nimbleFileInfo.bin
226
248
227
249
when isMainModule :
228
250
for x in tokenizeRequires(" jester@#head >= 1.5 & <= 1.8" ):
0 commit comments