summary refs log tree commit diff stats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/finish.nim2
-rw-r--r--tools/nimgrep.nim46
-rw-r--r--tools/niminst/buildsh.tmpl2
-rw-r--r--tools/niminst/makefile.tmpl61
-rw-r--r--tools/niminst/niminst.nim2
-rw-r--r--tools/nimpretty.nim5
-rw-r--r--tools/nimresolve.nim158
-rw-r--r--tools/nimweb.nim4
8 files changed, 60 insertions, 220 deletions
diff --git a/tools/finish.nim b/tools/finish.nim
index 45d7dd3a8..207f15f76 100644
--- a/tools/finish.nim
+++ b/tools/finish.nim
@@ -32,7 +32,7 @@ proc downloadMingw(): DownloadResult =
   let curl = findExe"curl"
   var cmd: string
   if curl.len > 0:
-    cmd = curl & " --out " & "dist" / mingw & " " & url
+    cmd = quoteShell(curl) & " --out " & "dist" / mingw & " " & url
   elif fileExists"bin/nimgrab.exe":
     cmd = "bin/nimgrab.exe " & url & " dist" / mingw
   if cmd.len > 0:
diff --git a/tools/nimgrep.nim b/tools/nimgrep.nim
index 8dff722ec..e9c1b26fa 100644
--- a/tools/nimgrep.nim
+++ b/tools/nimgrep.nim
@@ -45,6 +45,9 @@ type
   TOptions = set[TOption]
   TConfirmEnum = enum
     ceAbort, ceYes, ceAll, ceNo, ceNone
+  Pattern = Regex | Peg
+
+using pattern: Pattern
 
 var
   filenames: seq[string] = @[]
@@ -118,7 +121,7 @@ proc highlight(s, match, repl: string, t: tuple[first, last: int],
     stdout.write("\n")
     stdout.flushFile()
 
-proc processFile(filename: string) =
+proc processFile(pattern; filename: string) =
   var filenameShown = false
   template beforeHighlight =
     if not filenameShown and optVerbose notin options:
@@ -135,18 +138,8 @@ proc processFile(filename: string) =
   if optVerbose in options:
     stdout.writeLine(filename)
     stdout.flushFile()
-  var pegp: Peg
-  var rep: Regex
   var result: string
 
-  if optRegex in options:
-    if {optIgnoreCase, optIgnoreStyle} * options != {}:
-      rep = re(pattern, {reExtended, reIgnoreCase})
-    else:
-      rep = re(pattern)
-  else:
-    pegp = peg(pattern)
-
   if optReplace in options:
     result = newStringOfCap(buffer.len)
 
@@ -156,11 +149,7 @@ proc processFile(filename: string) =
   for j in 0..high(matches): matches[j] = ""
   var reallyReplace = true
   while i < buffer.len:
-    var t: tuple[first, last: int]
-    if optRegex notin options:
-      t = findBounds(buffer, pegp, matches, i)
-    else:
-      t = findBounds(buffer, rep, matches, i)
+    let t = findBounds(buffer, pattern, matches, i)
     if t.first < 0: break
     inc(line, countLines(buffer, i, t.first-1))
 
@@ -170,11 +159,7 @@ proc processFile(filename: string) =
     if optReplace notin options:
       highlight(buffer, wholeMatch, "", t, line, showRepl=false)
     else:
-      var r: string
-      if optRegex notin options:
-        r = replace(wholeMatch, pegp, replacement % matches)
-      else:
-        r = replace(wholeMatch, rep, replacement % matches)
+      let r = replace(wholeMatch, pattern, replacement % matches)
       if optConfirm in options:
         highlight(buffer, wholeMatch, r, t, line, showRepl=true)
         case confirm()
@@ -246,17 +231,17 @@ proc styleInsensitive(s: string): string =
         addx()
     else: addx()
 
-proc walker(dir: string) =
+proc walker(pattern; dir: string) =
   for kind, path in walkDir(dir):
     case kind
     of pcFile:
       if extensions.len == 0 or path.hasRightExt(extensions):
-        processFile(path)
+        processFile(pattern, path)
     of pcDir:
       if optRecursive in options:
-        walker(path)
+        walker(pattern, path)
     else: discard
-  if existsFile(dir): processFile(dir)
+  if existsFile(dir): processFile(pattern, dir)
 
 proc writeHelp() =
   stdout.write(Usage)
@@ -332,11 +317,18 @@ else:
       pattern = "\\y " & pattern
     elif optIgnoreCase in options:
       pattern = "\\i " & pattern
+    let pegp = peg(pattern)
+    for f in items(filenames):
+      walker(pegp, f)
   else:
+    var reflags = {reStudy, reExtended}
     if optIgnoreStyle in options:
       pattern = styleInsensitive(pattern)
     if optWord in options:
       pattern = r"\b (:?" & pattern & r") \b"
-  for f in items(filenames):
-    walker(f)
+    if {optIgnoreCase, optIgnoreStyle} * options != {}:
+      reflags.incl reIgnoreCase
+    let rep = re(pattern, reflags)
+    for f in items(filenames):
+      walker(rep, f)
 
diff --git a/tools/niminst/buildsh.tmpl b/tools/niminst/buildsh.tmpl
index ec20566ac..3e7d8ae6e 100644
--- a/tools/niminst/buildsh.tmpl
+++ b/tools/niminst/buildsh.tmpl
@@ -144,6 +144,8 @@ case $ucpu in
       mycpu="sparc64"
     fi
     ;;
+  *ppc64le* )
+    mycpu="powerpc64el" ;;
   *ppc64* )
     if [ "$myos" = "linux" ] ; then
       COMP_FLAGS="$COMP_FLAGS -m64"
