summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorflywind <43030857+xflywind@users.noreply.github.com>2021-02-17 08:48:17 -0600
committerGitHub <noreply@github.com>2021-02-17 15:48:17 +0100
commit874ccc8493605b8e227007f1c0fa1a1131b80e23 (patch)
tree87d26d96f26c912d6d7a7fa65aa97e68613f22e3
parentaa3af9e0537eedc874b4c6dbb56d895c7ba8b26d (diff)
downloadNim-874ccc8493605b8e227007f1c0fa1a1131b80e23.tar.gz
[minor] clean extccomp (#17069)
-rw-r--r--compiler/extccomp.nim37
1 files changed, 16 insertions, 21 deletions
diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim
index 6341cddd9..e95ed893b 100644
--- a/compiler/extccomp.nim
+++ b/compiler/extccomp.nim
@@ -12,9 +12,9 @@
 # from a lineinfos file, to provide generalized procedures to compile
 # nim files.
 
-import
-  ropes, os, strutils, osproc, platform, condsyms, options, msgs,
-  lineinfos, std / sha1, streams, pathutils, sequtils, times, strtabs
+import ropes, platform, condsyms, options, msgs, lineinfos, pathutils
+
+import std/[os, strutils, osproc, sha1, streams, sequtils, times, strtabs, json]
 
 type
   TInfoCCProp* = enum         # properties of the C compiler:
@@ -571,10 +571,10 @@ proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile,
 
   includeCmd.add(join([CC[c].includeCmd, quoteShell(conf.projectPath.string)]))
 
-  var cf = if noAbsolutePaths(conf): AbsoluteFile extractFilename(cfile.cname.string)
+  let cf = if noAbsolutePaths(conf): AbsoluteFile extractFilename(cfile.cname.string)
            else: cfile.cname
 
-  var objfile =
+  let objfile =
     if cfile.obj.isEmpty:
       if CfileFlag.External notin cfile.flags or noAbsolutePaths(conf):
         toObjFile(conf, cf).string
@@ -629,8 +629,8 @@ proc footprint(conf: ConfigRef; cfile: Cfile): SecureHash =
 proc externalFileChanged(conf: ConfigRef; cfile: Cfile): bool =
   if conf.backend == backendJs: return false # pre-existing behavior, but not sure it's good
 
-  var hashFile = toGeneratedFile(conf, conf.withPackageName(cfile.cname), "sha1")
-  var currentHash = footprint(conf, cfile)
+  let hashFile = toGeneratedFile(conf, conf.withPackageName(cfile.cname), "sha1")
+  let currentHash = footprint(conf, cfile)
   var f: File
   if open(f, hashFile.string, fmRead):
     let oldHash = parseSecureHash(f.readLine())
@@ -903,8 +903,8 @@ proc callCCompiler*(conf: ConfigRef) =
       # only if not cached - copy the resulting main file from the nimcache folder to its originally intended destination
       if CfileFlag.Cached notin conf.toCompile[mainFileIdx].flags:
         let mainObjFile = getObjFilePath(conf, conf.toCompile[mainFileIdx])
-        var src = conf.hcrLinkTargetName(mainObjFile, true)
-        var dst = conf.prepareToWriteOutput
+        let src = conf.hcrLinkTargetName(mainObjFile, true)
+        let dst = conf.prepareToWriteOutput
         copyFileWithPermissions(src.string, dst.string)
     else:
       for x in conf.toCompile:
@@ -933,20 +933,15 @@ proc callCCompiler*(conf: ConfigRef) =
     script.add("\n")
     generateScript(conf, script)
 
-#from json import escapeJson
-import json, std / sha1
 
 template hashNimExe(): string = $secureHashFile(os.getAppFilename())
 
 proc writeJsonBuildInstructions*(conf: ConfigRef) =
-  template lit(x: untyped) = f.write x
-  template str(x: untyped) =
-    when compiles(escapeJson(x, buf)):
-      buf.setLen 0
-      escapeJson(x, buf)
-      f.write buf
-    else:
-      f.write escapeJson(x)
+  template lit(x: string) = f.write x
+  template str(x: string) =
+    buf.setLen 0
+    escapeJson(x, buf)
+    f.write buf
 
   proc cfiles(conf: ConfigRef; f: File; buf: var string; clist: CfileList, isExternal: bool) =
     var comma = false
@@ -982,7 +977,7 @@ proc writeJsonBuildInstructions*(conf: ConfigRef) =
       pastStart = true
     lit "\L"
 
-  proc depfiles(conf: ConfigRef; f: File) =
+  proc depfiles(conf: ConfigRef; f: File; buf: var string) =
     var i = 0
     for it in conf.m.fileInfos:
       let path = it.fullPath.string
@@ -1034,7 +1029,7 @@ proc writeJsonBuildInstructions*(conf: ConfigRef) =
       lit ",\L\"cmdline\": "
       str conf.commandLine
       lit ",\L\"depfiles\":[\L"
-      depfiles(conf, f)
+      depfiles(conf, f, buf)
       lit "],\L\"nimexe\": \L"
       str hashNimExe()
       lit "\L"
f='#n273'>273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393