diff --git a/src/nimblepkg/nimscriptwrapper.nim b/src/nimblepkg/nimscriptwrapper.nim index 1a49c94d..44d6b812 100755 --- a/src/nimblepkg/nimscriptwrapper.nim +++ b/src/nimblepkg/nimscriptwrapper.nim @@ -65,7 +65,6 @@ proc setupNimscript(scriptName: string, options: Options) = cacheDir = getTempDir() / "nimblecache" nimscriptApiFile = cacheDir / "nimscriptapi.nim" nimsFile = getNimsFile(scriptName, options) - iniFile = nimsFile.changeFileExt(".ini") let isNimscriptApiCached = @@ -89,14 +88,19 @@ import system except getCommand, setCommand, switch, `--`, requires, task, packageName """ & "import nimscriptapi, strutils\n" & scriptName.readFile() & "\nonExit()\n") - discard tryRemoveFile(iniFile) proc getIniFile*(scriptName: string, options: Options): string = let nimsFile = getNimsFile(scriptName, options) result = nimsFile.changeFileExt(".ini") - if not result.fileExists(): + + let + isIniResultCached = + result.fileExists() and result.getLastModificationTime() > + scriptName.getLastModificationTime() + + if not isIniResultCached: setupNimscript(scriptName, options) let (output, exitCode) = diff --git a/tests/caching/caching.nimble b/tests/caching/caching.nimble new file mode 100644 index 00000000..d3035a90 --- /dev/null +++ b/tests/caching/caching.nimble @@ -0,0 +1,10 @@ +# Package + +version = "0.1.0" +author = "Dominik Picheta" +description = "Test package" +license = "BSD" + +# Dependencies + +requires "nim >= 0.12.1" diff --git a/tests/tester.nim b/tests/tester.nim index 8fcf303c..b57ab188 100644 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -71,6 +71,17 @@ proc inLines(lines: seq[string], line: string): bool = for i in lines: if line.normalize in i.normalize: return true +test "caching works": + cd "caching": + var (output, exitCode) = execNimble("dump") + check output.contains("0.1.0") + let + nfile = "caching.nimble" + writeFile(nfile, readFile(nfile).replace("0.1.0", "0.2.0")) + (output, exitCode) = execNimble("dump") + check output.contains("0.2.0") + writeFile(nfile, readFile(nfile).replace("0.2.0", "0.1.0")) + test "picks #head when looking for packages": cd "versionClashes" / "aporiaScenario": let (output, exitCode) = execNimble("install", "-y", "--verbose")