summary refs log tree commit diff stats
path: root/tools/niminst
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-06-07 13:47:02 +0200
committerAndreas Rumpf <rumpf_a@web.de>2016-06-07 13:47:37 +0200
commite0f57ee1a1757c6c572a5e0054dd2f03a4670bed (patch)
tree8a4dd96802cd4eff68f58319249c6f7a789ec7ec /tools/niminst
parent82a75635f7c3500002e4e5a8ca91c1c02af8f5bb (diff)
downloadNim-e0f57ee1a1757c6c572a5e0054dd2f03a4670bed.tar.gz
finally make niminst smart about which files are important
Diffstat (limited to 'tools/niminst')
-rw-r--r--tools/niminst/niminst.nim49
1 files changed, 34 insertions, 15 deletions
diff --git a/tools/niminst/niminst.nim b/tools/niminst/niminst.nim
index 991789a08..8ff53bbe3 100644
--- a/tools/niminst/niminst.nim
+++ b/tools/niminst/niminst.nim
@@ -202,23 +202,41 @@ proc parseCmdLine(c: var ConfigData) =
   if c.infile.len == 0: quit(Usage)
   if c.mainfile.len == 0: c.mainfile = changeFileExt(c.infile, "nim")
 
-proc walkDirRecursively(s: var seq[string], root: string) =
+proc ignoreFile(f, root: string, preventHtml: bool): bool =
+  let (_, name, ext) = splitFile(f)
+  let html = if preventHtml: ".html" else: ""
+  let explicit = splitPath(root).tail
+  result = (ext in ["", ".exe", ".idx"] or
+            ext == html or name[0] == '.') and f != explicit
+
+proc walkDirRecursively(s: var seq[string], root: string,
+                        preventHtml: bool) =
+  let tail = splitPath(root).tail
+  if tail == "nimcache" or tail[0] == '.':
+    return
+  let preventHtml = preventHtml or tail != "doc"
   for k, f in walkDir(root):
-    case k
-    of pcFile, pcLinkToFile: add(s, unixToNativePath(f))
-    of pcDir: walkDirRecursively(s, f)
-    of pcLinkToDir: discard
+    if f[0] == '.' and root[0] != '.':
+      discard "skip .git directories etc"
+    else:
+      case k
+      of pcFile, pcLinkToFile:
+        if not ignoreFile(f, root, preventHtml):
+          add(s, unixToNativePath(f))
+      of pcDir:
+        walkDirRecursively(s, f, preventHtml)
+      of pcLinkToDir: discard
 
 proc addFiles(s: var seq[string], patterns: seq[string]) =
   for p in items(patterns):
     if existsDir(p):
-      walkDirRecursively(s, p)
+      walkDirRecursively(s, p, true)
     else:
       var i = 0
       for f in walkFiles(p):
         if existsDir(f):
-          walkDirRecursively(s, f)
-        else:
+          walkDirRecursively(s, f, false)
+        elif not ignoreFile(f, p, false):
           add(s, unixToNativePath(f))
           inc(i)
       if i == 0: echo("[Warning] No file found that matches: " & p)
@@ -613,13 +631,14 @@ proc xzDist(c: var ConfigData) =
   let nimbleFile = c.nimblePkgName & ".nimble"
   processFile(z, proj / nimbleFile, nimbleFile)
 
-  let oldDir = getCurrentDir()
-  setCurrentDir(tmpDir)
-  try:
-    if execShellCmd("XZ_OPT=-9 tar Jcf $1.tar.xz $1" % proj) != 0:
-      echo("External program failed")
-  finally:
-    setCurrentDir(oldDir)
+  when true:
+    let oldDir = getCurrentDir()
+    setCurrentDir(tmpDir)
+    try:
+      if execShellCmd("XZ_OPT=-9 tar Jcf $1.tar.xz $1" % proj) != 0:
+        echo("External program failed")
+    finally:
+      setCurrentDir(oldDir)
 
 # -- prepare build files for .deb creation