[minor] clean extccomp (#17069)

This commit is contained in:
flywind 2021-02-17 08:48:17 -06:00 • committed by GitHub
commit 874ccc8493
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,9 +12,9 @@
# from a lineinfos file, to provide generalized procedures to compile # from a lineinfos file, to provide generalized procedures to compile
# nim files. # nim files.
import import ropes, platform, condsyms, options, msgs, lineinfos, pathutils
ropes, os, strutils, osproc, platform, condsyms, options, msgs,
lineinfos, std / sha1, streams, pathutils, sequtils, times, strtabs import std/[os, strutils, osproc, sha1, streams, sequtils, times, strtabs, json]
type type
TInfoCCProp* = enum # properties of the C compiler: 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)])) 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 else: cfile.cname
var objfile = let objfile =
if cfile.obj.isEmpty: if cfile.obj.isEmpty:
if CfileFlag.External notin cfile.flags or noAbsolutePaths(conf): if CfileFlag.External notin cfile.flags or noAbsolutePaths(conf):
toObjFile(conf, cf).string toObjFile(conf, cf).string
@ -629,8 +629,8 @@ proc footprint(conf: ConfigRef; cfile: Cfile): SecureHash =
proc externalFileChanged(conf: ConfigRef; cfile: Cfile): bool = proc externalFileChanged(conf: ConfigRef; cfile: Cfile): bool =
if conf.backend == backendJs: return false # pre-existing behavior, but not sure it's good if conf.backend == backendJs: return false # pre-existing behavior, but not sure it's good
var hashFile = toGeneratedFile(conf, conf.withPackageName(cfile.cname), "sha1") let hashFile = toGeneratedFile(conf, conf.withPackageName(cfile.cname), "sha1")
var currentHash = footprint(conf, cfile) let currentHash = footprint(conf, cfile)
var f: File var f: File
if open(f, hashFile.string, fmRead): if open(f, hashFile.string, fmRead):
let oldHash = parseSecureHash(f.readLine()) 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 # 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: if CfileFlag.Cached notin conf.toCompile[mainFileIdx].flags:
let mainObjFile = getObjFilePath(conf, conf.toCompile[mainFileIdx]) let mainObjFile = getObjFilePath(conf, conf.toCompile[mainFileIdx])
var src = conf.hcrLinkTargetName(mainObjFile, true) let src = conf.hcrLinkTargetName(mainObjFile, true)
var dst = conf.prepareToWriteOutput let dst = conf.prepareToWriteOutput
copyFileWithPermissions(src.string, dst.string) copyFileWithPermissions(src.string, dst.string)
else: else:
for x in conf.toCompile: for x in conf.toCompile:
@ -933,20 +933,15 @@ proc callCCompiler*(conf: ConfigRef) =
script.add("\n") script.add("\n")
generateScript(conf, script) generateScript(conf, script)
#from json import escapeJson
import json, std / sha1
template hashNimExe(): string = $secureHashFile(os.getAppFilename()) template hashNimExe(): string = $secureHashFile(os.getAppFilename())
proc writeJsonBuildInstructions*(conf: ConfigRef) = proc writeJsonBuildInstructions*(conf: ConfigRef) =
template lit(x: untyped) = f.write x template lit(x: string) = f.write x
template str(x: untyped) = template str(x: string) =
when compiles(escapeJson(x, buf)): buf.setLen 0
buf.setLen 0 escapeJson(x, buf)
escapeJson(x, buf) f.write buf
f.write buf
else:
f.write escapeJson(x)
proc cfiles(conf: ConfigRef; f: File; buf: var string; clist: CfileList, isExternal: bool) = proc cfiles(conf: ConfigRef; f: File; buf: var string; clist: CfileList, isExternal: bool) =
var comma = false var comma = false
@ -982,7 +977,7 @@ proc writeJsonBuildInstructions*(conf: ConfigRef) =
pastStart = true pastStart = true
lit "\L" lit "\L"
proc depfiles(conf: ConfigRef; f: File) = proc depfiles(conf: ConfigRef; f: File; buf: var string) =
var i = 0 var i = 0
for it in conf.m.fileInfos: for it in conf.m.fileInfos:
let path = it.fullPath.string let path = it.fullPath.string
@ -1034,7 +1029,7 @@ proc writeJsonBuildInstructions*(conf: ConfigRef) =
lit ",\L\"cmdline\": " lit ",\L\"cmdline\": "
str conf.commandLine str conf.commandLine
lit ",\L\"depfiles\":[\L" lit ",\L\"depfiles\":[\L"
depfiles(conf, f) depfiles(conf, f, buf)
lit "],\L\"nimexe\": \L" lit "],\L\"nimexe\": \L"
str hashNimExe() str hashNimExe()
lit "\L" lit "\L"