Skip to content

Commit

Permalink
Fix caching issue
Browse files Browse the repository at this point in the history
  • Loading branch information
genotrance committed Apr 28, 2019
1 parent 640ce3f commit e86a376
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/nimblepkg/nimscriptwrapper.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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) =
Expand Down
10 changes: 10 additions & 0 deletions tests/caching/caching.nimble
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Package

version = "0.1.0"
author = "Dominik Picheta"
description = "Test package"
license = "BSD"

# Dependencies

requires "nim >= 0.12.1"
11 changes: 11 additions & 0 deletions tests/tester.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit e86a376

Please sign in to comment.