aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2014-06-04 20:49:38 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2014-06-04 20:49:38 +0300
commit451f6247f372ddaaf085ab4a37f302497ed6e324 (patch)
treea0414fafc5b4731f710328c2baa2bd8b72ac174e /tools
parent37bc1240469c9dfb95f0022da08843ba331f231c (diff)
downloadmeson-451f6247f372ddaaf085ab4a37f302497ed6e324.zip
meson-451f6247f372ddaaf085ab4a37f302497ed6e324.tar.gz
meson-451f6247f372ddaaf085ab4a37f302497ed6e324.tar.bz2
Convert function arguments.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/cmake2meson.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/tools/cmake2meson.py b/tools/cmake2meson.py
index 6f936e8..0d3f3c6 100755
--- a/tools/cmake2meson.py
+++ b/tools/cmake2meson.py
@@ -35,12 +35,12 @@ class Lexer:
# Need to be sorted longest to shortest.
('ignore', re.compile(r'[ \t]')),
('string', re.compile(r'"([^\\]|(\\.))*?"', re.M)),
+ ('varexp', re.compile(r'\${[-_0-9a-z/A-Z.]+}')),
('id', re.compile('''[,-><${}=+_0-9a-z/A-Z@.*]+''')),
('eol', re.compile(r'\n')),
('comment', re.compile(r'\#.*')),
('lparen', re.compile(r'\(')),
('rparen', re.compile(r'\)')),
- ('varexp', re.compile(r'\${[-_0-9a-z/A-Z.]+}')),
]
def lex(self, code):
@@ -133,12 +133,32 @@ class Parser():
yield(self.statement())
class Converter:
- ignored_funcs = {'cmake_minimum_required' : True}
+ ignored_funcs = {'cmake_minimum_required' : True,
+ 'enable_testing' : True,
+ 'include' : True}
def __init__(self, cmake_root):
self.cmake_root = cmake_root
self.indent_unit = ' '
self.indent_level = 0
+ def convert_args(self, args):
+ res = []
+ for i in args:
+ if i.tid == 'id':
+ res.append("'%s'" % i.value)
+ elif i.tid == 'varexp':
+ res.append('%s' % i.value)
+ elif i.tid == 'string':
+ res.append("'%s'" % i.value)
+ else:
+ print(i)
+ raise RuntimeError('Unknown arg type.')
+ if len(res) > 1:
+ return '[' + ', '.join(res) + ']'
+ if len(res) == 1:
+ return res[0]
+ return ''
+
def write_entry(self, outfile, t):
if t.name in Converter.ignored_funcs:
return
@@ -167,6 +187,9 @@ class Converter:
args.append(l)
args = ["'%s'" % i for i in args]
line = 'project(' + ', '.join(args) + ')'
+ elif t.name == 'set':
+ varname = t.args[0].value.lower()
+ line = '%s = %s\n' % (varname, self.convert_args(t.args[1:]))
else:
line = '''# %s''' % t.name
outfile.write(indent)