From db018f235babd5b6e64d9524fafd02e110499dcd Mon Sep 17 00:00:00 2001 From: Ivan Bobev Date: Tue, 6 Aug 2019 16:34:53 +0300 Subject: [PATCH] Clear deprecation warnings This fix clears deprecation warnings related to Nim's HashSet procedures. There were two types of warnings which have been fixed: - Warning: Deprecated since v0.20, use 'initHashSet'; initSet is deprecated [Deprecated] - Warning: Deprecated since v0.20, use 'toHashSet'; toSet is deprecated [Deprecated] Backward compatibility with older Nim versions is also implemented. Related to #680 --- src/nimble.nim | 6 +++--- src/nimblepkg/cli.nim | 5 ++++- src/nimblepkg/common.nim | 12 ++++++++++++ src/nimblepkg/packageinfo.nim | 2 +- src/nimblepkg/packageinstaller.nim | 5 ++++- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/nimble.nim b/src/nimble.nim index a35f262..6c13ca9 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -94,7 +94,7 @@ proc copyFilesRec(origDir, currentDir, dest: string, ## Copies all the required files, skips files specified in the .nimble file ## (PackageInfo). ## Returns a list of filepaths to files which have been installed. - result = initSet[string]() + result = initHashSet[string]() let whitelistMode = pkgInfo.installDirs.len != 0 or pkgInfo.installFiles.len != 0 or @@ -373,7 +373,7 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options, createDir(pkgDestDir) # Copy this package's files based on the preferences specified in PkgInfo. - var filesInstalled = initSet[string]() + var filesInstalled = initHashSet[string]() iterInstallFiles(realDir, pkgInfo, options, proc (file: string) = createDir(changeRoot(realDir, pkgDestDir, file.splitFile.dir)) @@ -386,7 +386,7 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options, pkgInfo.myPath) filesInstalled.incl copyFileD(pkgInfo.myPath, dest) - var binariesInstalled = initSet[string]() + var binariesInstalled = initHashSet[string]() if pkgInfo.bin.len > 0: # Make sure ~/.nimble/bin directory is created. createDir(binDir) diff --git a/src/nimblepkg/cli.nim b/src/nimblepkg/cli.nim index 9544373..a3ac714 100644 --- a/src/nimblepkg/cli.nim +++ b/src/nimblepkg/cli.nim @@ -15,6 +15,9 @@ import terminal, sets, strutils import version +when not declared(initHashSet): + import common + type CLI* = ref object level: Priority @@ -46,7 +49,7 @@ const proc newCLI(): CLI = result = CLI( level: HighPriority, - warnings: initSet[(string, string)](), + warnings: initHashSet[(string, string)](), suppressionCount: 0, showColor: true, suppressMessages: false diff --git a/src/nimblepkg/common.nim b/src/nimblepkg/common.nim index 5cacb86..f015d24 100644 --- a/src/nimblepkg/common.nim +++ b/src/nimblepkg/common.nim @@ -63,3 +63,15 @@ when not defined(nimscript): const nimbleVersion* = "0.10.2" + +when not declared(initHashSet): + import sets + + template initHashSet*[A](initialSize = 64): HashSet[A] = + initSet[A](initialSize) + +when not declared(toHashSet): + import sets + + template toHashSet*[A](keys: openArray[A]): HashSet[A] = + toSet(keys) diff --git a/src/nimblepkg/packageinfo.nim b/src/nimblepkg/packageinfo.nim index 6b2d6ae..e3cac25 100644 --- a/src/nimblepkg/packageinfo.nim +++ b/src/nimblepkg/packageinfo.nim @@ -277,7 +277,7 @@ proc getPackage*(pkg: string, options: Options, resPkg: var Package): bool = proc getPackageList*(options: Options): seq[Package] = ## Returns the list of packages found in the downloaded packages.json files. result = @[] - var namesAdded = initSet[string]() + var namesAdded = initHashSet[string]() for name, list in options.config.packageLists: let packages = readPackageList(name, options) for p in packages: diff --git a/src/nimblepkg/packageinstaller.nim b/src/nimblepkg/packageinstaller.nim index f131942..71f305f 100644 --- a/src/nimblepkg/packageinstaller.nim +++ b/src/nimblepkg/packageinstaller.nim @@ -5,6 +5,9 @@ import os, strutils, sets, json # Local imports import version, cli, options, tools +when not declared(initHashSet) or not declared(toHashSet): + import common + when defined(windows): # This is just for Win XP support. # TODO: Drop XP support? @@ -103,4 +106,4 @@ proc saveNimbleMeta*(pkgDestDir, pkgDir, vcsRevision, nimbleLinkPath: string) = ## pkgDir - The directory where the original package files are. ## For example: ~/projects/jester/ saveNimbleMeta(pkgDestDir, "file://" & pkgDir, vcsRevision, - toSet[string]([nimbleLinkPath]), initSet[string](), true) \ No newline at end of file + toHashSet[string]([nimbleLinkPath]), initHashSet[string](), true) \ No newline at end of file