diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/detect/detect.nim | 3 | ||||
-rw-r--r-- | tools/finish.nim | 58 | ||||
-rw-r--r-- | tools/nim.bash-completion | 6 | ||||
-rw-r--r-- | tools/nim.zsh-completion | 4 | ||||
-rw-r--r-- | tools/nimgrep.nim | 58 | ||||
-rw-r--r-- | tools/niminst/buildbat.tmpl | 58 | ||||
-rw-r--r-- | tools/niminst/buildsh.tmpl | 4 | ||||
-rw-r--r-- | tools/niminst/niminst.nim | 18 | ||||
-rw-r--r-- | tools/nimpretty.nim | 4 | ||||
-rw-r--r-- | tools/nimweb.nim | 2 |
10 files changed, 143 insertions, 72 deletions
diff --git a/tools/detect/detect.nim b/tools/detect/detect.nim index 1b016cef9..5b4fdc99e 100644 --- a/tools/detect/detect.nim +++ b/tools/detect/detect.nim @@ -586,6 +586,9 @@ v("POSIX_TYPED_MEM_ALLOCATE_CONTIG") v("POSIX_TYPED_MEM_MAP_ALLOCATABLE") v("MAP_POPULATE", no_other = true) +header("<sys/resource.h>") +v("RLIMIT_NOFILE") + header("<sys/select.h>") v("FD_SETSIZE") diff --git a/tools/finish.nim b/tools/finish.nim index 207f15f76..4f2c72595 100644 --- a/tools/finish.nim +++ b/tools/finish.nim @@ -34,7 +34,7 @@ proc downloadMingw(): DownloadResult = if curl.len > 0: cmd = quoteShell(curl) & " --out " & "dist" / mingw & " " & url elif fileExists"bin/nimgrab.exe": - cmd = "bin/nimgrab.exe " & url & " dist" / mingw + cmd = r"bin\nimgrab.exe " & url & " dist" / mingw if cmd.len > 0: if execShellCmd(cmd) != 0: echo "download failed! ", cmd @@ -52,14 +52,17 @@ when defined(windows): proc askBool(m: string): bool = stdout.write m while true: - let answer = stdin.readLine().normalize - case answer - of "y", "yes": - return true - of "n", "no": - return false - else: - echo "Please type 'y' or 'n'" + try: + let answer = stdin.readLine().normalize + case answer + of "y", "yes": + return true + of "n", "no": + return false + else: + echo "Please type 'y' or 'n'" + except EOFError: + quit(1) proc askNumber(m: string; a, b: int): int = stdout.write m @@ -99,10 +102,6 @@ when defined(windows): proc addToPathEnv*(e: string) = var p = tryGetUnicodeValue(r"Environment", "Path", HKEY_CURRENT_USER) - if p.len == 0: - p = tryGetUnicodeValue( - r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", - "Path", HKEY_LOCAL_MACHINE) let x = if e.contains(Whitespace): "\"" & e & "\"" else: e if p.len > 0: p.add ";" @@ -188,10 +187,14 @@ when defined(windows): proc main() = when defined(windows): - let desiredPath = expandFilename(getCurrentDir() / "bin") - let p = getUnicodeValue(r"Environment", "Path", - HKEY_CURRENT_USER) - var alreadyInPath = false + let nimDesiredPath = expandFilename(getCurrentDir() / "bin") + let nimbleDesiredPath = expandFilename(getEnv("USERPROFILE") / ".nimble" / "bin") + let p = tryGetUnicodeValue(r"Environment", "Path", + HKEY_CURRENT_USER) & ";" & tryGetUnicodeValue( + r"System\CurrentControlSet\Control\Session Manager\Environment", "Path", + HKEY_LOCAL_MACHINE) + var nimAlreadyInPath = false + var nimbleAlreadyInPath = false var mingWchoices: seq[string] = @[] var incompat: seq[string] = @[] for x in p.split(';'): @@ -199,18 +202,29 @@ proc main() = let y = try: expandFilename(if x[0] == '"' and x[^1] == '"': substr(x, 1, x.len-2) else: x) except: "" - if y == desiredPath: alreadyInPath = true - if y.toLowerAscii.contains("mingw"): + if y.cmpIgnoreCase(nimDesiredPath) == 0: + nimAlreadyInPath = true + elif y.cmpIgnoreCase(nimbleDesiredPath) == 0: + nimbleAlreadyInPath = true + elif y.toLowerAscii.contains("mingw"): if dirExists(y): if checkGccArch(y): mingWchoices.add y else: incompat.add y - if alreadyInPath: - echo "bin/nim.exe is already in your PATH [Skipping]" + if nimAlreadyInPath: + echo "bin\\nim.exe is already in your PATH [Skipping]" else: if askBool("nim.exe is not in your PATH environment variable.\n" & "Should it be added permanently? (y/n) "): - addToPathEnv(desiredPath) + addToPathEnv(nimDesiredPath) + + if nimbleAlreadyInPath: + echo nimbleDesiredPath & " is already in your PATH [Skipping]" + else: + if askBool(nimbleDesiredPath & " is not in your PATH environment variable.\n" & + "Should it be added permanently? (y/n) "): + addToPathEnv(nimbleDesiredPath) + if mingWchoices.len == 0: # No mingw in path, so try a few locations: let alternative = tryDirs(incompat, defaultMingwLocations()) diff --git a/tools/nim.bash-completion b/tools/nim.bash-completion index 4f62da986..8e569079a 100644 --- a/tools/nim.bash-completion +++ b/tools/nim.bash-completion @@ -10,12 +10,12 @@ _nim() if [ $COMP_CWORD -eq 1 ] ; then # first item - suggest commands - kw="compile c doc doc2 compileToC cc compileToCpp cpp compileToOC objc js e rst2html rst2tex jsondoc jsondoc2 buildIndex genDepend dump check" + kw="compile c doc compileToC cc compileToCpp cpp compileToOC objc js e rst2html rst2tex jsondoc buildIndex genDepend dump check" COMPREPLY=( $( compgen -W "${kw}" -- $cur ) ) return 0 fi case $prev in - --stackTrace|--lineTrace|--threads|-x|--checks|--objChecks|--fieldChecks|--rangeChecks|--boundChecks|--overflowChecks|-a|--assertions|--floatChecks|--nanChecks|--infChecks|--deadCodeElim) + --stackTrace|--lineTrace|--threads|-x|--checks|--objChecks|--fieldChecks|--rangeChecks|--boundChecks|--overflowChecks|-a|--assertions|--floatChecks|--nanChecks|--infChecks) # Options that require on/off [[ "$cur" == "=" ]] && cur="" COMPREPLY=( $(compgen -W 'on off' -- "$cur") ) @@ -32,7 +32,7 @@ _nim() return 0 ;; *) - kw="-r -p= --path= -d= --define= -u= --undef= -f --forceBuild --opt= --app= --stackTrace= --lineTrace= --threads= -x= --checks= --objChecks= --fieldChecks= --rangeChecks= --boundChecks= --overflowChecks= -a= --assertions= --floatChecks= --nanChecks= --infChecks= --deadCodeElim=" + kw="-r -p= --path= -d= --define= -u= --undef= -f --forceBuild --opt= --app= --stackTrace= --lineTrace= --threads= -x= --checks= --objChecks= --fieldChecks= --rangeChecks= --boundChecks= --overflowChecks= -a= --assertions= --floatChecks= --nanChecks= --infChecks=" COMPREPLY=( $( compgen -W "${kw}" -- $cur ) ) _filedir '@(nim)' #$split diff --git a/tools/nim.zsh-completion b/tools/nim.zsh-completion index 135649c90..e9b9002fb 100644 --- a/tools/nim.zsh-completion +++ b/tools/nim.zsh-completion @@ -5,7 +5,6 @@ _nim() { ':command:(( {compile,c}\:compile\ project\ with\ default\ code\ generator\ C doc\:generate\ the\ documentation\ for\ inputfile - doc2\:generate\ the\ documentation\ for\ inputfile {compileToC,cc}\:compile\ project\ with\ C\ code\ generator {compileToCpp,cpp}\:compile\ project\ to\ C++\ code {compileToOC,objc}\:compile\ project\ to\ Objective\ C\ code @@ -14,7 +13,6 @@ _nim() { rst2html\:convert\ a\ reStructuredText\ file\ to\ HTML rst2tex\:convert\ a\ reStructuredText\ file\ to\ TeX jsondoc\:extract\ the\ documentation\ to\ a\ json\ file - jsondoc2\:extract\ documentation\ to\ a\ json\ file\ using\ doc2 buildIndex\:build\ an\ index\ for\ the\ whole\ documentation genDepend\:generate\ a\ DOT\ file\ containing\ the\ module\ dependency\ graph dump\:dump\ all\ defined\ conditionals\ and\ search\ paths @@ -62,8 +60,6 @@ _nim() { '*--infChecks=off[turn Inf checks off]' \ '*--nilChecks=on[turn nil checks on]' \ '*--nilChecks=off[turn nil checks off]' \ - '*--deadCodeElim=on[whole program dead code elimination on]' \ - '*--deadCodeElim=off[whole program dead code elimination off]' \ '*--opt=none[do not optimize]' \ '*--opt=speed[optimize for speed|size - use -d:release for a release build]' \ '*--opt=size[optimize for size]' \ diff --git a/tools/nimgrep.nim b/tools/nimgrep.nim index e9c1b26fa..9cfd7a86f 100644 --- a/tools/nimgrep.nim +++ b/tools/nimgrep.nim @@ -11,7 +11,7 @@ import os, strutils, parseopt, pegs, re, terminal const - Version = "1.1" + Version = "1.2" Usage = "nimgrep - Nim Grep Utility Version " & Version & """ (c) 2012 Andreas Rumpf @@ -33,7 +33,10 @@ Options: --ignoreStyle, -y be style insensitive --ext:EX1|EX2|... only search the files with the given extension(s) --nocolor output will be given without any colours. + --oneline show file on each matched line --verbose be verbose: list every processed file + --filenames find the pattern in the filenames, not in the contents + of the file --help, -h shows this help --version, -v shows the version """ @@ -41,7 +44,7 @@ Options: type TOption = enum optFind, optReplace, optPeg, optRegex, optRecursive, optConfirm, optStdin, - optWord, optIgnoreCase, optIgnoreStyle, optVerbose + optWord, optIgnoreCase, optIgnoreStyle, optVerbose, optFilenames TOptions = set[TOption] TConfirmEnum = enum ceAbort, ceYes, ceAll, ceNo, ceNone @@ -56,6 +59,7 @@ var extensions: seq[string] = @[] options: TOptions = {optRegex} useWriteStyled = true + oneline = false proc ask(msg: string): string = stdout.write(msg) @@ -103,9 +107,12 @@ proc writeColored(s: string) = stdout.write(s) proc highlight(s, match, repl: string, t: tuple[first, last: int], - line: int, showRepl: bool) = + filename:string, line: int, showRepl: bool) = const alignment = 6 - stdout.write(line.`$`.align(alignment), ": ") + if oneline: + stdout.write(filename, ":", line, ": ") + else: + stdout.write(line.`$`.align(alignment), ": ") var x = beforePattern(s, t.first) var y = afterPattern(s, t.last) for i in x .. t.first-1: stdout.write(s[i]) @@ -121,20 +128,23 @@ proc highlight(s, match, repl: string, t: tuple[first, last: int], stdout.write("\n") stdout.flushFile() -proc processFile(pattern; filename: string) = +proc processFile(pattern; filename: string; counter: var int) = var filenameShown = false template beforeHighlight = - if not filenameShown and optVerbose notin options: + if not filenameShown and optVerbose notin options and not oneline: stdout.writeLine(filename) stdout.flushFile() filenameShown = true var buffer: string - try: - buffer = system.readFile(filename) - except IOError: - echo "cannot open file: ", filename - return + if optFilenames in options: + buffer = filename + else: + try: + buffer = system.readFile(filename) + except IOError: + echo "cannot open file: ", filename + return if optVerbose in options: stdout.writeLine(filename) stdout.flushFile() @@ -156,12 +166,13 @@ proc processFile(pattern; filename: string) = var wholeMatch = buffer.substr(t.first, t.last) beforeHighlight() + inc counter if optReplace notin options: - highlight(buffer, wholeMatch, "", t, line, showRepl=false) + highlight(buffer, wholeMatch, "", t, filename, line, showRepl=false) else: let r = replace(wholeMatch, pattern, replacement % matches) if optConfirm in options: - highlight(buffer, wholeMatch, r, t, line, showRepl=true) + highlight(buffer, wholeMatch, r, t, filename, line, showRepl=true) case confirm() of ceAbort: quit(0) of ceYes: reallyReplace = true @@ -174,7 +185,7 @@ proc processFile(pattern; filename: string) = reallyReplace = false options.excl(optConfirm) else: - highlight(buffer, wholeMatch, r, t, line, showRepl=reallyReplace) + highlight(buffer, wholeMatch, r, t, filename, line, showRepl=reallyReplace) if reallyReplace: result.add(buffer.substr(i, t.first-1)) result.add(r) @@ -231,17 +242,17 @@ proc styleInsensitive(s: string): string = addx() else: addx() -proc walker(pattern; dir: string) = +proc walker(pattern; dir: string; counter: var int) = for kind, path in walkDir(dir): case kind of pcFile: if extensions.len == 0 or path.hasRightExt(extensions): - processFile(pattern, path) + processFile(pattern, path, counter) of pcDir: if optRecursive in options: - walker(pattern, path) + walker(pattern, path, counter) else: discard - if existsFile(dir): processFile(pattern, dir) + if existsFile(dir): processFile(pattern, dir, counter) proc writeHelp() = stdout.write(Usage) @@ -286,7 +297,9 @@ for kind, key, val in getopt(): of "ignorestyle", "y": incl(options, optIgnoreStyle) of "ext": extensions.add val.split('|') of "nocolor": useWriteStyled = false + of "oneline": oneline = true of "verbose": incl(options, optVerbose) + of "filenames": incl(options, optFilenames) of "help", "h": writeHelp() of "version", "v": writeVersion() else: writeHelp() @@ -298,6 +311,7 @@ when defined(posix): checkOptions({optFind, optReplace}, "find", "replace") checkOptions({optPeg, optRegex}, "peg", "re") checkOptions({optIgnoreCase, optIgnoreStyle}, "ignore_case", "ignore_style") +checkOptions({optFilenames, optReplace}, "filenames", "replace") if optStdin in options: pattern = ask("pattern [ENTER to exit]: ") @@ -308,6 +322,7 @@ if optStdin in options: if pattern.len == 0: writeHelp() else: + var counter = 0 if filenames.len == 0: filenames.add(os.getCurrentDir()) if optRegex notin options: @@ -319,7 +334,7 @@ else: pattern = "\\i " & pattern let pegp = peg(pattern) for f in items(filenames): - walker(pegp, f) + walker(pegp, f, counter) else: var reflags = {reStudy, reExtended} if optIgnoreStyle in options: @@ -330,5 +345,6 @@ else: reflags.incl reIgnoreCase let rep = re(pattern, reflags) for f in items(filenames): - walker(rep, f) - + walker(rep, f, counter) + if not oneline: + stdout.write($counter & " matches\n") diff --git a/tools/niminst/buildbat.tmpl b/tools/niminst/buildbat.tmpl index 278b6caea..6767461e3 100644 --- a/tools/niminst/buildbat.tmpl +++ b/tools/niminst/buildbat.tmpl @@ -1,5 +1,5 @@ #? stdtmpl(subsChar='?') | standard -#proc generateBuildBatchScript(c: ConfigData, winIndex, cpuIndex: int): string = +#proc generateBuildBatchScript(c: ConfigData, winIndex, cpuIndex32, cpuIndex64: int): string = # result = "@echo off\nREM Generated by niminst\n" SET CC=gcc SET LINKER=gcc @@ -7,26 +7,62 @@ SET COMP_FLAGS=?{c.ccompiler.flags} SET LINK_FLAGS=?{c.linker.flags} SET BIN_DIR=?{firstBinPath(c).toWin} +REM Detect gcc arch +IF DEFINED ARCH ( + ECHO Forcing %CC% arch +) ELSE ( + ECHO Detecting %CC% arch + ECHO int main^(^) { return sizeof^(void *^); } | gcc -xc - -o archtest && archtest + IF ERRORLEVEL 4 SET ARCH=32 + IF ERRORLEVEL 8 SET ARCH=64 + del archtest.* +) +ECHO Building with %ARCH% bit %CC% + if EXIST ..\koch.nim SET BIN_DIR=..\bin if NOT EXIST %BIN_DIR%\nul mkdir %BIN_DIR% REM call the compiler: +IF %ARCH% EQU 32 ( + # block win32: # var linkCmd = "" -# for ff in items(c.cfiles[winIndex][cpuIndex]): -# let f = ff.toWin -ECHO %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")} -CALL %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")} -# linkCmd.add(" " & changeFileExt(f, "o")) -IF ERRORLEVEL 1 (GOTO:END) -# end for +# if cpuIndex32 != -1: +# for ff in items(c.cfiles[winIndex][cpuIndex32]): +# let f = ff.toWin + ECHO %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")} + CALL %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")} +# linkCmd.add(" " & changeFileExt(f, "o")) + IF ERRORLEVEL 1 (GOTO:END) +# end for +# end if + + ECHO %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS% + CALL %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS% + +# end block + +) ELSE IF %ARCH% EQU 64 ( + +# block win64: +# var linkCmd = "" +# if cpuIndex64 != -1: +# for ff in items(c.cfiles[winIndex][cpuIndex64]): +# let f = ff.toWin + ECHO %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")} + CALL %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")} +# linkCmd.add(" " & changeFileExt(f, "o")) + IF ERRORLEVEL 1 (GOTO:END) +# end for +# end if -ECHO %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS% -CALL %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS% + ECHO %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS% + CALL %LINKER% -o ?{"%BIN_DIR%"\toLowerAscii(c.name)}.exe ?linkCmd %LINK_FLAGS% # end block +) :END IF ERRORLEVEL 1 ( @@ -35,6 +71,8 @@ IF ERRORLEVEL 1 ( ECHO CSource compilation failed. Please check that the gcc compiler is in ECHO the PATH environment variable, and that you are calling the batch script ECHO that matches the target architecture of the compiler. + ECHO. + ECHO Use build.bat to autodetect the compiler architecture. ) ELSE ( ECHO SUCCESS ) diff --git a/tools/niminst/buildsh.tmpl b/tools/niminst/buildsh.tmpl index 3e7d8ae6e..be6d43754 100644 --- a/tools/niminst/buildsh.tmpl +++ b/tools/niminst/buildsh.tmpl @@ -39,8 +39,8 @@ do esac done -CC="gcc" -LINKER="gcc" +CC="${CC:-gcc}" +LINKER="${LD:-gcc}" COMP_FLAGS="${CPPFLAGS:-} ${CFLAGS:-} ?{c.ccompiler.flags}$extraBuildArgs" LINK_FLAGS="${LDFLAGS:-} ?{c.linker.flags}" PS4="" diff --git a/tools/niminst/niminst.nim b/tools/niminst/niminst.nim index 9c15326b0..e2cc8cf3a 100644 --- a/tools/niminst/niminst.nim +++ b/tools/niminst/niminst.nim @@ -15,13 +15,14 @@ when haveZipLib: import os, osproc, strutils, parseopt, parsecfg, strtabs, streams, debcreation, - securehash + std / sha1 const maxOS = 20 # max number of OSes maxCPU = 20 # max number of CPUs buildShFile = "build.sh" - buildBatFile32 = "build.bat" + buildBatFile = "build.bat" + buildBatFile32 = "build32.bat" buildBatFile64 = "build64.bat" makeFile = "makefile" installShFile = "install.sh" @@ -542,12 +543,13 @@ proc srcdist(c: var ConfigData) = inclFilePermissions(getOutputDir(c) / buildShFile, {fpUserExec, fpGroupExec, fpOthersExec}) writeFile(getOutputDir(c) / makeFile, generateMakefile(c), "\10") if winIndex >= 0: + if intel32Index >= 0 or intel64Index >= 0: + writeFile(getOutputDir(c) / buildBatFile, + generateBuildBatchScript(c, winIndex, intel32Index, intel64Index), "\13\10") if intel32Index >= 0: - writeFile(getOutputDir(c) / buildBatFile32, - generateBuildBatchScript(c, winIndex, intel32Index), "\13\10") + writeFile(getOutputDir(c) / buildBatFile32, "SET ARCH=32\nCALL build.bat\n") if intel64Index >= 0: - writeFile(getOutputDir(c) / buildBatFile64, - generateBuildBatchScript(c, winIndex, intel64Index), "\13\10") + writeFile(getOutputDir(c) / buildBatFile64, "SET ARCH=64\nCALL build.bat\n") writeInstallScripts(c) # --------------------- generate inno setup ----------------------------------- @@ -593,6 +595,7 @@ when haveZipLib: else: n = c.outdir / n var z: ZipArchive if open(z, n, fmWrite): + addFile(z, proj / buildBatFile, "build" / buildBatFile) addFile(z, proj / buildBatFile32, "build" / buildBatFile32) addFile(z, proj / buildBatFile64, "build" / buildBatFile64) addFile(z, proj / buildShFile, "build" / buildShFile) @@ -631,11 +634,12 @@ proc xzDist(c: var ConfigData; windowsZip=false) = if not dirExists(destDir): createDir(destDir) copyFileWithPermissions(src, dest) - if not windowsZip and not existsFile("build" / buildBatFile32): + if not windowsZip and not existsFile("build" / buildBatFile): quit("No C sources found in ./build/, please build by running " & "./koch csource -d:release.") if not windowsZip: + processFile(proj / buildBatFile, "build" / buildBatFile) processFile(proj / buildBatFile32, "build" / buildBatFile32) processFile(proj / buildBatFile64, "build" / buildBatFile64) processFile(proj / buildShFile, "build" / buildShFile) diff --git a/tools/nimpretty.nim b/tools/nimpretty.nim index 36d1382cf..396f17b0b 100644 --- a/tools/nimpretty.nim +++ b/tools/nimpretty.nim @@ -24,7 +24,7 @@ const Usage: nimpretty [options] file.nim Options: - --backup:ON|OFF create a backup file before overwritting (default: ON) + --backup:on|off create a backup file before overwritting (default: ON) --version show the version --help show this help """ @@ -43,7 +43,7 @@ proc prettyPrint(infile: string) = let fileIdx = fileInfoIdx(infile) let tree = parseFile(fileIdx, newIdentCache()) let outfile = changeFileExt(infile, ".pretty.nim") - renderModule(tree, infile, outfile, {}) + renderModule(tree, infile, outfile, {}, fileIdx) proc main = var infile: string diff --git a/tools/nimweb.nim b/tools/nimweb.nim index c8b87c1f2..6e1d9d359 100644 --- a/tools/nimweb.nim +++ b/tools/nimweb.nim @@ -418,7 +418,7 @@ proc generateRss(outputFilename: string, news: seq[TRssItem]) = href = rss.url), updatedDate(rss.year, rss.month, rss.day), "<author><name>Nim</name></author>", - content(xmltree.escape(rss.content), `type` = "text"), + content(xmltree.escape(rss.content), `type` = "text") )) output.write("""</feed>""") |