diff --git a/tools/niminst/makefile.tmpl b/tools/niminst/makefile.tmpl
index 4a20680e0..891333251 100644
--- a/tools/niminst/makefile.tmpl
+++ b/tools/niminst/makefile.tmpl
@@ -4,10 +4,10 @@
 #           "# Template is in tools/niminst/makefile.tmpl\n" &
 #           "# To regenerate run ``niminst csource`` or ``koch csource``\n"
 
-CC = gcc
-LINKER = gcc
-COMP_FLAGS = $(CPPFLAGS) $(CFLAGS) ?{c.ccompiler.flags}
-LINK_FLAGS = $(LDFLAGS) ?{c.linker.flags}
+CC ??= gcc
+LD ??= gcc
+CFLAGS += -Ic_code ?{c.ccompiler.flags}
+LDFLAGS += ?{c.linker.flags}
 binDir = ?{firstBinPath(c).toUnix}
 
 koch := $(shell sh -c 'test -s ../koch.nim && echo "yes"')
@@ -17,63 +17,57 @@ endif
 
 ucpu := $(shell sh -c 'uname -m | tr "[:upper:]" "[:lower:]"')
 uos := $(shell sh -c 'uname | tr "[:upper:]" "[:lower:]"')
-uosname := $(shell sh -c 'uname -o | tr "[:upper:]" "[:lower:]"')
 
 ifeq ($(uos),linux)
   myos = linux
-  LINK_FLAGS += -ldl -lm
+  LDFLAGS += -ldl -lm
 endif
 ifeq ($(uos),dragonfly)
   myos = freebsd
-  LINK_FLAGS += -lm
+  LDFLAGS += -lm
 endif
 ifeq ($(uos),freebsd)
   myos= freebsd
   CC = clang
-  LINKER = clang
-  LINK_FLAGS += -lm
+  LD = clang
+  LDFLAGS += -lm
 endif
 ifeq ($(uos),openbsd)
   myos = openbsd
-  LINK_FLAGS += -lm
+  LDFLAGS += -lm
 endif
 ifeq ($(uos),netbsd)
   myos = netbsd
-  LINK_FLAGS += -lm
+  LDFLAGS += -lm
 endif
 ifeq ($(uos),darwin)
   myos = macosx
   CC = clang
-  LINKER = clang
-  LINK_FLAGS += -ldl -lm
+  LD = clang
+  LDFLAGS += -ldl -lm
   ifeq ($(HOSTTYPE),x86_64)
     ucpu = amd64
   endif
 endif
 ifeq ($(uos),aix)
   myos = aix
-  LINK_FLAGS += -dl -lm
+  LDFLAGS += -dl -lm
 endif
 ifeq ($(uos),solaris)
   myos = solaris
-  LINK_FLAGS += -ldl -lm -lsocket -lnsl
+  LDFLAGS += -ldl -lm -lsocket -lnsl
 endif
 ifeq ($(uos),sun)
   myos = solaris
-  LINK_FLAGS += -ldl -lm -lsocket -lnsl
+  LDFLAGS += -ldl -lm -lsocket -lnsl
 endif
 ifeq ($(uos),haiku)
   myos = haiku
 endif
-ifndef uos
+ifndef myos
   $(error unknown operating system: $(uos))
 endif
 
-ifeq ($(uosname),android)
-  myos = android
-  LINK_FLAGS += -landroid-glob
-endif
-
 ifeq ($(ucpu),i386)
   mycpu = i386
 endif
@@ -107,11 +101,14 @@ endif
 ifeq ($(ucpu),sun)
   mycpu = sparc
 endif
