diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2016-09-01 23:12:06 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-09-01 23:12:06 +0300 |
commit | cdf0c4f1a945f1262ae604047fd240b25cf44050 (patch) | |
tree | efb861fa017c1f8663b75570fe61fa644c2bd3d0 /tools/cmake2meson.py | |
parent | 389259c229b30d38ec9de503dff965973b24ee26 (diff) | |
parent | 859c5e28df90851838aacc4b9ad49d3630e4992a (diff) | |
download | meson-cdf0c4f1a945f1262ae604047fd240b25cf44050.zip meson-cdf0c4f1a945f1262ae604047fd240b25cf44050.tar.gz meson-cdf0c4f1a945f1262ae604047fd240b25cf44050.tar.bz2 |
Merge branch 'QuLogic-context-managers'
Diffstat (limited to 'tools/cmake2meson.py')
-rwxr-xr-x | tools/cmake2meson.py | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/tools/cmake2meson.py b/tools/cmake2meson.py index 098a6e0..7465d45 100755 --- a/tools/cmake2meson.py +++ b/tools/cmake2meson.py @@ -252,39 +252,46 @@ class Converter: subdir = self.cmake_root cfile = os.path.join(subdir, 'CMakeLists.txt') try: - cmakecode = open(cfile).read() + with open(cfile) as f: + cmakecode = f.read() except FileNotFoundError: print('\nWarning: No CMakeLists.txt in', subdir, '\n') return p = Parser(cmakecode) - outfile = open(os.path.join(subdir, 'meson.build'), 'w') - for t in p.parse(): - 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, t) + with open(os.path.join(subdir, 'meson.build'), 'w') as outfile: + for t in p.parse(): + 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, t) if subdir == self.cmake_root and len(self.options) > 0: self.write_options() def write_options(self): - optfile = open(os.path.join(self.cmake_root, 'meson_options.txt'), 'w') - for o in self.options: - (optname, description, default) = o - if default is None: - defaultstr = '' - else: - if default == 'OFF': - typestr = ' type : boolean,' - default = 'false' - elif default == 'ON': - default = 'true' - typestr = ' type : boolean,' + filename = os.path.join(self.cmake_root, 'meson_options.txt') + with open(filename, 'w') as optfile: + for o in self.options: + (optname, description, default) = o + if default is None: + defaultstr = '' else: - typestr = ' type : string,' - defaultstr = ' value : %s,' % default - line = "option(%s,%s%s description : '%s')\n" % (optname, typestr, defaultstr, description) - optfile.write(line) + if default == 'OFF': + typestr = ' type : boolean,' + default = 'false' + elif default == 'ON': + default = 'true' + typestr = ' type : boolean,' + else: + typestr = ' type : string,' + defaultstr = ' value : %s,' % default + line = "option(%s,%s%s description : '%s')\n" % (optname, + typestr, + defaultstr, + description) + optfile.write(line) if __name__ == '__main__': if len(sys.argv) != 2: |