the installer can generate tar.gz

This commit is contained in:
Araq 2015-04-29 19:59:06 +02:00
commit 813a4f1d83
2 changed files with 70 additions and 18 deletions

View file

@ -106,6 +106,12 @@ proc zip(args: string) =
exec("$# --var:version=$# --var:mingw=none --main:compiler/nim.nim zip compiler/installer.ini" % exec("$# --var:version=$# --var:mingw=none --main:compiler/nim.nim zip compiler/installer.ini" %
["tools/niminst/niminst".exe, VersionAsString]) ["tools/niminst/niminst".exe, VersionAsString])
proc targz(args: string) =
exec("$3 cc -r $2 --var:version=$1 --var:mingw=none --main:compiler/nim.nim scripts compiler/installer.ini" %
[VersionAsString, compileNimInst, findNim()])
exec("$# --var:version=$# --var:mingw=none --main:compiler/nim.nim targz compiler/installer.ini" %
["tools" / "niminst" / "niminst".exe, VersionAsString])
proc buildTool(toolname, args: string) = proc buildTool(toolname, args: string) =
exec("$# cc $# $#" % [findNim(), args, toolname]) exec("$# cc $# $#" % [findNim(), args, toolname])
copyFile(dest="bin"/ splitFile(toolname).name.exe, source=toolname.exe) copyFile(dest="bin"/ splitFile(toolname).name.exe, source=toolname.exe)
@ -118,7 +124,7 @@ proc nsis(args: string) =
exec "nim c compiler" / "nim.nim" exec "nim c compiler" / "nim.nim"
copyExe("compiler/nim".exe, "bin/nim_debug".exe) copyExe("compiler/nim".exe, "bin/nim_debug".exe)
exec(("tools" / "niminst" / "niminst --var:version=$# --var:mingw=mingw$#" & exec(("tools" / "niminst" / "niminst --var:version=$# --var:mingw=mingw$#" &
" nsis compiler/nim") % [VersionAsString, $(sizeof(pointer)*8)]) " nsis compiler/installer.ini") % [VersionAsString, $(sizeof(pointer)*8)])
proc install(args: string) = proc install(args: string) =
exec("$# cc -r $# --var:version=$# --var:mingw=none --main:compiler/nim.nim scripts compiler/installer.ini" % exec("$# cc -r $# --var:version=$# --var:mingw=none --main:compiler/nim.nim scripts compiler/installer.ini" %
@ -308,12 +314,14 @@ proc winRelease() =
#buildTool("tools/niminst/niminst", " -d:release") #buildTool("tools/niminst/niminst", " -d:release")
buildTool("tools/nimgrep", " -d:release") buildTool("tools/nimgrep", " -d:release")
buildTool("compiler/nimfix/nimfix", " -d:release") buildTool("compiler/nimfix/nimfix", " -d:release")
buildTool("compiler/nimsuggest/nimsuggest", " -d:release")
#run7z("win32", "bin/nim.exe", "bin/c2nim.exe", "bin/nimgrep.exe",
# "bin/nimfix.exe",
# "bin/nimble.exe", "bin/*.dll",
# "config", "dist/*.dll", "examples", "lib",
# "readme.txt", "contributors.txt", "copying.txt")
run7z("win32", "bin/nim.exe", "bin/c2nim.exe", "bin/nimgrep.exe",
"bin/nimfix.exe",
"bin/nimble.exe", "bin/*.dll",
"config", "dist/*.dll", "examples", "lib",
"readme.txt", "contributors.txt", "copying.txt")
# second step: XXX build 64 bit version # second step: XXX build 64 bit version
# -------------- tests -------------------------------------------------------- # -------------- tests --------------------------------------------------------
@ -357,6 +365,7 @@ of cmdArgument:
of "pdf": pdf() of "pdf": pdf()
of "csource", "csources": csource(op.cmdLineRest) of "csource", "csources": csource(op.cmdLineRest)
of "zip": zip(op.cmdLineRest) of "zip": zip(op.cmdLineRest)
of "targz": targz(op.cmdLineRest)
of "nsis": nsis(op.cmdLineRest) of "nsis": nsis(op.cmdLineRest)
of "install": install(op.cmdLineRest) of "install": install(op.cmdLineRest)
of "test", "tests": tests(op.cmdLineRest) of "test", "tests": tests(op.cmdLineRest)

View file

@ -35,6 +35,7 @@ type
actionNsis, # action: create NSIS installer actionNsis, # action: create NSIS installer
actionScripts # action: create install and deinstall scripts actionScripts # action: create install and deinstall scripts
actionZip, # action: create zip file actionZip, # action: create zip file
actionTargz, # action: create targz file
actionDeb # action: prepare deb package actionDeb # action: prepare deb package
FileCategory = enum FileCategory = enum
@ -171,6 +172,7 @@ proc parseCmdLine(c: var ConfigData) =
of "csource": incl(c.actions, actionCSource) of "csource": incl(c.actions, actionCSource)
of "scripts": incl(c.actions, actionScripts) of "scripts": incl(c.actions, actionScripts)
of "zip": incl(c.actions, actionZip) of "zip": incl(c.actions, actionZip)
of "targz": incl(c.actions, actionTargz)
of "inno": incl(c.actions, actionInno) of "inno": incl(c.actions, actionInno)
of "nsis": incl(c.actions, actionNsis) of "nsis": incl(c.actions, actionNsis)
of "deb": incl(c.actions, actionDeb) of "deb": incl(c.actions, actionDeb)
@ -181,10 +183,10 @@ proc parseCmdLine(c: var ConfigData) =
break break
of cmdLongoption, cmdShortOption: of cmdLongoption, cmdShortOption:
case normalize(key.string) case normalize(key.string)
of "help", "h": of "help", "h":
stdout.write(Usage) stdout.write(Usage)
quit(0) quit(0)
of "version", "v": of "version", "v":
stdout.write(Version & "\n") stdout.write(Version & "\n")
quit(0) quit(0)
of "o", "output": c.outdir = val of "o", "output": c.outdir = val
@ -240,7 +242,7 @@ proc incl(s: var seq[string], x: string): int =
for i in 0.. <s.len: for i in 0.. <s.len:
if cmpIgnoreStyle(s[i], x) == 0: return i if cmpIgnoreStyle(s[i], x) == 0: return i
s.add(x) s.add(x)
result = s.len-1 result = s.len-1
proc platforms(c: var ConfigData, v: string) = proc platforms(c: var ConfigData, v: string) =
for line in splitLines(v): for line in splitLines(v):
@ -277,17 +279,17 @@ proc parseIniFile(c: var ConfigData) =
of "name": c.name = v of "name": c.name = v
of "displayname": c.displayName = v of "displayname": c.displayName = v
of "version": c.version = v of "version": c.version = v
of "os": of "os":
c.oses = split(v, {';'}) c.oses = split(v, {';'})
hasCpuOs = true hasCpuOs = true
if c.explicitPlatforms: if c.explicitPlatforms:
quit(errorStr(p, "you cannot have both 'platforms' and 'os'")) quit(errorStr(p, "you cannot have both 'platforms' and 'os'"))
of "cpu": of "cpu":
c.cpus = split(v, {';'}) c.cpus = split(v, {';'})
hasCpuOs = true hasCpuOs = true
if c.explicitPlatforms: if c.explicitPlatforms:
quit(errorStr(p, "you cannot have both 'platforms' and 'cpu'")) quit(errorStr(p, "you cannot have both 'platforms' and 'cpu'"))
of "platforms": of "platforms":
platforms(c, v) platforms(c, v)
c.explicitPlatforms = true c.explicitPlatforms = true
if hasCpuOs: if hasCpuOs:
@ -389,7 +391,7 @@ proc readCFiles(c: var ConfigData, osA, cpuA: int) =
of cfgKeyValuePair: of cfgKeyValuePair:
case section case section
of "ccompiler": pathFlags(p, k.key, k.value, c.ccompiler) of "ccompiler": pathFlags(p, k.key, k.value, c.ccompiler)
of "linker": of "linker":
pathFlags(p, k.key, k.value, c.linker) pathFlags(p, k.key, k.value, c.linker)
# HACK: we conditionally add ``-lm -ldl``, so remove them from the # HACK: we conditionally add ``-lm -ldl``, so remove them from the
# linker flags: # linker flags:
@ -558,28 +560,67 @@ when haveZipLib:
else: else:
quit("Cannot open for writing: " & n) quit("Cannot open for writing: " & n)
proc targzDist(c: var ConfigData) =
let proj = toLower(c.name) & "-" & c.version
var n = "$#.tar.gz" % proj
let tmpDir = if c.outdir.len == 0: "build" else: c.outdir
template processFile(z, dest, src) =
let s = src
let d = dest
echo "Copying ", s, " to ", tmpDir / d
let destdir = tmpdir / d.splitFile.dir
if not dirExists(destdir): createDir(destdir)
copyFile(s, tmpDir / d)
processFile(z, proj / buildBatFile32, "build" / buildBatFile32)
processFile(z, proj / buildBatFile64, "build" / buildBatFile64)
processFile(z, proj / buildShFile, "build" / buildShFile)
processFile(z, proj / makeFile, "build" / makeFile)
processFile(z, proj / installShFile, installShFile)
processFile(z, proj / deinstallShFile, deinstallShFile)
for f in walkFiles(c.libpath / "lib/*.h"):
processFile(z, proj / "c_code" / extractFilename(f), f)
for osA in 1..c.oses.len:
for cpuA in 1..c.cpus.len:
var dir = buildDir(osA, cpuA)
for k, f in walkDir("build" / dir):
if k == pcFile: processFile(z, proj / dir / extractFilename(f), f)
for cat in items({fcConfig..fcOther, fcUnix}):
for f in items(c.cat[cat]): processFile(z, proj / f, f)
let oldDir = getCurrentDir()
setCurrentDir(tmpDir)
try:
if execShellCmd("7z a -ttar $1.tar $1" % proj) != 0 or
execShellCmd("7z a -tgzip $1.tar.gz $1.tar" % proj) != 0:
echo("External program failed")
finally:
setCurrentDir(oldDir)
# -- prepare build files for .deb creation # -- prepare build files for .deb creation
proc debDist(c: var ConfigData) = proc debDist(c: var ConfigData) =
if not existsFile(getOutputDir(c) / "build.sh"): quit("No build.sh found.") if not existsFile(getOutputDir(c) / "build.sh"): quit("No build.sh found.")
if not existsFile(getOutputDir(c) / "install.sh"): quit("No install.sh found.") if not existsFile(getOutputDir(c) / "install.sh"): quit("No install.sh found.")
if c.debOpts.shortDesc == "": quit("shortDesc must be set in the .ini file.") if c.debOpts.shortDesc == "": quit("shortDesc must be set in the .ini file.")
if c.debOpts.licenses.len == 0: if c.debOpts.licenses.len == 0:
echo("[Warning] No licenses specified for .deb creation.") echo("[Warning] No licenses specified for .deb creation.")
# -- Copy files into /tmp/.. # -- Copy files into /tmp/..
echo("Copying source to tmp/niminst/deb/") echo("Copying source to tmp/niminst/deb/")
var currentSource = getCurrentDir() var currentSource = getCurrentDir()
var workingDir = getTempDir() / "niminst" / "deb" var workingDir = getTempDir() / "niminst" / "deb"
var upstreamSource = (c.name.toLower() & "-" & c.version) var upstreamSource = (c.name.toLower() & "-" & c.version)
createDir(workingDir / upstreamSource) createDir(workingDir / upstreamSource)
template copyNimDist(f, dest: string): stmt = template copyNimDist(f, dest: string): stmt =
createDir((workingDir / upstreamSource / dest).splitFile.dir) createDir((workingDir / upstreamSource / dest).splitFile.dir)
copyFile(currentSource / f, workingDir / upstreamSource / dest) copyFile(currentSource / f, workingDir / upstreamSource / dest)
# Don't copy all files, only the ones specified in the config: # Don't copy all files, only the ones specified in the config:
copyNimDist(buildShFile, buildShFile) copyNimDist(buildShFile, buildShFile)
copyNimDist(makeFile, makeFile) copyNimDist(makeFile, makeFile)
@ -624,5 +665,7 @@ if actionZip in c.actions:
zipDist(c) zipDist(c)
else: else:
quit("libzip is not installed") quit("libzip is not installed")
if actionTargz in c.actions:
targzDist(c)
if actionDeb in c.actions: if actionDeb in c.actions:
debDist(c) debDist(c)