+ifeq ($(ucpu),ppc64le)
+  mycpu = powerpc64el
+endif
 ifeq ($(ucpu),ppc64)
   mycpu = powerpc64
   ifeq ($(myos),linux)
-    COMP_FLAGS += -m64
-    LINK_FLAGS += -m64
+    CFLAGS += -m64
+    LDFLAGS += -m64
   endif
 endif
 ifeq ($(ucpu),powerpc)
@@ -138,7 +135,16 @@ endif
 ifeq ($(ucpu),armv6l)
   mycpu = arm
 endif
-ifndef ucpu
+ifeq ($(ucpu),armv7l)
+  mycpu = arm
+endif
+ifeq ($(ucpu),armv7hl)
+  mycpu = arm
+endif
+ifeq ($(ucpu),aarch64)
+  mycpu = arm64
+endif
+ifndef mycpu
   $(error unknown processor: $(ucpu))
 endif
 
@@ -160,12 +166,9 @@ ifeq ($(strip $(oFiles)),)
   $(error no C code generated for: [$(myos): $(mycpu)])
 endif
 
-%.o: %.c
-	$(CC) $(COMP_FLAGS) -Ic_code -c $< -o $@
-
 ?{"$(binDir)/" & toLowerAscii(c.name)}: $(oFiles)
 	@mkdir -p $(binDir)
-	$(LINKER) -o $@ $^ $(LINK_FLAGS)
+	$(LD) -o $@ $^ $(LDFLAGS)
 	@echo "SUCCESS"
 
 .PHONY: clean
diff --git a/tools/niminst/niminst.nim b/tools/niminst/niminst.nim
index e4568dc3a..9c15326b0 100644
--- a/tools/niminst/niminst.nim
+++ b/tools/niminst/niminst.nim
@@ -283,7 +283,7 @@ proc yesno(p: var CfgParser, v: string): bool =
   else: quit(errorStr(p, "unknown value; use: yes|no"))
 
 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
   s.add(x)
   result = s.len-1
diff --git a/tools/nimpretty.nim b/tools/nimpretty.nim
index 2c967b1e8..36d1382cf 100644
--- a/tools/nimpretty.nim
+++ b/tools/nimpretty.nim
@@ -42,7 +42,8 @@ proc writeVersion() =
 proc prettyPrint(infile: string) =
   let fileIdx = fileInfoIdx(infile)
   let tree = parseFile(fileIdx, newIdentCache())
-  renderModule(tree, infile, {})
+  let outfile = changeFileExt(infile, ".pretty.nim")
+  renderModule(tree, infile, outfile, {})
 
 proc main =
   var infile: string
@@ -50,7 +51,7 @@ proc main =
   for kind, key, val in getopt():
     case kind
     of cmdArgument:
-      infile = key
+      infile = key.addFileExt(".nim")
     of cmdLongoption, cmdShortOption:
       case normalize(key)
       of "help", "h": writeHelp()
