diff options
Diffstat (limited to 'compiler/gorgeimpl.nim')
-rw-r--r-- | compiler/gorgeimpl.nim | 67 |
1 files changed, 29 insertions, 38 deletions
diff --git a/compiler/gorgeimpl.nim b/compiler/gorgeimpl.nim index 4e1ce6d50..da911c84c 100644 --- a/compiler/gorgeimpl.nim +++ b/compiler/gorgeimpl.nim @@ -7,10 +7,16 @@ # distribution, for details about the copyright. # -## Module that implements ``gorge`` for the compiler as well as -## the scriptable import mechanism. +## Module that implements ``gorge`` for the compiler. -import msgs, securehash, os, osproc, streams, strutils, options +import msgs, options, lineinfos, pathutils + +import std/[os, osproc, streams] + +when defined(nimPreviewSlimSystem): + import std/syncio + +import ../dist/checksums/src/checksums/sha1 proc readOutput(p: Process): (string, int) = result[0] = "" @@ -22,62 +28,47 @@ proc readOutput(p: Process): (string, int) = result[0].setLen(result[0].len - "\n".len) result[1] = p.waitForExit -proc opGorge*(cmd, input, cache: string, info: TLineInfo): (string, int) = - let workingDir = parentDir(info.toFullPath) - if cache.len > 0:# and optForceFullMake notin gGlobalOptions: +proc opGorge*(cmd, input, cache: string, info: TLineInfo; conf: ConfigRef): (string, int) = + let workingDir = parentDir(toFullPath(conf, info)) + result = ("", 0) + if cache.len > 0: let h = secureHash(cmd & "\t" & input & "\t" & cache) - let filename = options.toGeneratedFile("gorge_" & $h, "txt") - var f: File - if open(f, filename): + let filename = toGeneratedFile(conf, AbsoluteFile("gorge_" & $h), "txt").string + var f: File = default(File) + if optForceFullMake notin conf.globalOptions and open(f, filename): result = (f.readAll, 0) f.close return var readSuccessful = false try: var p = startProcess(cmd, workingDir, - options={poEvalCommand, poStderrToStdout}) + options={poEvalCommand, poStdErrToStdOut}) if input.len != 0: p.inputStream.write(input) p.inputStream.close() result = p.readOutput + p.close() readSuccessful = true # only cache successful runs: if result[1] == 0: writeFile(filename, result[0]) except IOError, OSError: - if not readSuccessful: result = ("", -1) + if not readSuccessful: + when defined(nimLegacyGorgeErrors): + result = ("", -1) + else: + result = ("Error running startProcess: " & getCurrentExceptionMsg(), -1) else: try: var p = startProcess(cmd, workingDir, - options={poEvalCommand, poStderrToStdout}) + options={poEvalCommand, poStdErrToStdOut}) if input.len != 0: p.inputStream.write(input) p.inputStream.close() result = p.readOutput + p.close() except IOError, OSError: - result = ("", -1) - -proc scriptableImport*(pkg, subdir: string; info: TLineInfo): string = - var cmd = getConfigVar("resolver.exe") - if cmd.len == 0: cmd = "nimresolve" - else: cmd = quoteShell(cmd) - cmd.add " --source:" - cmd.add quoteShell(info.toFullPath()) - cmd.add " --stdlib:" - cmd.add quoteShell(options.libpath) - cmd.add " --project:" - cmd.add quoteShell(gProjectFull) - if subdir.len != 0: - cmd.add " --subdir:" - cmd.add quoteShell(subdir) - if options.gNoNimblePath: - cmd.add " --nonimblepath" - cmd.add ' ' - cmd.add quoteShell(pkg) - let (res, exitCode) = opGorge(cmd, "", cmd, info) - if exitCode == 0: - result = res.strip() - elif res.len > 0: - localError(info, res) - else: - localError(info, "cannot resolve: " & (pkg / subdir)) + when defined(nimLegacyGorgeErrors): + result = ("", -1) + else: + result = ("Error running startProcess: " & getCurrentExceptionMsg(), -1) |