@@ -5,7 +5,7 @@ import std/strutils
55
66import compiler/ [ast, idents, msgs, syntaxes, options, pathutils, lineinfos]
77import version, packageinfotypes, packageinfo, options, packageparser
8- import std/ [tables, sequtils, strscans]
8+ import std/ [tables, sequtils, strscans, strformat ]
99
1010type NimbleFileInfo * = object
1111 nimbleFile* : string
@@ -14,6 +14,7 @@ type NimbleFileInfo* = object
1414 version* : string
1515 tasks* : seq [(string , string )]
1616 features* : Table [string , seq [string ]]
17+ bin* : Table [string , string ]
1718 hasInstallHooks* : bool
1819 hasErrors* : bool
1920
@@ -31,6 +32,20 @@ proc extractRequires(n: PNode, conf: ConfigRef, result: var seq[string], hasErro
3132 localError (conf, ch.info, " 'requires' takes string literals" )
3233 hasErrors = true
3334
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+
3449proc extract (n: PNode , conf: ConfigRef , result: var NimbleFileInfo ) =
3550 case n.kind
3651 of nkStmtList, nkStmtListExpr:
@@ -83,6 +98,12 @@ proc extract(n: PNode, conf: ConfigRef, result: var NimbleFileInfo) =
8398 else :
8499 localError (conf, n[1 ].info, " assignments to 'version' must be string literals" )
85100 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
86107 else :
87108 discard
88109
@@ -216,13 +237,14 @@ proc toRequiresInfo*(pkgInfo: PackageInfo, options: Options): PackageInfo =
216237 # we need to use the vm to get the version. Another option could be to use the binary and ask for the version
217238 if pkgInfo.basicInfo.name.isNim:
218239 return pkgInfo.toFullInfo (options)
219-
240+
220241 let nimbleFileInfo = extractRequiresInfo (pkgInfo.myPath)
221242 result = pkgInfo
222243 result .requires = getRequires (nimbleFileInfo, result .activeFeatures)
223244 if pkgInfo.infoKind != pikFull: # dont update as full implies pik requires
224245 result .infoKind = pikRequires
225246 result .features = getFeatures (nimbleFileInfo)
247+ result .bin = nimbleFileInfo.bin
226248
227249when isMainModule :
228250 for x in tokenizeRequires (" jester@#head >= 1.5 & <= 1.8" ):
0 commit comments