aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xghwt.py4
-rwxr-xr-xtools/ac_converter.py107
-rwxr-xr-xtools/cmake2meson.py55
3 files changed, 99 insertions, 67 deletions
diff --git a/ghwt.py b/ghwt.py
index 493b1e2..bb0be70 100755
--- a/ghwt.py
+++ b/ghwt.py
@@ -52,8 +52,8 @@ def unpack(sproj, branch, outdir):
return 1
spdir = os.path.split(outdir)[0]
ofilename = os.path.join(spdir, config['wrap-file']['source_filename'])
- ofile = open(ofilename, 'wb')
- ofile.write(us)
+ with open(ofilename, 'wb') as ofile:
+ ofile.write(us)
if 'lead_directory_missing' in config['wrap-file']:
os.mkdir(outdir)
shutil.unpack_archive(ofilename, outdir)
diff --git a/tools/ac_converter.py b/tools/ac_converter.py
index 571481e..e88f2e2 100755
--- a/tools/ac_converter.py
+++ b/tools/ac_converter.py
@@ -25,28 +25,6 @@ that are unrelated to configure checks.
import sys
-print('''cc = meson.get_compiler('c')
-cdata = configuration_data()''')
-
-print('check_headers = [')
-
-for line in open(sys.argv[1]):
- line = line.strip()
- if line.startswith('#mesondefine') and \
- line.endswith('_H'):
- token = line.split()[1]
- tarr = token.split('_')[1:-1]
- tarr = [x.lower() for x in tarr]
- hname = '/'.join(tarr) + '.h'
- print(" ['%s', '%s']," % (token, hname))
-print(']\n')
-
-print('''foreach h : check_headers
- if cc.has_header(h.get(1))
- cdata.set(h.get(0), 1)
- endif
-endforeach
-''')
# Add stuff here as it is encountered.
function_data = \
@@ -242,18 +220,71 @@ function_data = \
'HAVE_PTHREAD_SET_NAME_NP': ('pthread_set_name_np', 'pthread.h'),
}
-print('check_functions = [')
+headers = []
+functions = []
+sizes = []
+with open(sys.argv[1]) as f:
+ for line in f:
+ line = line.strip()
+ arr = line.split()
+
+ # Check for headers.
+ if line.startswith('#mesondefine') and line.endswith('_H'):
+ token = line.split()[1]
+ tarr = token.split('_')[1:-1]
+ tarr = [x.lower() for x in tarr]
+ hname = '/'.join(tarr) + '.h'
+ headers.append((token, hname))
+
+ # Check for functions.
+ try:
+ token = arr[1]
+ if token in function_data:
+ fdata = function_data[token]
+ functions.append((token, fdata[0], fdata[1]))
+ elif token.startswith('HAVE_') and not token.endswith('_H'):
+ functions.append((token, ))
+ except Exception:
+ pass
+
+ # Check for sizeof tests.
+ if len(arr) != 2:
+ continue
+ elem = arr[1]
+ if elem.startswith('SIZEOF_'):
+ typename = elem.split('_', 1)[1] \
+ .replace('_P', '*') \
+ .replace('_', ' ') \
+ .lower() \
+ .replace('size t', 'size_t')
+ sizes.append((elem, typename))
-for line in open(sys.argv[1]):
- try:
- token = line.split()[1]
- if token in function_data:
- fdata = function_data[token]
- print(" ['%s', '%s', '#include<%s>']," % (token, fdata[0], fdata[1]))
- elif token.startswith('HAVE_') and not token.endswith('_H'):
- print('# check token', token)
- except Exception:
- pass
+print('''cc = meson.get_compiler('c')
+cdata = configuration_data()''')
+
+# Convert header checks.
+
+print('check_headers = [')
+for token, hname in headers:
+ print(" ['%s', '%s']," % (token, hname))
+print(']\n')
+
+print('''foreach h : check_headers
+ if cc.has_header(h.get(1))
+ cdata.set(h.get(0), 1)
+ endif
+endforeach
+''')
+
+# Convert function checks.
+
+print('check_functions = [')
+for token in functions:
+ if len(func) == 3:
+ token, fdata0, fdata1 = token
+ print(" ['%s', '%s', '#include<%s>']," % (token, fdata0, fdata1))
+ else:
+ print('# check token', token)
print(']\n')
print('''foreach f : check_functions
@@ -265,14 +296,8 @@ endforeach
# Convert sizeof checks.
-for line in open(sys.argv[1]):
- arr = line.strip().split()
- if len(arr) != 2:
- continue
- elem = arr[1]
- if elem.startswith('SIZEOF_'):
- typename = elem.split('_', 1)[1].replace('_P', '*').replace('_', ' ').lower().replace('size t', 'size_t')
- print("cdata.set('%s', cc.sizeof('%s'))" % (elem, typename))
+for elem, typename in size:
+ print("cdata.set('%s', cc.sizeof('%s'))" % (elem, typename))
print('''
configure_file(input : 'config.h.meson',
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: