summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2014-06-02 00:20:08 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2014-06-02 00:20:08 +0300
commitc8184965c4420accddce035822df28bbf84eb522 (patch)
tree77568afaa1bfb40876185a79a47b982bf33e7665 /tools
parent053cc2e5f8bbd4263dd311423db8acc0060af767 (diff)
downloadmeson-c8184965c4420accddce035822df28bbf84eb522.tar.gz
Comments are converted. Yay!
Diffstat (limited to 'tools')
-rwxr-xr-xtools/cmake2meson.py30
1 files changed, 23 insertions, 7 deletions
diff --git a/tools/cmake2meson.py b/tools/cmake2meson.py
index aff50c163..d4e68ceda 100755
--- a/tools/cmake2meson.py
+++ b/tools/cmake2meson.py
@@ -35,7 +35,7 @@ class Lexer:
# Need to be sorted longest to shortest.
('ignore', re.compile(r'[ \t]')),
('string', re.compile(r'"([^\\]|(\\.))*?"', re.M)),
- ('id', re.compile('''[,-=+_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'\(')),
@@ -106,12 +106,14 @@ class Parser():
raise RuntimeError('Expecting %s got %s.' % (s, self.current.tid), self.current.lineno, self.current.colno)
def statement(self):
- name = self.current.value
+ cur = self.current
+ if self.accept('comment'):
+ return Statement('_', [cur.value])
self.accept('id')
self.expect('lparen')
args = self.arguments()
self.expect('rparen')
- return Statement(name, args)
+ return Statement(cur.value, args)
def arguments(self):
args = []
@@ -133,6 +135,18 @@ class Parser():
class Converter:
def __init__(self, cmake_root):
self.cmake_root = cmake_root
+ self.indent_unit = ' '
+
+ def write_entry(self, outfile, indent, t):
+ if t.name == '_':
+ outfile.writelines([indent, t.args[0], '\n'])
+ elif t.name == 'subdir':
+ outfile.writelines([indent, t.args[0], '\n'])
+ else:
+ self.unknown_command(outfile, indent, t)
+
+ def unknown_command(self, outfile, indent, t):
+ outfile.writelines([indent, '# ', t.name, '\n'])
def convert(self, subdir=''):
if subdir == '':
@@ -144,13 +158,15 @@ class Converter:
print('\nWarning: No CMakeLists.txt in', subdir, '\n')
return
p = Parser(cmakecode)
+ outfile = open(os.path.join(subdir, 'meson.build'), 'w')
+ indent_depth = 0
for t in p.parse():
+ indent = self.indent_unit*indent_depth
if t.name == 'add_subdirectory':
- print('\nRecursing to subdir', os.path.join(self.cmake_root, t.args[0].value), '\n')
+ #print('\nRecursing to subdir', os.path.join(self.cmake_root, t.args[0].value), '\n')
self.convert(os.path.join(subdir, t.args[0].value))
- print('\nReturning to', self.cmake_root, '\n')
- else:
- print(t.name, t.args)
+ #print('\nReturning to', self.cmake_root, '\n')
+ self.write_entry(outfile, indent, t)
if __name__ == '__main__':
if len(sys.argv) != 2: