installerscript.nim: quoting

This commit is contained in:
Anna “CyberTailor” 2022-07-03 16:28:06 +05:00
parent 8ff9819dae
commit 001edf960a
Signed by: CyberTaIlor
GPG Key ID: E7B76EDC50864BB1

View File

@ -6,19 +6,29 @@ import os, strformat
import common, options, packageinfo
proc writeCpFile(f: File, source, dest: string) =
f.write(&"""echo "-- Installing " & destDir & "{dest}"""")
f.write('\n')
f.write(&"""cpFile("{source}", destDir & "{dest}")""")
f.write('\n')
f.write(&"echo \"-- Installing: \" & destDir & {dest.tripleQuoted}\n")
f.write(&"cpFile({source.tripleQuoted}, destDir & {dest.tripleQuoted})\n")
proc writeMkDir(f: File, dir: string) =
f.write(&"""mkDir(destDir & "{dir}")""")
f.write('\n')
f.write(&"echo \"-- Installing: \" & destDir & {dir.tripleQuoted}\n")
f.write(&"mkDir(destDir & {dir.tripleQuoted})\n")
proc makeExecutable(f: File, dest: string) =
f.write("if chmod.len != 0:\n")
f.write(&""" exec(chmod & " +x " & destDir & "{dest}")""")
f.write('\n')
proc writeChmod(f: File, dest: string) =
f.write(&"if chmod.len != 0:\n")
f.write(&" exec(quoteShellCommand([chmod, \"+x\", destDir & {dest.tripleQuoted}]))\n")
proc writeBinInstaller(f: File, pkgInfo: PackageInfo, options: Options) =
f.write("""
import os
let chmod = findExe("chmod")
""")
f.writeMkDir(options.getBinDir())
for bin in pkgInfo.bin:
let binWithExt = bin.lastPathPart.addFileExt(ExeExt)
f.writeCpFile(binWithExt, options.getBinDir() / binWithExt)
f.writeChmod(options.getBinDir() / binWithExt)
proc writeInstallerScript*(f: File, pkgInfo: PackageInfo, options: Options) =
f.write("""#!/usr/bin/env nim e
@ -35,7 +45,7 @@ let destDir = getEnv("DESTDIR")
if fileExists(nimbleMeta):
f.writeCpFile(nimbleMeta, packageDir / packageMetadataFileName)
let offset = pkgInfo.getSourceDir(options).len
let offset = pkgInfo.getSourceDir(options).len # length of source root
for entry in pkgInfo.getInstallFiles(options):
let dest = packageDir / entry.path.substr(offset)
case entry.kind
@ -46,14 +56,5 @@ let destDir = getEnv("DESTDIR")
f.writeCpFile(entry.path, dest)
else: continue
if pkgInfo.bin.len == 0:
return
f.write('\n')
f.write("""let chmod = findExe("chmod")""")
f.write('\n')
f.writeMkDir(options.getBinDir())
for bin in pkgInfo.bin:
let binWithExt = bin.lastPathPart.addFileExt(ExeExt)
f.writeCpFile(binWithExt, options.getBinDir() / binWithExt)
f.makeExecutable(options.getBinDir() / binWithExt)
if pkgInfo.bin.len != 0:
f.writeBinInstaller(pkgInfo, options)