diff --git a/tools/nimresolve.nim b/tools/nimresolve.nim
deleted file mode 100644
index 9af24df5a..000000000
--- a/tools/nimresolve.nim
+++ /dev/null
@@ -1,158 +0,0 @@
-#
-#
-#           The Nim Compiler
-#        (c) Copyright 2017 Andreas Rumpf
-#
-#    See the file "copying.txt", included in this
-#    distribution, for details about the copyright.
-#
-
-## Standard tool that resolves import paths.
-
-import
-  os, strutils, parseopt
-
-import "../compiler/nimblecmd"
-
-# You can change these constants to build you own adapted resolver.
-const
-  considerParentDirs = not defined(noParentProjects)
-  considerNimbleDirs = not defined(noNimbleDirs)
-
-const
-  Version = "1.0"
-  Usage = "nimresolve - Nim Resolve Package Path Version " & Version & """
-
-  (c) 2017 Andreas Rumpf
-Usage:
-  nimresolve [options] package
-Options:
-  --source:FILE       the file that requests to resolve 'package'
-  --stdlib:PATH       the path to use for the standard library
-  --project:FILE      the main '.nim' file that was passed to the Nim compiler
-  --subdir:EXPR       the subdir part in: 'import $pkg / subdir'
-  --noNimblePath      do not search the Nimble path to resolve the package
-"""
-
-proc writeHelp() =
-  stdout.write(Usage)
-  stdout.flushFile()
-  quit(0)
-
-proc writeVersion() =
-  stdout.write(Version & "\n")
-  stdout.flushFile()
-  quit(0)
-
-type
-  Task = object
-    source, stdlib, subdir, project, pkg: string
-    noNimblePath: bool
-
-proc findInNimbleDir(t: Task; dir: string): bool =
-  var best = ""
-  var bestv = ""
-  for k, p in os.walkDir(dir, relative=true):
-    if k == pcDir and p.len > t.pkg.len+1 and
-        p[t.pkg.len] == '-' and p.startsWith(t.pkg):
-      let (_, a) = getPathVersion(p)
-      if bestv.len == 0 or bestv < a:
-        bestv = a
-        best = dir / p
-
-  if best.len > 0:
-    var f: File
-    if open(f, best / changeFileExt(t.pkg, ".nimble-link")):
-      # the second line contains what we're interested in, see:
-      # https://github.com/nim-lang/nimble#nimble-link
-      var override = ""
-      discard readLine(f, override)
-      discard readLine(f, override)
-      close(f)
-      if not override.isAbsolute():
-        best = best / override
-      else:
-        best = override
-  let f = if t.subdir.len == 0: t.pkg else: t.subdir
-  let res = addFileExt(best / f, "nim")
-  if best.len > 0 and fileExists(res):
-    echo res
-    result = true
-
-const stdlibDirs = [
-  "pure", "core", "arch",
-  "pure/collections",
-  "pure/concurrency", "impure",
-  "wrappers", "wrappers/linenoise",
-  "windows", "posix", "js"]
-
-proc resolve(t: Task) =
-  template attempt(a) =
-    let x = addFileExt(a, "nim")
-    if fileExists(x):
-      echo x
-      return
-
-  case t.pkg
-  of "stdlib":
-    if t.subdir.len == 0:
-      echo t.stdlib
-      return
-    else:
-      for candidate in stdlibDirs:
-        attempt(t.stdlib / candidate / t.subdir)
-  of "root":
-    let root = t.project.splitFile.dir
-    if t.subdir.len == 0:
-      echo root
-      return
-    else:
-      attempt(root / t.subdir)
-  else:
-    when considerParentDirs:
-      var p = parentDir(t.source.splitFile.dir)
-      # support 'import $karax':
-      let f = if t.subdir.len == 0: t.pkg else: t.subdir
-
-      while p.len > 0:
-        let dir = p / t.pkg
-        if dirExists(dir):
-          attempt(dir / f)
-          # 2nd attempt: try to use 'karax/karax'
-          attempt(dir / t.pkg / f)
-          # 3rd attempt: try to use 'karax/src/karax'
-          attempt(dir / "src" / f)
-          attempt(dir / "src" / t.pkg / f)
-        p = parentDir(p)
-
-    when considerNimbleDirs:
-      if not t.noNimblePath:
-        if findInNimbleDir(t, getHomeDir() / ".nimble" / "pkgs"): return
-        when not defined(windows):
-          if findInNimbleDir(t, "/opt/nimble/pkgs"): return
-
-  quit "cannot resolve: " & (t.pkg / t.subdir)
-
-proc main =
-  var t: Task
-  t.subdir = ""
-  for kind, key, val in getopt():
-    case kind
-    of cmdArgument:
-      t.pkg = key
-    of cmdLongoption, cmdShortOption:
-      case normalize(key)
-      of "source": t.source = val
-      of "stdlib": t.stdlib = val
-      of "project": t.project = val
-      of "subdir": t.subdir = val
-      of "nonimblepath": t.noNimblePath = true
-      of "help", "h": writeHelp()
-      of "version", "v": writeVersion()
-      else: writeHelp()
-    of cmdEnd: assert(false) # cannot happen
-  if t.pkg.len == 0:
-    quit "[Error] no package to resolve."
-  resolve(t)
-
-main()
diff --git a/tools/nimweb.nim b/tools/nimweb.nim
index a082520e0..c8b87c1f2 100644
--- a/tools/nimweb.nim
+++ b/tools/nimweb.nim
@@ -52,7 +52,7 @@ proc initConfigData(c: var TConfigData) =
   c.pdf = @[]
   c.infile = ""
   c.outdir = ""
-  c.nimArgs = "--hint[Conf]:off --hint[Path]:off --hint[Processing]:off "
+  c.nimArgs = "--hint[Conf]:off --hint[Path]:off --hint[Processing]:off -d:boot "
   c.authors = ""
   c.projectTitle = ""
   c.projectName = ""
@@ -307,7 +307,7 @@ proc buildDoc(c: var TConfigData, destPath: string) =
       destPath / changeFileExt(splitFile(d).name, "html"), d]
     i.inc
   for d in items(c.srcdoc):
-    commands[i] = findNim() & " doc $# --git.url:$# -o:$# --index:on $#" %
+    commands[i] = findNim() & " doc0 $# --git.url:$# -o:$# --index:on $#" %
       [c.nimArgs, gitRepo,
       destPath / changeFileExt(splitFile(d).name, "html"), d]
     i.inc