diff --git a/src/nimblepkg/nimblesat.nim b/src/nimblepkg/nimblesat.nim index f8d68b8f..d2faf9f5 100644 --- a/src/nimblepkg/nimblesat.nim +++ b/src/nimblepkg/nimblesat.nim @@ -401,11 +401,11 @@ proc getSolvedPackages*(pkgVersionTable: Table[string, PackageVersions], output: for dep, q in items graph.reqs[ver.req].deps: if dep notin graph.packageToDependency: #debug print. show all packacges in the graph + output.add &"Dependency {dep} not found in the graph \n" for k, v in pkgVersionTable: output.add &"Package {k} \n" for v in v.versions: output.add &"\t \t Version {v.version} requires: {v.requires} \n" - output.add &"Dependency {dep} not found in the graph \n" return newSeq[SolvedPackage]() let form = toFormular(graph) @@ -447,7 +447,9 @@ proc getAllNimReleases(options: Options): seq[PackageMinimalInfo] = proc getPackageMinimalVersionsFromRepo*(repoDir, pkgName: string, downloadMethod: DownloadMethod, options: Options): seq[PackageMinimalInfo] = #This is expensive. We need to cache it. Potentially it could be also run in parallel # echo &"Discovering version for {pkgName}" - gitFetchTags(repoDir, downloadMethod) + gitFetchTags(repoDir, downloadMethod) + #First package must be the current one + result.add getPkgInfo(repoDir, options).getMinimalInfo(options) let tags = getTagsList(repoDir, downloadMethod).getVersionList() var checkedTags = 0 for (ver, tag) in tags.pairs: @@ -461,17 +463,19 @@ proc getPackageMinimalVersionsFromRepo*(repoDir, pkgName: string, downloadMethod let nimbleFile = findNimbleFile(repoDir, true, options) let pkgInfo = getPkgInfoFromFile(nimbleFile, options, useCache=false) let minimalInfo = pkgInfo.getMinimalInfo(options) - result.add minimalInfo + result.addUnique minimalInfo except CatchableError as e: displayWarning(&"Error reading tag {tag}: for package {pkgName}. This may not be relevant as it could be an old version of the package. \n {e.msg}", HighPriority) - + proc downloadMinimalPackage*(pv: PkgTuple, options: Options): seq[PackageMinimalInfo] = if pv.name == "": return newSeq[PackageMinimalInfo]() if pv.isNim and not options.disableNimBinaries: return getAllNimReleases(options) if pv.ver.kind == verSpecial: - return @[downloadPkInfoForPv(pv, options).getMinimalInfo(options)] - let (downloadRes, downloadMeth) = downloadPkgFromUrl(pv, options) - getPackageMinimalVersionsFromRepo(downloadRes.dir, pv.name, downloadMeth, options) + result = @[downloadPkInfoForPv(pv, options).getMinimalInfo(options)] + else: + let (downloadRes, downloadMeth) = downloadPkgFromUrl(pv, options) + result = getPackageMinimalVersionsFromRepo(downloadRes.dir, pv.name, downloadMeth, options) + # echo "Downloading minimal package for ", pv.name, " ", $pv.ver, result proc fillPackageTableFromPreferred*(packages: var Table[string, PackageVersions], preferredPackages: seq[PackageMinimalInfo]) = for pkg in preferredPackages: @@ -484,20 +488,17 @@ proc fillPackageTableFromPreferred*(packages: var Table[string, PackageVersions] proc getInstalledMinimalPackages*(options: Options): seq[PackageMinimalInfo] = getInstalledPkgsMin(options.getPkgsDir(), options).mapIt(it.getMinimalInfo(options)) -proc collectAllVersions*(versions: var Table[string, PackageVersions], package: PackageMinimalInfo, options: Options, getMinimalPackage: GetPackageMinimal, preferredPackages: seq[PackageMinimalInfo] = newSeq[PackageMinimalInfo]()) = - ### Collects all the versions of a package and its dependencies and stores them in the versions table - ### A getMinimalPackage function is passed to get the package + +proc collectAllVersions*(versions: var Table[string, PackageVersions], package: PackageMinimalInfo, options: Options, getMinimalPackage: GetPackageMinimal, preferredPackages: seq[PackageMinimalInfo] = newSeq[PackageMinimalInfo]()) = proc getMinimalFromPreferred(pv: PkgTuple): seq[PackageMinimalInfo] = - #Before proceding to download we check if the package is in the preferred packages for pp in preferredPackages: if pp.name == pv.name and pp.version.withinRange(pv.ver): return @[pp] + # echo "Getting minimal from getMinimalPackage for ", pv.name, " ", $pv.ver getMinimalPackage(pv, options) - for pv in package.requires: - # echo "Collecting versions for ", pv.name, " and Version: ", $pv.ver, " via ", package.name - var pv = pv - if not hasVersion(versions, pv): # Not found, meaning this package-version needs to be explored + proc processRequirements(versions: var Table[string, PackageVersions], pv: PkgTuple) = + if not hasVersion(versions, pv): var pkgMins = getMinimalFromPreferred(pv) for pkgMin in pkgMins.mitems: if pv.ver.kind == verSpecial: @@ -506,8 +507,14 @@ proc collectAllVersions*(versions: var Table[string, PackageVersions], package: versions[pv.name] = PackageVersions(pkgName: pv.name, versions: @[pkgMin]) else: versions[pv.name].versions.addUnique pkgMin - #TODO Note for when implementing "enumerate all versions": do not enter in the loop until we have collected all the versions - collectAllVersions(versions, pkgMin, options, getMinimalPackage, preferredPackages) + + # Process requirements from both the package and GetMinimalPackage results + for req in pkgMin.requires: + # echo "Processing requirement: ", req.name, " ", $req.ver + processRequirements(versions, req) + + for pv in package.requires: + processRequirements(versions, pv) proc topologicalSort*(solvedPkgs: seq[SolvedPackage]): seq[SolvedPackage] = var inDegree = initTable[string, int]() diff --git a/src/nimblepkg/options.nim b/src/nimblepkg/options.nim index 2b06ec36..a974b7fb 100644 --- a/src/nimblepkg/options.nim +++ b/src/nimblepkg/options.nim @@ -749,7 +749,7 @@ proc initOptions*(): Options = noColor: not isatty(stdout), startDir: getCurrentDir(), nimBinariesDir: getHomeDir() / ".nimble" / "nimbinaries", - maxTaggedVersions: 0 #TODO increase once we have a cache + maxTaggedVersions: 2 #TODO increase once we have a cache ) proc handleUnknownFlags(options: var Options) = diff --git a/tests/oldnimble/oldnimble.nimble b/tests/oldnimble/oldnimble.nimble new file mode 100644 index 00000000..070bebbb --- /dev/null +++ b/tests/oldnimble/oldnimble.nimble @@ -0,0 +1,13 @@ +# Package + +version = "0.1.0" +author = "jmgomez" +description = "A new awesome nimble package" +license = "MIT" +srcDir = "src" + + +# Dependencies + +requires "nim >= 2.0.11" +requires "nimble <= 0.16.2" #We know this nimble version has additional requirements (new nimble use submodules) diff --git a/tests/oldnimble/src/oldnimble.nim b/tests/oldnimble/src/oldnimble.nim new file mode 100644 index 00000000..b7a24803 --- /dev/null +++ b/tests/oldnimble/src/oldnimble.nim @@ -0,0 +1,7 @@ +# This is just an example to get you started. A typical library package +# exports the main API in this file. Note that you cannot rename this file +# but you can remove it if you wish. + +proc add*(x, y: int): int = + ## Adds two numbers together. + return x + y diff --git a/tests/oldnimble/src/oldnimble/submodule.nim b/tests/oldnimble/src/oldnimble/submodule.nim new file mode 100644 index 00000000..36fbf77d --- /dev/null +++ b/tests/oldnimble/src/oldnimble/submodule.nim @@ -0,0 +1,12 @@ +# This is just an example to get you started. Users of your library will +# import this file by writing ``import oldnimble/submodule``. Feel free to rename or +# remove this file altogether. You may create additional modules alongside +# this file as required. + +type + Submodule* = object + name*: string + +proc initSubmodule*(): Submodule = + ## Initialises a new ``Submodule`` object. + Submodule(name: "Anonymous") diff --git a/tests/oldnimble/tests/test1.nim b/tests/oldnimble/tests/test1.nim new file mode 100644 index 00000000..f8512dbe --- /dev/null +++ b/tests/oldnimble/tests/test1.nim @@ -0,0 +1,12 @@ +# This is just an example to get you started. You may wish to put all of your +# tests into a single file, or separate them into multiple `test1`, `test2` +# etc. files (better names are recommended, just make sure the name starts with +# the letter 't'). +# +# To run these tests, simply execute `nimble test`. + +import unittest + +import oldnimble +test "can add": + check add(5, 5) == 10 diff --git a/tests/wronglytaggednim/src/wronglytaggednim.nim b/tests/wronglytaggednim/src/wronglytaggednim.nim new file mode 100644 index 00000000..b7a24803 --- /dev/null +++ b/tests/wronglytaggednim/src/wronglytaggednim.nim @@ -0,0 +1,7 @@ +# This is just an example to get you started. A typical library package +# exports the main API in this file. Note that you cannot rename this file +# but you can remove it if you wish. + +proc add*(x, y: int): int = + ## Adds two numbers together. + return x + y diff --git a/tests/wronglytaggednim/src/wronglytaggednim/submodule.nim b/tests/wronglytaggednim/src/wronglytaggednim/submodule.nim new file mode 100644 index 00000000..63299f12 --- /dev/null +++ b/tests/wronglytaggednim/src/wronglytaggednim/submodule.nim @@ -0,0 +1,12 @@ +# This is just an example to get you started. Users of your library will +# import this file by writing ``import wronglytaggednim/submodule``. Feel free to rename or +# remove this file altogether. You may create additional modules alongside +# this file as required. + +type + Submodule* = object + name*: string + +proc initSubmodule*(): Submodule = + ## Initialises a new ``Submodule`` object. + Submodule(name: "Anonymous") diff --git a/tests/wronglytaggednim/tests/test1.nim b/tests/wronglytaggednim/tests/test1.nim new file mode 100644 index 00000000..3755c631 --- /dev/null +++ b/tests/wronglytaggednim/tests/test1.nim @@ -0,0 +1,12 @@ +# This is just an example to get you started. You may wish to put all of your +# tests into a single file, or separate them into multiple `test1`, `test2` +# etc. files (better names are recommended, just make sure the name starts with +# the letter 't'). +# +# To run these tests, simply execute `nimble test`. + +import unittest + +import wronglytaggednim +test "can add": + check add(5, 5) == 10 diff --git a/tests/wronglytaggednim/wronglytaggednim.nimble b/tests/wronglytaggednim/wronglytaggednim.nimble new file mode 100644 index 00000000..c9664b0a --- /dev/null +++ b/tests/wronglytaggednim/wronglytaggednim.nimble @@ -0,0 +1,12 @@ +# Package + +version = "0.1.0" +author = "jmgomez" +description = "A new awesome nimble package" +license = "MIT" +srcDir = "src" + + +# Dependencies + +requires "nim >= 0.18.0", "random >= 0.5.6", "nimfp <= 0.4.5"