externalToLink: use quoteShell to avoid issues with spaces in paths for {.link.} pragmas (#17875)

This commit is contained in:
Timothee Cour 2021-04-29 00:01:00 -07:00 • committed by GitHub
commit 927ae26fad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -943,6 +943,7 @@ proc jsonBuildInstructionsFile*(conf: ConfigRef): AbsoluteFile =
result = getNimcacheDir(conf) / conf.outFile.changeFileExt("json") result = getNimcacheDir(conf) / conf.outFile.changeFileExt("json")
proc writeJsonBuildInstructions*(conf: ConfigRef) = proc writeJsonBuildInstructions*(conf: ConfigRef) =
# xxx use std/json instead, will result in simpler, more maintainable code.
template lit(x: string) = f.write x template lit(x: string) = f.write x
template str(x: string) = template str(x: string) =
buf.setLen 0 buf.setLen 0
@ -964,23 +965,18 @@ proc writeJsonBuildInstructions*(conf: ConfigRef) =
proc linkfiles(conf: ConfigRef; f: File; buf, objfiles: var string; clist: CfileList; proc linkfiles(conf: ConfigRef; f: File; buf, objfiles: var string; clist: CfileList;
llist: seq[string]) = llist: seq[string]) =
var pastStart = false var pastStart = false
template impl(path) =
let path2 = quoteShell(path)
objfiles.add(' ')
objfiles.add(path2)
if pastStart: lit ",\L"
str path2
pastStart = true
for it in llist: for it in llist:
let objfile = if noAbsolutePaths(conf): it.extractFilename let objfile = if noAbsolutePaths(conf): it.extractFilename else: it
else: it impl(addFileExt(objfile, CC[conf.cCompiler].objExt))
let objstr = addFileExt(objfile, CC[conf.cCompiler].objExt)
objfiles.add(' ')
objfiles.add(objstr)
if pastStart: lit ",\L"
str objstr
pastStart = true
for it in clist: for it in clist:
let objstr = quoteShell(it.obj) impl(it.obj)
objfiles.add(' ')
objfiles.add(objstr)
if pastStart: lit ",\L"
str objstr
pastStart = true
lit "\L" lit "\L"
proc depfiles(conf: ConfigRef; f: File; buf: var string) = proc depfiles(conf: ConfigRef; f: File; buf: var string) =