From 7e8c9eda45b887b13f4354fcb25fe39708478cc3 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Mon, 13 Jun 2016 12:06:04 +0200 Subject: [PATCH] more niminst fixes --- compiler/installer.ini | 2 -- tools/niminst/niminst.nim | 40 +++++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/compiler/installer.ini b/compiler/installer.ini index 96254252f..f9b112d66 100644 --- a/compiler/installer.ini +++ b/compiler/installer.ini @@ -48,7 +48,6 @@ Start: "doc/overview.html" [Other] Files: "readme.txt;install.txt;contributors.txt;copying.txt" Files: "makefile" -Files: "*.ini" Files: "koch.nim" Files: "icons/nim.ico" @@ -66,7 +65,6 @@ Files: "tools" Files: "web/website.ini" Files: "web/ticker.html" Files: "web/*.nim" -Files: "web/*.txt" Files: "web/*.rst" Files: "web/*.csv" Files: "web/news/*.rst" diff --git a/tools/niminst/niminst.nim b/tools/niminst/niminst.nim index b2983b23b..eb2cb64a3 100644 --- a/tools/niminst/niminst.nim +++ b/tools/niminst/niminst.nim @@ -202,14 +202,34 @@ proc parseCmdLine(c: var ConfigData) = if c.infile.len == 0: quit(Usage) if c.mainfile.len == 0: c.mainfile = changeFileExt(c.infile, "nim") -proc ignoreFile(f, root: string, allowHtml: bool): bool = +proc eqT(a, b: string; t: proc (a: char): char{.nimcall.}): bool = + ## equality under a transformation ``t``. candidate for the stdlib? + var i = 0 + var j = 0 + while i < a.len and j < b.len: + let aa = t a[i] + let bb = t b[j] + if aa == '\0': + inc i + if bb == '\0': inc j + elif bb == '\0': inc j + else: + if aa != bb: return false + inc i + inc j + result = i >= a.len and j >= b.len + +proc tPath(c: char): char = + if c == '\\': '/' + else: c + +proc ignoreFile(f, explicit: string, allowHtml: bool): bool = let (_, name, ext) = splitFile(f) let html = if not allowHtml: ".html" else: "" - let explicit = splitPath(root).tail - result = (ext in ["", ".exe", ".idx"] or - ext == html or name[0] == '.') and name & ext != explicit + result = (ext in ["", ".exe", ".idx", ".o", ".obj", ".dylib"] or + ext == html or name[0] == '.') and not eqT(f, explicit, tPath) -proc walkDirRecursively(s: var seq[string], root: string, +proc walkDirRecursively(s: var seq[string], root, explicit: string, allowHtml: bool) = let tail = splitPath(root).tail if tail == "nimcache" or tail[0] == '.': @@ -221,22 +241,22 @@ proc walkDirRecursively(s: var seq[string], root: string, else: case k of pcFile, pcLinkToFile: - if not ignoreFile(f, root, allowHtml): + if not ignoreFile(f, explicit, allowHtml): add(s, unixToNativePath(f)) of pcDir: - walkDirRecursively(s, f, allowHtml) + walkDirRecursively(s, f, explicit, allowHtml) of pcLinkToDir: discard proc addFiles(s: var seq[string], patterns: seq[string]) = for p in items(patterns): if existsDir(p): - walkDirRecursively(s, p, false) + walkDirRecursively(s, p, p, false) else: var i = 0 for f in walkFiles(p): if existsDir(f): - walkDirRecursively(s, f, false) - elif not ignoreFile(f, p, false): + walkDirRecursively(s, f, p, false) + elif not ignoreFile(f, f, false): add(s, unixToNativePath(f)) inc(i) if i == 0: echo("[Warning] No file found that matches: " & p)