diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2014-06-02 00:51:36 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2014-06-02 00:51:36 +0300 |
commit | 0c31155b0a572522ea6e623add3d76318b091993 (patch) | |
tree | 0a05d84cd835c6a655647d7e555a52d22934289e /tools | |
parent | c8184965c4420accddce035822df28bbf84eb522 (diff) | |
download | meson-0c31155b0a572522ea6e623add3d76318b091993.zip meson-0c31155b0a572522ea6e623add3d76318b091993.tar.gz meson-0c31155b0a572522ea6e623add3d76318b091993.tar.bz2 |
Convert some function types.
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/cmake2meson.py | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/tools/cmake2meson.py b/tools/cmake2meson.py index d4e68ce..8cc9d55 100755 --- a/tools/cmake2meson.py +++ b/tools/cmake2meson.py @@ -136,17 +136,27 @@ class Converter: def __init__(self, cmake_root): self.cmake_root = cmake_root self.indent_unit = ' ' + self.indent_level = 0 - def write_entry(self, outfile, indent, t): + def write_entry(self, outfile, t): + indent = self.indent_level*self.indent_unit if t.name == '_': - outfile.writelines([indent, t.args[0], '\n']) - elif t.name == 'subdir': - outfile.writelines([indent, t.args[0], '\n']) + line = t.args[0] + elif t.name == 'add_subdirectory': + line = 'subdir(' + t.args[0].value + ')' + elif t.name == 'pkg_search_module' or t.name == 'pkg_search_modules': + varname = t.args[0].value.lower() + mods = ['dependency(%s)' % i.value for i in t.args[1:]] + if len(mods) == 1: + line = '%s = %s' % (varname, mods[0]) + else: + line = '%s = [%s]' % (varname, ', '.join(mods)) else: - self.unknown_command(outfile, indent, t) - - def unknown_command(self, outfile, indent, t): - outfile.writelines([indent, '# ', t.name, '\n']) + line = '''# %s''' % t.name + outfile.write(indent) + outfile.write(line) + if not(line.endswith('\n')): + outfile.write('\n') def convert(self, subdir=''): if subdir == '': @@ -159,22 +169,16 @@ class Converter: 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') self.convert(os.path.join(subdir, t.args[0].value)) #print('\nReturning to', self.cmake_root, '\n') - self.write_entry(outfile, indent, t) + self.write_entry(outfile, t) if __name__ == '__main__': if len(sys.argv) != 2: print(sys.argv[0], '<CMake project root>') sys.exit(1) - try: - c = Converter(sys.argv[1]) - c.convert() - except Exception as e: - print('Error:', e) - sys.exit(1) + c = Converter(sys.argv[1]) + c.convert() |