# # # Maintenance program for Nim # (c) Copyright 2017 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. # # See doc/koch.txt for documentation. # when defined(gcc) and defined(windows): when defined(x86): {.link: "icons/koch.res".} else: {.link: "icons/koch_icon.o".} when defined(amd64) and defined(windows) and defined(vcc): {.link: "icons/koch-amd64-windows-vcc.res" .} when defined(i386) and defined(windows) and defined(vcc): {.link: "icons/koch-i386-windows-vcc.res" .} import os, strutils, parseopt, osproc, streams const VersionAsString = system.NimVersion const HelpText = """ +-----------------------------------------------------------------+ | Maintenance program for Nim | | Version $1| | (c) 2017 Andreas Rumpf | +-----------------------------------------------------------------+ Build time: $2, $3 Usage: koch [options] command [options for command] Options: --help, -h shows this help and quits Possible Commands: boot [options] bootstraps with given command line options distrohelper [bindir] helper for distro packagers tools builds Nim related tools nimble builds the Nimble tool Boot options: -d:release produce a release version of the compiler -d:useLinenoise use the linenoise library for interactive mode (not needed on Windows) -d:avoidTimeMachine only for Mac OS X, excludes nimcache dir from backups Commands for core developers: web [options] generates the website and the full documentation website [options] generates only the website csource -d:release builds the C sources for installation pdf builds the PDF documentation zip builds the installation zip package xz builds the installation tar.xz package testinstall test tar.xz package; Unix only! tests [options] run the testsuite temp options creates a temporary compiler for testing winrelease creates a Windows release pushcsource push generated C sources to its repo Web options: --googleAnalytics:UA-... add the given google analytics code to the docs. To build the official docs, use UA-48159761-1 """ const gaCode = " --googleAnalytics:UA-48159761-1" proc exe(f: string): string = result = addFileExt(f, ExeExt) when defined(windows): result = result.replace('/','\\') template withDir(dir, body) = let old = getCurrentDir() try: setCurrentDir(dir) body finally: setCurrentdir(old) proc findNim(): string = var nim = "nim".exe result = "bin" / nim if existsFile(result): return for dir in split(getEnv("PATH"), PathSep): if existsFile(dir / nim): return dir / nim # assume there is a symlink to the exe or something: return nim proc exec(cmd: string, errorcode: int = QuitFailure, additionalPath = "") = let prevPath = getEnv("PATH") if additionalPath.len > 0: var absolute = additionalPATH if not absolute.isAbsolute: absolute = getCurrentDir() / absolute echo("Adding to $PATH: ", absolute) putEnv("PATH", prevPath & PathSep & absolute) echo(cmd) if execShellCmd(cmd) != 0: quit("FAILURE", errorcode) putEnv("PATH", prevPath) proc nimexec(cmd: string) = exec findNim() & " " & cmd proc execCleanPath(cmd: string, additionalPath = ""; errorcode: int = QuitFailure) = # simulate a poor man's virtual environment let prevPath = getEnv("PATH") when defined(windows): let CleanPath = r"$1\system32;$1;$1\System32\Wbem" % getEnv"SYSTEMROOT" else: const CleanPath = r"/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin" putEnv("PATH", CleanPath & PathSep & additionalPath) echo(cmd) if execShellCmd(cmd) != 0: quit("FAILURE", errorcode) putEnv("PATH", prevPath) proc testUnixInstall() = let oldCurrentDir = getCurrentDir() try: let destDir = getTempDir() copyFile("build/nim-$1.tar.xz" % VersionAsString, destDir / "nim-$1.tar.xz" % VersionAsString) setCurrentDir(destDir) execCleanPath("tar -xJf nim-$1.tar.xz" % VersionAsString) setCurrentDir("nim-$1" % VersionAsString) execCleanPath("sh build.sh") # first test: try if './bin/nim --version' outputs something sane: let output = execProcess("./bin/nim --version").splitLines if output.len > 0 and output[0].contains(VersionAsString): echo "Version check: success" execCleanPath("./bin/nim c koch.nim") execCleanPath("./koch boot -d:release", destDir / "bin") # check the docs build: execCleanPath("./koch web", destDir / "bin") # check nimble builds: execCleanPath("./koch tools") # check the tests work: execCleanPath("./koch tests", destDir / "bin") else: echo "Version check: failure" finally: setCurrentDir oldCurrentDir proc tryExec(cmd: string): bool = echo(cmd) result = execShellCmd(cmd) == 0 proc safeRemove(filename: string) = if existsFile(filename): removeFile(filename) proc overwriteFile(source, dest: string) = safeRemove(dest) moveFile(source, dest) proc copyExe(source, dest: string) = safeRemove(dest) copyFile(dest=dest, source=source) inclFilePermissions(dest, {fpUserExec}) const compileNimInst = "tools/niminst/niminst" proc csource(args: string) = nimexec(("cc $1 -r $3 --var:version=$2 --var:mingw=none csource " & "--main:compiler/nim.nim compiler/installer.ini $1") % [args, VersionAsString, compileNimInst]) proc bundleNimbleSrc() = ## bunldeNimbleSrc() bundles a specific Nimble commit with the tarball. We ## always bundle the latest official release. if not dirExists("dist/nimble/.git"): exec("git clone https://github.com/nim-lang/nimble.git dist/ni
#!/bin/bash
# Regenerate html files.

set -e

( cd linkify; build; )

# generate html/$1.html using /tmp/tags
process() {
  rm -f html/$1.html
  convert_html $1
  linkify/linkify /tmp/tags html/$1.html
  mv html/$1.html.out html/$1.html
}

URL_BASE='https://github.com/akkartik/mu/blob/master'

convert_html() {
  vim -c "set number" -c TOhtml -c write -c qall $1

  sed -i 's,<title>.*/mu/,<title>Mu - ,' $1.html
  sed -i 's,\.html</title>,</title>,' $1.html

  sed -i "/^<body/a <a href='$URL_BASE/$1'>$URL_BASE/$1</a>" $1.html

  sed -i 's/^\* { \(.*\) }/* { font-size:12pt; \1 }/g' $1.html
  sed -i 's/^body { \(.*\) }/body { font-size:12pt; \1 }/g' $1.html

  sed -i '/^body {/a a { color:inherit; }' $1.html

  # switch unicode characters around in the rendered html
  #   the ones we have in the source files render double-wide in html
  #   the ones we want in the html cause iTerm2 to slow down in alt-tabbing for some reason
  # the following commands give us the best of both worlds
  sed -i -e 's/┈/╌/g' -e 's/┊/╎/g' $1.html

  mv -i $1.html html/`dirname $1`
}

ctags -x *.cc  |grep -v "^operator \| member \| variable "  > /tmp/tags
for f in *.cc
do
  process $f
done

ctags -x [0-9]*.mu  > /tmp/tags
for f in [0-9]*.mu
do
  process $f
done

for f in [a-zA-Z]*.mu
do
  ctags -x [0-9]*.mu $f  > /tmp/tags
  process $f
done

( cd edit
  ctags -x ../[0-9]*.mu *.mu  > /tmp/tags
)
for f in edit/*.mu
do
  process $f
done

( cd subx
  ctags -x *.cc  |grep -v '^. '  > /tmp/tags  # don't hyperlink every 'i' to the integer register variant
)
for f in subx/*.cc
do
  process $f
done

for f in subx/examples/*.subx
do
  ( cd subx/examples
    ctags -x `basename $f` > /tmp/tags
  )
  process $f
done

( cd subx
  ctags -x *.subx  > /tmp/tags