Skip to content

Adds a test that verifies that the required Nim is the one used by nimble when compiling and running the package #1235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/nimblepkg/nimenv.nim
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,34 @@ proc compileNim*(options: Options, nimDest: string, v: VersionRange) =
else:
"csources_v1"
cd workspace:
echo "Entering CSOURCES", csourcesVersion, " exists ", dirExists(csourcesVersion)
if not dirExists(csourcesVersion):
exec "git clone https://github.com/nim-lang/" & csourcesVersion

var csourcesSucceed = false
cd workspace / csourcesVersion:
when defined(windows):
exec "build.bat"
let cmd = "build.bat"
csourcesSucceed = os.execShellCmd(cmd) != 0
else:
let makeExe = findExe("make")
if makeExe.len == 0:
exec "sh build.sh"
let cmd = "sh build.sh"
csourcesSucceed = os.execShellCmd(cmd) != 0
else:
exec "make"
let nimExe0 = ".." / csourcesVersion / "bin" / "nim".addFileExt(ExeExt)
let cmd = "make"
csourcesSucceed = os.execShellCmd(cmd) != 0

cd nimDest:
#Sometimes building from csources fails and we cant do much about it. So we fallback to the slow build_all method
if not csourcesSucceed:
display("Warning", "Building nim from csources failed. Using `build_all`", Warning, HighPriority)
let cmd =
when defined(windows): "build_all.bat"
else: "sh build_all.sh"
exec cmd
let nimExe = "bin" / "nim".addFileExt(ExeExt)
copyFileWithPermissions nimExe0, nimExe
when defined(nimExe0):
copyFileWithPermissions nimExe0, nimExe
exec nimExe & " c --noNimblePath --skipUserCfg --skipParentCfg --hints:off koch"
let kochExe = when defined(windows): "koch.exe" else: "./koch"
exec kochExe & " boot -d:release --skipUserCfg --skipParentCfg --hints:off"
Expand Down
6 changes: 5 additions & 1 deletion tests/nimnimble/nim1.6.20/nim1620.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ author = "jmgomez"
description = "A new awesome nimble package"
license = "MIT"
srcDir = "src"

bin = @["nim1620"]

# Dependencies

requires "nim == 1.6.20"

after build:
let (output, _) = gorgeEx "./nim1620"
assert output.strip == NimVersion
2 changes: 2 additions & 0 deletions tests/nimnimble/nim1.6.20/src/nim1620.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
proc add*(x, y: int): int =
## Adds two numbers together.
return x + y

echo NimVersion
15 changes: 15 additions & 0 deletions tests/nimnimble/nim2.0.10/nim2010.nimble
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Package
version = "0.1.0"
author = "jmgomez"
description = "A new awesome nimble package"
license = "MIT"
srcDir = "src"
bin = @["nim2010"]

# Dependencies

requires "nim == 2.0.10"

after build:
let (output, _) = gorgeEx "./nim2010"
assert output.strip == NimVersion
10 changes: 10 additions & 0 deletions tests/nimnimble/nim2.0.10/src/nim2010.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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


echo NimVersion
12 changes: 12 additions & 0 deletions tests/nimnimble/nim2.0.10/src/nim2010/submodule.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This is just an example to get you started. Users of your library will
# import this file by writing ``import nim204/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")
12 changes: 12 additions & 0 deletions tests/nimnimble/nim2.0.10/tests/test1.nim
Original file line number Diff line number Diff line change
@@ -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 nim204
test "can add":
check add(5, 5) == 10
7 changes: 5 additions & 2 deletions tests/nimnimble/nim2.0.4/nim204.nimble
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Package

version = "0.1.0"
author = "jmgomez"
description = "A new awesome nimble package"
license = "MIT"
srcDir = "src"

bin = @["nim204"]

# Dependencies

requires "nim == 2.0.4"

after build:
let (output, _) = gorgeEx "./nim204"
assert output.strip == NimVersion
3 changes: 3 additions & 0 deletions tests/nimnimble/nim2.0.4/src/nim204.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
proc add*(x, y: int): int =
## Adds two numbers together.
return x + y


echo NimVersion
5 changes: 5 additions & 0 deletions tests/nimnimble/nimdevel/nimdevel.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ author = "jmgomez"
description = "A new awesome nimble package"
license = "MIT"
srcDir = "src"
bin = @["nimdevel"]


# Dependencies

requires "nim#devel"

after build:
let (output, _) = gorgeEx "./nimdevel"
assert output.strip == NimVersion
2 changes: 2 additions & 0 deletions tests/nimnimble/nimdevel/src/nimdevel.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
proc add*(x, y: int): int =
## Adds two numbers together.
return x + y

echo NimVersion
3 changes: 1 addition & 2 deletions tests/tniminstall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ from nimblepkg/common import cd
proc isNimPkgVer(folder: string, ver: string): bool =
let name = folder.split("-")
result = name.len == 3 and name[1].contains(ver)
echo "Checking ", folder, " for ", ver, " result: ", result
if ver == "devel":
#We know devel is bigger than 2.1 and it should be an odd number (notice what we test here is actually the #)
var major, minor, patch: int
Expand All @@ -26,7 +25,7 @@ suite "Nim install":
cd nimVerDir:
let nimVer = nimVerDir.replace("nim", "")
echo "Checking version ", nimVer
let (_, exitCode) = execNimble("install", "-l")
let (_, exitCode) = execNimble("build", "-l")
let pkgPath = getCurrentDir() / "nimbledeps" / "pkgs2"
check exitCode == QuitSuccess
check walkDir(pkgPath).toSeq.anyIt(it[1].isNimPkgVer(nimVer))