Skip to content

Commit

Permalink
Declarative various fixes (#1359)
Browse files Browse the repository at this point in the history
* Makes the declarative parser the default (CI test)

* Various fixes

- Fixes an issue where the --require flag wasnt working
- Fixes an issue where cycletest was failing due to underspecified nim
- Adds support to multiple require features in the same line
- Fallback to full vm parser when a babel file is encountered
  • Loading branch information
jmgomez authored Mar 5, 2025
1 parent ec91888 commit 8a4786c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
38 changes: 22 additions & 16 deletions src/nimblepkg/declarativeparser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import std/strutils

import compiler/[ast, idents, msgs, syntaxes, options, pathutils, lineinfos]
import version, packageinfotypes, packageinfo, options, packageparser
import std/[tables, sequtils, strscans, strformat]
import version, packageinfotypes, packageinfo, options, packageparser, cli
import std/[tables, sequtils, strscans, strformat, os]

type NimbleFileInfo* = object
nimbleFile*: string
Expand Down Expand Up @@ -207,25 +207,27 @@ iterator tokenizeRequires*(s: string): string =
yield tok


proc parseRequiresWithFeatures(require: string): (PkgTuple, seq[string]) =
proc parseRequiresWithFeatures(require: string): seq[(PkgTuple, seq[string])] =
#features are expressed like this: require[feature1, feature2]
var featuresStr: string
var requireStr: string
var features = newSeq[string]()
if scanf(require, "$*[$*]", requireStr, featuresStr):
features = featuresStr.split(",")
return (parseRequires(requireStr), features)
else:
return (parseRequires(require), @[])
result = newSeq[(PkgTuple, seq[string])]()
for req in require.split(",").mapIt(it.strip):
var featuresStr: string
var requireStr: string
var features = newSeq[string]()
if scanf(req, "$*[$*]", requireStr, featuresStr):
features = featuresStr.split(",")
result.add((parseRequires(requireStr), features))
else:
result.add((parseRequires(req), @[]))

proc getRequires*(nimbleFileInfo: NimbleFileInfo, pkgActiveFeatures: var Table[PkgTuple, seq[string]]): seq[PkgTuple] =
for require in nimbleFileInfo.requires:
let (pkgTuple, activeFeatures) = parseRequiresWithFeatures(require)
if activeFeatures.len > 0:
# displayInfo &"Package {nimbleFileInfo.nimbleFile} Found active features {activeFeatures} for {pkgTuple}", priority = HighPriority
pkgActiveFeatures[pkgTuple] = activeFeatures
for (pkgTuple, activeFeatures) in parseRequiresWithFeatures(require):
if activeFeatures.len > 0:
# displayInfo &"Package {nimbleFileInfo.nimbleFile} Found active features {activeFeatures} for {pkgTuple}", priority = HighPriority
pkgActiveFeatures[pkgTuple] = activeFeatures

result.add(pkgTuple)
result.add(pkgTuple)

proc getFeatures*(nimbleFileInfo: NimbleFileInfo): Table[string, seq[PkgTuple]] =
result = initTable[string, seq[PkgTuple]]()
Expand All @@ -238,6 +240,10 @@ proc toRequiresInfo*(pkgInfo: PackageInfo, options: Options): PackageInfo =
if pkgInfo.basicInfo.name.isNim:
return pkgInfo.toFullInfo(options)

if pkgInfo.myPath.splitFile.ext == ".babel":
displayWarning &"Package {pkgInfo.basicInfo.name} is a babel package, skipping declarative parser", priority = HighPriority
return pkgInfo.toFullInfo(options)

let nimbleFileInfo = extractRequiresInfo(pkgInfo.myPath)
result = pkgInfo
result.requires = getRequires(nimbleFileInfo, result.activeFeatures)
Expand Down
3 changes: 2 additions & 1 deletion src/nimblepkg/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@ proc initOptions*(): Options =
startDir: getCurrentDir(),
nimBinariesDir: getHomeDir() / ".nimble" / "nimbinaries",
maxTaggedVersions: 4,
useSatSolver: true
useSatSolver: true,
useDeclarativeParser: false
)

proc handleUnknownFlags(options: var Options) =
Expand Down
2 changes: 1 addition & 1 deletion tests/sattests/cycletest/cycletest.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ srcDir = "src"

# Dependencies

requires "https://github.com/disruptek/frosty"
requires "nim", "https://github.com/disruptek/frosty"

0 comments on commit 8a4786c

Please sign in to comment.