Skip to content

Commit

Permalink
nim c -r main.nim now outputs under $nimcache/main
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Feb 13, 2020
1 parent 1e30310 commit 2ca2039
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
15 changes: 9 additions & 6 deletions compiler/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ when not defined(leanCompiler):
compileProject(graph)
finishDoc2Pass(graph.config.projectName)

proc setOutDir(conf: ConfigRef) =
if conf.outDir.isEmpty:
if optRun in conf.globalOptions:
conf.outDir = getNimcacheDir(conf)
else:
conf.outDir = conf.projectPath

proc commandCompileToC(graph: ModuleGraph) =
let conf = graph.config

if conf.outDir.isEmpty:
conf.outDir = conf.projectPath
setOutDir(conf)
if conf.outFile.isEmpty:
let targetName = if optGenDynLib in conf.globalOptions:
platform.OS[conf.target.targetOS].dllFrmt % conf.projectName
Expand Down Expand Up @@ -109,9 +114,7 @@ when not defined(leanCompiler):
proc commandCompileToJS(graph: ModuleGraph) =
let conf = graph.config
conf.exc = excCpp

if conf.outDir.isEmpty:
conf.outDir = conf.projectPath
setOutDir(conf)
if conf.outFile.isEmpty:
conf.outFile = RelativeFile(conf.projectName & ".js")

Expand Down
8 changes: 7 additions & 1 deletion testament/important_packages.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ template pkg(name: string; cmd = "nimble test"; hasDeps = false; url = ""): unty

var packages*: seq[tuple[name, cmd: string; hasDeps: bool; url: string]] = @[]

##[
if an upstream package is broken, you can apply a hotfix as follows:
pkg "foo", "sh -c 'git checkout hotfix && nimble test'", url = "https://github.com/yourusername/foo"
or, using an explicit hash instead of a branch name
(works on posix + windows)
]##

pkg "argparse"
pkg "arraymancer", "nim c tests/tests_cpu.nim", true
Expand Down Expand Up @@ -41,7 +47,7 @@ pkg "iterutils"
pkg "jstin"
pkg "karax", "nim c -r tests/tester.nim"
pkg "loopfusion"
pkg "msgpack4nim"
pkg "msgpack4nim", "sh -c 'git checkout pr_fix_outdir3 && nimble test'", url = "https://github.com/timotheecour/msgpack4nim"
pkg "nake", "nim c nakefile.nim"
pkg "neo", "nim c -d:blas=openblas tests/all.nim", true
# pkg "nico", "", true
Expand Down
16 changes: 10 additions & 6 deletions testament/testament.nim
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,20 @@ proc execCmdEx2(command: string, args: openArray[string]; workingDir, input: str
close(p)

proc nimcacheDir(filename, options: string, target: TTarget): string =
## Give each test a private nimcache dir so they don't clobber each other's.
## Give each test a private nimcache dir so they don't clobber each other's,
## and replace any whitespace in filename
let hashInput = options & $target
result = "nimcache" / (filename & '_' & hashInput.getMD5)
result = "nimcache" / (filename.replace(" ", "_") & '_' & hashInput.getMD5)

proc prepareTestArgs(cmdTemplate, filename, options, nimcache: string,
target: TTarget, extraOptions = ""): seq[string] =
let options = options & " " & quoteShell("--nimCache:" & nimcache) & " " & extraOptions
let options = options & " " & extraOptions
var fileReplace = "--nimcache:" & nimcache.quoteShell
if not options.contains("--outdir:"):
fileReplace.add " --outdir:$projectdir "
fileReplace.add " " & filename.quoteShell
result = parseCmdLine(cmdTemplate % ["target", targetToCmd[target],
"options", options, "file", filename.quoteShell,
"options", options, "file", fileReplace,
"filedir", filename.getFileDir()])

proc callCompiler(cmdTemplate, filename, options, nimcache: string,
Expand Down Expand Up @@ -678,8 +683,7 @@ proc main() =
case action
of "all":
#processCategory(r, Category"megatest", p.cmdLineRest.string, testsDir, runJoinableTests = false)

var myself = quoteShell(findExe("testament" / "testament"))
var myself = quoteShell getAppFilename()
if targetsStr.len > 0:
myself &= " " & quoteShell("--targets:" & targetsStr)

Expand Down
1 change: 1 addition & 0 deletions testament/testament.nim.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
path = "$nim" # For compiler/nodejs
-d:ssl # For azure
outdir:"$projectdir"
2 changes: 1 addition & 1 deletion tests/dll/nimhcr_integration.nim
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ proc compileReloadExecute() =
# to be applied only for the main build - the one done from koch, but when this
# binary triggers rebuilding itself here it shouldn't rebuild the main module -
# that would lead to replacing the main binary executable which is running!
let cmd = commandLineParams()[0..^1].join(" ").replace(" --forceBuild")
let cmd = commandLineParams().quoteShellCommand.replace(" --forceBuild")
let (stdout, exitcode) = execCmdEx(cmd)
if exitcode != 0:
echo "COMPILATION ERROR!"
Expand Down

0 comments on commit 2ca2039

Please sign in to comment.