Changeset: d0ea7e938b39 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d0ea7e938b39
Added Files:
buildtools/autogen/autogen/filesplit.py
Modified Files:
buildtools/autogen/autogen/am.py
buildtools/autogen/autogen/codegen.py
buildtools/autogen/autogen/msc.py
Branch: default
Log Message:
Modify split_filename to work correctly with dots in a filename (e.g.
file.bla.c).
Also modify it to work correctly with relative paths (../../file.c).
diffs (144 lines):
diff --git a/buildtools/autogen/autogen/am.py b/buildtools/autogen/autogen/am.py
--- a/buildtools/autogen/autogen/am.py
+++ b/buildtools/autogen/autogen/am.py
@@ -10,9 +10,7 @@ import sys
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
from codegen import find_org
import re
-
-automake_ext = ['', 'c', 'def', 'h', 'lo', 'o', 'pm.c',
-'tab.c', 'tab.h', 'yy.c']
+from filesplit import split_filename, rsplit_filename, automake_ext
# buildtools_ext contains the extensions of files from which sources
# are generated by rules that are specified in rules.mk in
@@ -23,21 +21,6 @@ buildtools_ext = ['brg', 'l', 'pm.i', 's
am_assign = "+="
-def split_filename(f):
-base = f
-ext = ""
-if f.find(".") >= 0:
-return f.split(".", 1)
-return base, ext
-
-def rsplit_filename(f):
-base = f
-ext = ""
-s = f.rfind(".")
-if s >= 0:
-return f[:s], f[s+1:]
-return base, ext
-
def cond_subdir(fd, dir, i):
res = ""
parts = dir.split("?")
diff --git a/buildtools/autogen/autogen/codegen.py
b/buildtools/autogen/autogen/codegen.py
--- a/buildtools/autogen/autogen/codegen.py
+++ b/buildtools/autogen/autogen/codegen.py
@@ -13,6 +13,7 @@ import sys
from tokenize import tokenize
from tokenize import NL
+from filesplit import split_filename
# direct rules
@@ -75,13 +76,6 @@ scan_map = {
'tex': [ tex_inc, None, '' ],
}
-def split_filename(f):
-base = f
-ext = ""
-if f.find(".") >= 0:
-return f.split(".", 1)
-return base,ext
-
def readfile(f):
src = open(f, 'r')
buf = src.read()
diff --git a/buildtools/autogen/autogen/filesplit.py
b/buildtools/autogen/autogen/filesplit.py
new file mode 100644
--- /dev/null
+++ b/buildtools/autogen/autogen/filesplit.py
@@ -0,0 +1,43 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V.
+
+
+# get the right-most extension of a filename
+def rsplit_filename(f):
+base = f
+ext = ""
+s = f.rfind(".")
+if s >= 0:
+return f[:s], f[s+1:]
+return base, ext
+
+automake_ext = ['', 'c', 'def', 'h', 'lo', 'o', 'pm.c', 'tab.c', 'tab.h',
'yy.c', 'pm.i']
+automake_extra_extensions = set([rsplit_filename(x)[1] for x in automake_ext
if '.' in x])
+extra_extensions = ['in', 'bat', 'sed']
+
+
+
+# get the left-most extension of a filename
+# we skip over known 'extra' extensions to get the real left-most extension
+# this allows us to work with files with periods in them (file.bla.c would
have 'c' as extension)
+# while supporting files with multiple extensions (file.c.in would result in
'c' rather than 'in')
+def split_filename(f):
+base,ext = rsplit_filename(f)
+# special case for automake extensions (tab.c,tab.h)
+# we want: file.tab.c -> 'tab.c'
+# file.bla.c -> 'c'
+if ext in automake_extra_extensions:
+new_base,new_ext = rsplit_filename(base)
+new_ext = new_ext + '.' + ext
+if new_ext in automake_ext:
+return new_base,new_ext
+while ext in extra_extensions:
+new_base,new_ext = rsplit_filename(base)
+if len(new_ext) > 0 and '/' not in new_ext:
+base,ext = new_base,new_ext + '.' + ext
+else:
+break
+return base,ext
diff --git a/buildtools/autogen/autogen/msc.py
b/buildtools/autogen/autogen/msc.py
--- a/buildtools/autogen/autogen/msc.py
+++ b/buildtools/autogen/autogen/msc.py
@@ -7,6 +7,7 @@
import string
import os
import re
+from filesplit import rsplit_filename, split_filename, automake_ext
# the text that is put at the top of every generated Makefile.msc
MAKEFILE_HEAD = '''
@@ -16,23 +17,6 @@ MAKEFILE_HEAD = '''
'''
-automake_ext = ['c', 'h', 'tab.c', 'tab.h', 'yy.c', 'pm.i', '']
-
-def split_filename(f):
-base = f
-ext = ""
-if f.find(".") >= 0:
-return f.split(".", 1)
-return base, ext
-
-def rsplit_filename(f):
-base = f
-ext = ""
-s = f.rfind(".")
-if s >= 0:
-return f[:s], f[s+1:]
-return base, ext
-
def msc_basename(f):
# return basename (i.e. just the file name part) of a path, no
# matter which directory separator was used
___
checkin-list mailing list