Merge branch 'QuLogic-context-managers'

pull/749/head
Jussi Pakkanen 8 years ago
commit cdf0c4f1a9
  1. 4
      ghwt.py
  2. 59
      mesonbuild/backend/backends.py
  3. 141
      mesonbuild/backend/ninjabackend.py
  4. 120
      mesonbuild/backend/vs2010backend.py
  5. 36
      mesonbuild/backend/xcodebackend.py
  6. 73
      mesonbuild/compilers.py
  7. 6
      mesonbuild/coredata.py
  8. 25
      mesonbuild/dependencies.py
  9. 6
      mesonbuild/interpreter.py
  10. 9
      mesonbuild/mconf.py
  11. 16
      mesonbuild/mesonlib.py
  12. 3
      mesonbuild/mesonmain.py
  13. 12
      mesonbuild/mintro.py
  14. 62
      mesonbuild/modules/pkgconfig.py
  15. 147
      mesonbuild/modules/rpm.py
  16. 3
      mesonbuild/optinterpreter.py
  17. 34
      mesonbuild/scripts/depfixer.py
  18. 43
      mesonbuild/scripts/meson_benchmark.py
  19. 3
      mesonbuild/scripts/meson_exe.py
  20. 11
      mesonbuild/scripts/meson_install.py
  21. 45
      mesonbuild/scripts/meson_test.py
  22. 6
      mesonbuild/scripts/regen_checker.py
  23. 9
      mesonbuild/scripts/symbolextractor.py
  24. 13
      mesonbuild/scripts/vcstagger.py
  25. 80
      mesonbuild/wrap/wrap.py
  26. 6
      mesonbuild/wrap/wraptool.py
  27. 12
      run_tests.py
  28. 15
      test cases/common/103 manygen/subdir/manygen.py
  29. 9
      test cases/common/107 postconf/postconf.py
  30. 9
      test cases/common/108 postconf with args/postconf.py
  31. 3
      test cases/common/113 generatorcustom/catter.py
  32. 6
      test cases/common/113 generatorcustom/gen.py
  33. 3
      test cases/common/117 custom target capture/my_compiler.py
  34. 8
      test cases/common/16 configure file/generator.py
  35. 5
      test cases/common/48 test args/tester.py
  36. 6
      test cases/common/56 custom target/depfile/dep.py
  37. 7
      test cases/common/56 custom target/my_compiler.py
  38. 7
      test cases/common/57 custom target chain/my_compiler.py
  39. 7
      test cases/common/57 custom target chain/my_compiler2.py
  40. 4
      test cases/common/57 custom target chain/usetarget/subcomp.py
  41. 3
      test cases/common/58 run target/converter.py
  42. 3
      test cases/common/58 run target/fakeburner.py
  43. 6
      test cases/common/61 custom target source output/generator.py
  44. 6
      test cases/common/64 custom header generator/makeheader.py
  45. 9
      test cases/common/65 multiple generators/mygen.py
  46. 9
      test cases/common/72 build always/version_gen.py
  47. 9
      test cases/common/76 configure file in custom target/src/mycompiler.py
  48. 6
      test cases/common/78 ctarget dependency/gen1.py
  49. 3
      test cases/common/78 ctarget dependency/gen2.py
  50. 6
      test cases/common/93 private include/stlib/compiler.py
  51. 6
      test cases/common/98 gen extra/srcgen.py
  52. 107
      tools/ac_converter.py
  53. 55
      tools/cmake2meson.py

@ -52,8 +52,8 @@ def unpack(sproj, branch, outdir):
return 1 return 1
spdir = os.path.split(outdir)[0] spdir = os.path.split(outdir)[0]
ofilename = os.path.join(spdir, config['wrap-file']['source_filename']) ofilename = os.path.join(spdir, config['wrap-file']['source_filename'])
ofile = open(ofilename, 'wb') with open(ofilename, 'wb') as ofile:
ofile.write(us) ofile.write(us)
if 'lead_directory_missing' in config['wrap-file']: if 'lead_directory_missing' in config['wrap-file']:
os.mkdir(outdir) os.mkdir(outdir)
shutil.unpack_archive(ofilename, outdir) shutil.unpack_archive(ofilename, outdir)

@ -139,24 +139,34 @@ class Backend():
langlist = {} langlist = {}
abs_files = [] abs_files = []
result = [] result = []
for src in unity_src:
comp = self.get_compiler_for_source(src, target.is_cross) def init_language_file(language, suffix):
language = comp.get_language() outfilename = os.path.join(self.get_target_private_dir_abs(target),
suffix = '.' + comp.get_default_suffix() target.name + '-unity' + suffix)
if language not in langlist: outfileabs = os.path.join(self.environment.get_build_dir(),
outfilename = os.path.join(self.get_target_private_dir_abs(target), target.name + '-unity' + suffix) outfilename)
outfileabs = os.path.join(self.environment.get_build_dir(), outfilename) outfileabs_tmp = outfileabs + '.tmp'
outfileabs_tmp = outfileabs + '.tmp' abs_files.append(outfileabs)
abs_files.append(outfileabs) outfileabs_tmp_dir = os.path.dirname(outfileabs_tmp)
outfileabs_tmp_dir = os.path.dirname(outfileabs_tmp) if not os.path.exists(outfileabs_tmp_dir):
if not os.path.exists(outfileabs_tmp_dir): os.makedirs(outfileabs_tmp_dir)
os.makedirs(outfileabs_tmp_dir) result.append(outfilename)
outfile = open(outfileabs_tmp, 'w') return open(outfileabs_tmp, 'w')
langlist[language] = outfile
result.append(outfilename) try:
ofile = langlist[language] for src in unity_src:
ofile.write('#include<%s>\n' % src) comp = self.get_compiler_for_source(src, target.is_cross)
[x.close() for x in langlist.values()] language = comp.get_language()
try:
ofile = langlist[language]
except KeyError:
suffix = '.' + comp.get_default_suffix()
ofile = langlist[language] = init_language_file(language,
suffix)
ofile.write('#include<%s>\n' % src)
finally:
for x in langlist.values():
x.close()
[mesonlib.replace_if_different(x, x + '.tmp') for x in abs_files] [mesonlib.replace_if_different(x, x + '.tmp') for x in abs_files]
return result return result
@ -215,13 +225,11 @@ class Backend():
def serialise_tests(self): def serialise_tests(self):
test_data = os.path.join(self.environment.get_scratch_dir(), 'meson_test_setup.dat') test_data = os.path.join(self.environment.get_scratch_dir(), 'meson_test_setup.dat')
datafile = open(test_data, 'wb') with open(test_data, 'wb') as datafile:
self.write_test_file(datafile) self.write_test_file(datafile)
datafile.close()
benchmark_data = os.path.join(self.environment.get_scratch_dir(), 'meson_benchmark_setup.dat') benchmark_data = os.path.join(self.environment.get_scratch_dir(), 'meson_benchmark_setup.dat')
datafile = open(benchmark_data, 'wb') with open(benchmark_data, 'wb') as datafile:
self.write_benchmark_file(datafile) self.write_benchmark_file(datafile)
datafile.close()
return (test_data, benchmark_data) return (test_data, benchmark_data)
def has_source_suffix(self, target, suffix): def has_source_suffix(self, target, suffix):
@ -442,7 +450,8 @@ class Backend():
mfobj = {'type': 'dependency manifest', mfobj = {'type': 'dependency manifest',
'version': '1.0'} 'version': '1.0'}
mfobj['projects'] = self.build.dep_manifest mfobj['projects'] = self.build.dep_manifest
open(ifilename, 'w').write(json.dumps(mfobj)) with open(ifilename, 'w') as f:
f.write(json.dumps(mfobj))
d.data.append([ifilename, ofilename]) d.data.append([ifilename, ofilename])
def get_regen_filelist(self): def get_regen_filelist(self):

@ -133,17 +133,18 @@ class NinjaBackend(backends.Backend):
self.all_outputs = {} self.all_outputs = {}
self.valgrind = environment.find_valgrind() self.valgrind = environment.find_valgrind()
def detect_vs_dep_prefix(self, outfile, tempfilename): def detect_vs_dep_prefix(self, tempfilename):
'''VS writes its dependency in a locale dependent format. '''VS writes its dependency in a locale dependent format.
Detect the search prefix to use.''' Detect the search prefix to use.'''
# Of course there is another program called 'cl' on # Of course there is another program called 'cl' on
# some platforms. Let's just require that on Windows # some platforms. Let's just require that on Windows
# cl points to msvc. # cl points to msvc.
if not mesonlib.is_windows() or shutil.which('cl') is None: if not mesonlib.is_windows() or shutil.which('cl') is None:
return outfile return open(tempfilename, 'a')
outfile.close() filename = os.path.join(self.environment.get_scratch_dir(),
open(os.path.join(self.environment.get_scratch_dir(), 'incdetect.c'), 'incdetect.c')
'w').write('''#include<stdio.h> with open(filename, 'w') as f:
f.write('''#include<stdio.h>
int dummy; int dummy;
''') ''')
@ -157,9 +158,8 @@ int dummy;
for line in stdo.split(b'\r\n'): for line in stdo.split(b'\r\n'):
if line.endswith(b'stdio.h'): if line.endswith(b'stdio.h'):
matchstr = b':'.join(line.split(b':')[0:2]) + b':' matchstr = b':'.join(line.split(b':')[0:2]) + b':'
binfile = open(tempfilename, 'ab') with open(tempfilename, 'ab') as binfile:
binfile.write(b'msvc_deps_prefix = ' + matchstr + b'\r\n') binfile.write(b'msvc_deps_prefix = ' + matchstr + b'\r\n')
binfile.close()
return open(tempfilename, 'a') return open(tempfilename, 'a')
raise MesonException('Could not determine vs dep dependency prefix string.') raise MesonException('Could not determine vs dep dependency prefix string.')
@ -167,30 +167,31 @@ int dummy;
self.interpreter = interp self.interpreter = interp
outfilename = os.path.join(self.environment.get_build_dir(), self.ninja_filename) outfilename = os.path.join(self.environment.get_build_dir(), self.ninja_filename)
tempfilename = outfilename + '~' tempfilename = outfilename + '~'
outfile = open(tempfilename, 'w') with open(tempfilename, 'w') as outfile:
outfile.write('# This is the build file for project "%s"\n' % self.build.get_project()) outfile.write('# This is the build file for project "%s"\n' %
outfile.write('# It is autogenerated by the Meson build system.\n') self.build.get_project())
outfile.write('# Do not edit by hand.\n\n') outfile.write('# It is autogenerated by the Meson build system.\n')
outfile.write('ninja_required_version = 1.5.1\n\n') outfile.write('# Do not edit by hand.\n\n')
outfile = self.detect_vs_dep_prefix(outfile, tempfilename) outfile.write('ninja_required_version = 1.5.1\n\n')
self.generate_rules(outfile) with self.detect_vs_dep_prefix(tempfilename) as outfile:
self.generate_phony(outfile) self.generate_rules(outfile)
outfile.write('# Build rules for targets\n\n') self.generate_phony(outfile)
[self.generate_target(t, outfile) for t in self.build.get_targets().values()] outfile.write('# Build rules for targets\n\n')
outfile.write('# Test rules\n\n') for t in self.build.get_targets().values():
self.generate_tests(outfile) self.generate_target(t, outfile)
outfile.write('# Install rules\n\n') outfile.write('# Test rules\n\n')
self.generate_install(outfile) self.generate_tests(outfile)
if 'b_coverage' in self.environment.coredata.base_options and \ outfile.write('# Install rules\n\n')
self.environment.coredata.base_options['b_coverage'].value: self.generate_install(outfile)
outfile.write('# Coverage rules\n\n') if 'b_coverage' in self.environment.coredata.base_options and \
self.generate_coverage_rules(outfile) self.environment.coredata.base_options['b_coverage'].value:
outfile.write('# Suffix\n\n') outfile.write('# Coverage rules\n\n')
self.generate_utils(outfile) self.generate_coverage_rules(outfile)
self.generate_ending(outfile) outfile.write('# Suffix\n\n')
self.generate_utils(outfile)
self.generate_ending(outfile)
# Only ovewrite the old build file after the new one has been # Only ovewrite the old build file after the new one has been
# fully created. # fully created.
outfile.close()
os.replace(tempfilename, outfilename) os.replace(tempfilename, outfilename)
self.generate_compdb() self.generate_compdb()
@ -202,7 +203,8 @@ int dummy;
jsondb = subprocess.check_output([ninja_exe, '-t', 'compdb', 'c_COMPILER', 'cpp_COMPILER'], cwd=builddir) jsondb = subprocess.check_output([ninja_exe, '-t', 'compdb', 'c_COMPILER', 'cpp_COMPILER'], cwd=builddir)
except Exception: except Exception:
raise MesonException('Could not create compilation database.') raise MesonException('Could not create compilation database.')
open(os.path.join(builddir, 'compile_commands.json'), 'wb').write(jsondb) with open(os.path.join(builddir, 'compile_commands.json'), 'wb') as f:
f.write(jsondb)
# Get all generated headers. Any source file might need them so # Get all generated headers. Any source file might need them so
# we need to add an order dependency to them. # we need to add an order dependency to them.
@ -505,8 +507,8 @@ int dummy;
self.generate_subdir_install(d) self.generate_subdir_install(d)
elem.write(outfile) elem.write(outfile)
ofile = open(install_data_file, 'wb') with open(install_data_file, 'wb') as ofile:
pickle.dump(d, ofile) pickle.dump(d, ofile)
def generate_target_install(self, d): def generate_target_install(self, d):
should_strip = self.environment.coredata.get_builtin_option('strip') should_strip = self.environment.coredata.get_builtin_option('strip')
@ -1416,16 +1418,22 @@ rule FORTRAN_DEP_HACK
# but those are really rare. I hope. # but those are really rare. I hope.
if not compiler.can_compile(s): if not compiler.can_compile(s):
continue continue
for line in open(os.path.join(self.environment.get_source_dir(), s.subdir, s.fname)): filename = os.path.join(self.environment.get_source_dir(),
modmatch = modre.match(line) s.subdir, s.fname)
if modmatch is not None: with open(filename) as f:
modname = modmatch.group(1) for line in f:
if modname.lower() == 'procedure': # MODULE PROCEDURE construct modmatch = modre.match(line)
continue if modmatch is not None:
if modname in module_files: modname = modmatch.group(1)
raise InvalidArguments('Namespace collision: module %s defined in two files %s and %s.' % if modname.lower() == 'procedure':
(modname, module_files[modname], s)) # MODULE PROCEDURE construct
module_files[modname] = s continue
if modname in module_files:
raise InvalidArguments(
'Namespace collision: module %s defined in '
'two files %s and %s.' %
(modname, module_files[modname], s))
module_files[modname] = s
self.fortran_deps[target.get_basename()] = module_files self.fortran_deps[target.get_basename()] = module_files
def get_fortran_deps(self, compiler, src, target): def get_fortran_deps(self, compiler, src, target):
@ -1433,27 +1441,32 @@ rule FORTRAN_DEP_HACK
usere = re.compile(r"\s*use\s+(\w+)", re.IGNORECASE) usere = re.compile(r"\s*use\s+(\w+)", re.IGNORECASE)
dirname = self.get_target_private_dir(target) dirname = self.get_target_private_dir(target)
tdeps= self.fortran_deps[target.get_basename()] tdeps= self.fortran_deps[target.get_basename()]
for line in open(src): with open(src) as f:
usematch = usere.match(line) for line in f:
if usematch is not None: usematch = usere.match(line)
usename = usematch.group(1) if usematch is not None:
if usename not in tdeps: usename = usematch.group(1)
# The module is not provided by any source file. This is due to if usename not in tdeps:
# a) missing file/typo/etc # The module is not provided by any source file. This
# b) using a module provided by the compiler, such as OpenMP # is due to:
# There's no easy way to tell which is which (that I know of) # a) missing file/typo/etc
# so just ignore this and go on. Ideally we would print a # b) using a module provided by the compiler, such as
# warning message to the user but this is a common occurrance, # OpenMP
# which would lead to lots of distracting noise. # There's no easy way to tell which is which (that I
continue # know of) so just ignore this and go on. Ideally we
mod_source_file = tdeps[usename] # would print a warning message to the user but this is
# Check if a source uses a module it exports itself. # a common occurrence, which would lead to lots of
# Potential bug if multiple targets have a file with # distracting noise.
# the same name. continue
if mod_source_file.fname == os.path.split(src)[1]: mod_source_file = tdeps[usename]
continue # Check if a source uses a module it exports itself.
mod_name = compiler.module_name_to_filename(usematch.group(1)) # Potential bug if multiple targets have a file with
mod_files.append(os.path.join(dirname, mod_name)) # the same name.
if mod_source_file.fname == os.path.split(src)[1]:
continue
mod_name = compiler.module_name_to_filename(
usematch.group(1))
mod_files.append(os.path.join(dirname, mod_name))
return mod_files return mod_files
def get_cross_stdlib_args(self, target, compiler): def get_cross_stdlib_args(self, target, compiler):

@ -175,14 +175,18 @@ class Vs2010Backend(backends.Backend):
@staticmethod @staticmethod
def touch_regen_timestamp(build_dir): def touch_regen_timestamp(build_dir):
open(Vs2010Backend.get_regen_stampfile(build_dir), 'w').close() with open(Vs2010Backend.get_regen_stampfile(build_dir), 'w'):
pass
def generate_regen_info(self): def generate_regen_info(self):
deps = self.get_regen_filelist() deps = self.get_regen_filelist()
regeninfo = RegenInfo(self.environment.get_source_dir(), regeninfo = RegenInfo(self.environment.get_source_dir(),
self.environment.get_build_dir(), self.environment.get_build_dir(),
deps) deps)
pickle.dump(regeninfo, open(os.path.join(self.environment.get_scratch_dir(), 'regeninfo.dump'), 'wb')) filename = os.path.join(self.environment.get_scratch_dir(),
'regeninfo.dump')
with open(filename, 'wb') as f:
pickle.dump(regeninfo, f)
def get_obj_target_deps(self, obj_list): def get_obj_target_deps(self, obj_list):
result = {} result = {}
@ -217,57 +221,66 @@ class Vs2010Backend(backends.Backend):
return all_deps return all_deps
def generate_solution(self, sln_filename, projlist): def generate_solution(self, sln_filename, projlist):
ofile = open(sln_filename, 'w') with open(sln_filename, 'w') as ofile:
ofile.write('Microsoft Visual Studio Solution File, Format Version 11.00\n') ofile.write('Microsoft Visual Studio Solution File, Format '
ofile.write('# Visual Studio ' + self.vs_version + '\n') 'Version 11.00\n')
prj_templ = prj_line = 'Project("{%s}") = "%s", "%s", "{%s}"\n' ofile.write('# Visual Studio ' + self.vs_version + '\n')
for p in projlist: prj_templ = prj_line = 'Project("{%s}") = "%s", "%s", "{%s}"\n'
prj_line = prj_templ % (self.environment.coredata.guid, p[0], p[1], p[2]) for p in projlist:
ofile.write(prj_line) prj_line = prj_templ % (self.environment.coredata.guid,
all_deps = self.determine_deps(p) p[0], p[1], p[2])
ofile.write('\tProjectSection(ProjectDependencies) = postProject\n') ofile.write(prj_line)
regen_guid = self.environment.coredata.regen_guid all_deps = self.determine_deps(p)
ofile.write('\t\t{%s} = {%s}\n' % (regen_guid, regen_guid)) ofile.write('\tProjectSection(ProjectDependencies) = '
for dep in all_deps.keys(): 'postProject\n')
guid = self.environment.coredata.target_guids[dep] regen_guid = self.environment.coredata.regen_guid
ofile.write('\t\t{%s} = {%s}\n' % (guid, guid)) ofile.write('\t\t{%s} = {%s}\n' % (regen_guid, regen_guid))
ofile.write('EndProjectSection\n') for dep in all_deps.keys():
guid = self.environment.coredata.target_guids[dep]
ofile.write('\t\t{%s} = {%s}\n' % (guid, guid))
ofile.write('EndProjectSection\n')
ofile.write('EndProject\n')
test_line = prj_templ % (self.environment.coredata.guid,
'RUN_TESTS', 'RUN_TESTS.vcxproj',
self.environment.coredata.test_guid)
ofile.write(test_line)
ofile.write('EndProject\n') ofile.write('EndProject\n')
test_line = prj_templ % (self.environment.coredata.guid, regen_line = prj_templ % (self.environment.coredata.guid,
'RUN_TESTS', 'RUN_TESTS.vcxproj', self.environment.coredata.test_guid) 'REGEN', 'REGEN.vcxproj',
ofile.write(test_line) self.environment.coredata.regen_guid)
ofile.write('EndProject\n') ofile.write(regen_line)
regen_line = prj_templ % (self.environment.coredata.guid, ofile.write('EndProject\n')
'REGEN', 'REGEN.vcxproj', self.environment.coredata.regen_guid) ofile.write('Global\n')
ofile.write(regen_line) ofile.write('\tGlobalSection(SolutionConfigurationPlatforms) = '
ofile.write('EndProject\n') 'preSolution\n')
ofile.write('Global\n') ofile.write('\t\t%s|%s = %s|%s\n' %
ofile.write('\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n') (self.buildtype, self.platform, self.buildtype,
ofile.write('\t\t%s|%s = %s|%s\n' % (self.buildtype, self.platform, self.buildtype, self.platform)) self.platform))
ofile.write('\tEndGlobalSection\n') ofile.write('\tEndGlobalSection\n')
ofile.write('\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n') ofile.write('\tGlobalSection(ProjectConfigurationPlatforms) = '
ofile.write('\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n' % 'postSolution\n')
(self.environment.coredata.regen_guid, self.buildtype, self.platform,
self.buildtype, self.platform))
ofile.write('\t\t{%s}.%s|%s.Build.0 = %s|%s\n' %
(self.environment.coredata.regen_guid, self.buildtype, self.platform,
self.buildtype, self.platform))
for p in projlist:
ofile.write('\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n' % ofile.write('\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n' %
(p[2], self.buildtype, self.platform, (self.environment.coredata.regen_guid, self.buildtype,
self.buildtype, self.platform)) self.platform, self.buildtype, self.platform))
if not isinstance(self.build.targets[p[0]], build.RunTarget): ofile.write('\t\t{%s}.%s|%s.Build.0 = %s|%s\n' %
ofile.write('\t\t{%s}.%s|%s.Build.0 = %s|%s\n' % (self.environment.coredata.regen_guid, self.buildtype,
self.platform, self.buildtype, self.platform))
for p in projlist:
ofile.write('\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n' %
(p[2], self.buildtype, self.platform, (p[2], self.buildtype, self.platform,
self.buildtype, self.platform)) self.buildtype, self.platform))
ofile.write('\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n' % if not isinstance(self.build.targets[p[0]], build.RunTarget):
(self.environment.coredata.test_guid, self.buildtype, self.platform, ofile.write('\t\t{%s}.%s|%s.Build.0 = %s|%s\n' %
self.buildtype, self.platform)) (p[2], self.buildtype, self.platform,
ofile.write('\tEndGlobalSection\n') self.buildtype, self.platform))
ofile.write('\tGlobalSection(SolutionProperties) = preSolution\n') ofile.write('\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n' %
ofile.write('\t\tHideSolutionNode = FALSE\n') (self.environment.coredata.test_guid, self.buildtype,
ofile.write('\tEndGlobalSection\n') self.platform, self.buildtype, self.platform))
ofile.write('EndGlobal\n') ofile.write('\tEndGlobalSection\n')
ofile.write('\tGlobalSection(SolutionProperties) = preSolution\n')
ofile.write('\t\tHideSolutionNode = FALSE\n')
ofile.write('\tEndGlobalSection\n')
ofile.write('EndGlobal\n')
def generate_projects(self): def generate_projects(self):
projlist = [] projlist = []
@ -862,12 +875,15 @@ class Vs2010Backend(backends.Backend):
tree.write(ofname, encoding='utf-8', xml_declaration=True) tree.write(ofname, encoding='utf-8', xml_declaration=True)
# ElementTree can not do prettyprinting so do it manually # ElementTree can not do prettyprinting so do it manually
doc = xml.dom.minidom.parse(ofname) doc = xml.dom.minidom.parse(ofname)
open(ofname, 'w').write(doc.toprettyxml()) with open(ofname, 'w') as of:
of.write(doc.toprettyxml())
# World of horror! Python insists on not quoting quotes and # World of horror! Python insists on not quoting quotes and
# fixing the escaped &quot; into &amp;quot; whereas MSVS # fixing the escaped &quot; into &amp;quot; whereas MSVS
# requires quoted but not fixed elements. Enter horrible hack. # requires quoted but not fixed elements. Enter horrible hack.
txt = open(ofname, 'r').read() with open(ofname, 'r') as of:
open(ofname, 'w').write(txt.replace('&amp;quot;', '&quot;')) txt = of.read()
with open(ofname, 'w') as of:
of.write(txt.replace('&amp;quot;', '&quot;'))
def gen_regenproj(self, project_name, ofname): def gen_regenproj(self, project_name, ofname):
root = ET.Element('Project', {'DefaultTargets': 'Build', root = ET.Element('Project', {'DefaultTargets': 'Build',

@ -82,26 +82,22 @@ class XCodeBackend(backends.Backend):
self.proj_dir = os.path.join(self.environment.get_build_dir(), self.build.project_name + '.xcodeproj') self.proj_dir = os.path.join(self.environment.get_build_dir(), self.build.project_name + '.xcodeproj')
os.makedirs(self.proj_dir, exist_ok=True) os.makedirs(self.proj_dir, exist_ok=True)
self.proj_file = os.path.join(self.proj_dir, 'project.pbxproj') self.proj_file = os.path.join(self.proj_dir, 'project.pbxproj')
self.ofile = open(self.proj_file, 'w') with open(self.proj_file, 'w') as self.ofile:
self.generate_prefix() self.generate_prefix()
self.generate_pbx_aggregate_target() self.generate_pbx_aggregate_target()
self.generate_pbx_build_file() self.generate_pbx_build_file()
self.generate_pbx_build_style() self.generate_pbx_build_style()
self.generate_pbx_container_item_proxy() self.generate_pbx_container_item_proxy()
self.generate_pbx_file_reference() self.generate_pbx_file_reference()
self.generate_pbx_group() self.generate_pbx_group()
self.generate_pbx_native_target() self.generate_pbx_native_target()
self.generate_pbx_project() self.generate_pbx_project()
self.generate_pbx_shell_build_phase(test_data) self.generate_pbx_shell_build_phase(test_data)
self.generate_pbx_sources_build_phase() self.generate_pbx_sources_build_phase()
self.generate_pbx_target_dependency() self.generate_pbx_target_dependency()
self.generate_xc_build_configuration() self.generate_xc_build_configuration()
self.generate_xc_configurationList() self.generate_xc_configurationList()
self.generate_suffix() self.generate_suffix()
# for some reason, the entire file was not being flushed to the disk.
# closing it explicitly forces a flush and fixes the issue
self.ofile.close()
def get_xcodetype(self, fname): def get_xcodetype(self, fname):
return self.xcodetypemap[fname.split('.')[-1]] return self.xcodetypemap[fname.split('.')[-1]]

@ -538,9 +538,8 @@ class CCompiler(Compiler):
binname += '.exe' binname += '.exe'
# Write binary check source # Write binary check source
binary_name = os.path.join(work_dir, binname) binary_name = os.path.join(work_dir, binname)
ofile = open(source_name, 'w') with open(source_name, 'w') as ofile:
ofile.write(code) ofile.write(code)
ofile.close()
# Compile sanity check # Compile sanity check
cmdlist = self.exelist + extra_flags + [source_name] + self.get_output_args(binary_name) cmdlist = self.exelist + extra_flags + [source_name] + self.get_output_args(binary_name)
pc = subprocess.Popen(cmdlist, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=work_dir) pc = subprocess.Popen(cmdlist, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=work_dir)
@ -617,9 +616,8 @@ int main () {{ {1}; }}'''
suflen = len(self.default_suffix) suflen = len(self.default_suffix)
(fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix) (fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
os.close(fd) os.close(fd)
ofile = open(srcname, 'w') with open(srcname, 'w') as ofile:
ofile.write(code) ofile.write(code)
ofile.close()
# Convert flags to the native type of the selected compiler # Convert flags to the native type of the selected compiler
args = self.unix_link_flags_to_native(extra_args) args = self.unix_link_flags_to_native(extra_args)
# Read c_args/cpp_args/etc from the cross-info file (if needed) # Read c_args/cpp_args/etc from the cross-info file (if needed)
@ -647,9 +645,8 @@ int main () {{ {1}; }}'''
os.close(fd) os.close(fd)
(fd, dstname) = tempfile.mkstemp() (fd, dstname) = tempfile.mkstemp()
os.close(fd) os.close(fd)
ofile = open(srcname, 'w') with open(srcname, 'w') as ofile:
ofile.write(code) ofile.write(code)
ofile.close()
# Convert flags to the native type of the selected compiler # Convert flags to the native type of the selected compiler
args = self.unix_link_flags_to_native(extra_args) args = self.unix_link_flags_to_native(extra_args)
# Select a CRT if needed since we're linking # Select a CRT if needed since we're linking
@ -672,9 +669,8 @@ int main () {{ {1}; }}'''
raise CrossNoRunException('Can not run test applications in this cross environment.') raise CrossNoRunException('Can not run test applications in this cross environment.')
(fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix) (fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
os.close(fd) os.close(fd)
ofile = open(srcname, 'w') with open(srcname, 'w') as ofile:
ofile.write(code) ofile.write(code)
ofile.close()
# Convert flags to the native type of the selected compiler # Convert flags to the native type of the selected compiler
args = self.unix_link_flags_to_native(extra_args) args = self.unix_link_flags_to_native(extra_args)
# Select a CRT if needed since we're linking # Select a CRT if needed since we're linking
@ -997,9 +993,9 @@ class ObjCCompiler(CCompiler):
extra_flags = self.get_cross_extra_flags(environment, compile=True, link=False) extra_flags = self.get_cross_extra_flags(environment, compile=True, link=False)
if self.is_cross: if self.is_cross:
extra_flags += self.get_compile_only_args() extra_flags += self.get_compile_only_args()
ofile = open(source_name, 'w') with open(source_name, 'w') as ofile:
ofile.write('#import<stdio.h>\nint main(int argc, char **argv) { return 0; }\n') ofile.write('#import<stdio.h>\n'
ofile.close() 'int main(int argc, char **argv) { return 0; }\n')
pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name]) pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name])
pc.wait() pc.wait()
if pc.returncode != 0: if pc.returncode != 0:
@ -1031,9 +1027,10 @@ class ObjCPPCompiler(CPPCompiler):
extra_flags = self.get_cross_extra_flags(environment, compile=True, link=False) extra_flags = self.get_cross_extra_flags(environment, compile=True, link=False)
if self.is_cross: if self.is_cross:
extra_flags += self.get_compile_only_args() extra_flags += self.get_compile_only_args()
ofile = open(source_name, 'w') with open(source_name, 'w') as ofile:
ofile.write('#import<stdio.h>\nclass MyClass;int main(int argc, char **argv) { return 0; }\n') ofile.write('#import<stdio.h>\n'
ofile.close() 'class MyClass;'
'int main(int argc, char **argv) { return 0; }\n')
pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name]) pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name])
pc.wait() pc.wait()
if pc.returncode != 0: if pc.returncode != 0:
@ -1133,13 +1130,12 @@ class MonoCompiler(Compiler):
src = 'sanity.cs' src = 'sanity.cs'
obj = 'sanity.exe' obj = 'sanity.exe'
source_name = os.path.join(work_dir, src) source_name = os.path.join(work_dir, src)
ofile = open(source_name, 'w') with open(source_name, 'w') as ofile:
ofile.write('''public class Sanity { ofile.write('''public class Sanity {
static public void Main () { static public void Main () {
} }
} }
''') ''')
ofile.close()
pc = subprocess.Popen(self.exelist + [src], cwd=work_dir) pc = subprocess.Popen(self.exelist + [src], cwd=work_dir)
pc.wait() pc.wait()
if pc.returncode != 0: if pc.returncode != 0:
@ -1245,14 +1241,13 @@ class JavaCompiler(Compiler):
src = 'SanityCheck.java' src = 'SanityCheck.java'
obj = 'SanityCheck' obj = 'SanityCheck'
source_name = os.path.join(work_dir, src) source_name = os.path.join(work_dir, src)
ofile = open(source_name, 'w') with open(source_name, 'w') as ofile:
ofile.write('''class SanityCheck { ofile.write('''class SanityCheck {
public static void main(String[] args) { public static void main(String[] args) {
int i; int i;
} }
} }
''') ''')
ofile.close()
pc = subprocess.Popen(self.exelist + [src], cwd=work_dir) pc = subprocess.Popen(self.exelist + [src], cwd=work_dir)
pc.wait() pc.wait()
if pc.returncode != 0: if pc.returncode != 0:
@ -1292,11 +1287,10 @@ class ValaCompiler(Compiler):
def sanity_check(self, work_dir, environment): def sanity_check(self, work_dir, environment):
src = 'valatest.vala' src = 'valatest.vala'
source_name = os.path.join(work_dir, src) source_name = os.path.join(work_dir, src)
ofile = open(source_name, 'w') with open(source_name, 'w') as ofile:
ofile.write('''class SanityCheck : Object { ofile.write('''class SanityCheck : Object {
} }
''') ''')
ofile.close()
extra_flags = self.get_cross_extra_flags(environment, compile=True, link=False) extra_flags = self.get_cross_extra_flags(environment, compile=True, link=False)
pc = subprocess.Popen(self.exelist + extra_flags + ['-C', '-c', src], cwd=work_dir) pc = subprocess.Popen(self.exelist + extra_flags + ['-C', '-c', src], cwd=work_dir)
pc.wait() pc.wait()
@ -1336,11 +1330,10 @@ class RustCompiler(Compiler):
def sanity_check(self, work_dir, environment): def sanity_check(self, work_dir, environment):
source_name = os.path.join(work_dir, 'sanity.rs') source_name = os.path.join(work_dir, 'sanity.rs')
output_name = os.path.join(work_dir, 'rusttest') output_name = os.path.join(work_dir, 'rusttest')
ofile = open(source_name, 'w') with open(source_name, 'w') as ofile:
ofile.write('''fn main() { ofile.write('''fn main() {
} }
''') ''')
ofile.close()
pc = subprocess.Popen(self.exelist + ['-o', output_name, source_name], cwd=work_dir) pc = subprocess.Popen(self.exelist + ['-o', output_name, source_name], cwd=work_dir)
pc.wait() pc.wait()
if pc.returncode != 0: if pc.returncode != 0:
@ -1435,10 +1428,9 @@ class SwiftCompiler(Compiler):
src = 'swifttest.swift' src = 'swifttest.swift'
source_name = os.path.join(work_dir, src) source_name = os.path.join(work_dir, src)
output_name = os.path.join(work_dir, 'swifttest') output_name = os.path.join(work_dir, 'swifttest')
ofile = open(source_name, 'w') with open(source_name, 'w') as ofile:
ofile.write('''1 + 2 ofile.write('''1 + 2
''') ''')
ofile.close()
extra_flags = self.get_cross_extra_flags(environment, compile=True, link=True) extra_flags = self.get_cross_extra_flags(environment, compile=True, link=True)
pc = subprocess.Popen(self.exelist + extra_flags + ['-emit-executable', '-o', output_name, src], cwd=work_dir) pc = subprocess.Popen(self.exelist + extra_flags + ['-emit-executable', '-o', output_name, src], cwd=work_dir)
pc.wait() pc.wait()
@ -1461,11 +1453,10 @@ class DCompiler(Compiler):
def sanity_check(self, work_dir, environment): def sanity_check(self, work_dir, environment):
source_name = os.path.join(work_dir, 'sanity.d') source_name = os.path.join(work_dir, 'sanity.d')
output_name = os.path.join(work_dir, 'dtest') output_name = os.path.join(work_dir, 'dtest')
ofile = open(source_name, 'w') with open(source_name, 'w') as ofile:
ofile.write('''void main() { ofile.write('''void main() {
} }
''') ''')
ofile.close()
pc = subprocess.Popen(self.exelist + self.get_output_args(output_name) + [source_name], cwd=work_dir) pc = subprocess.Popen(self.exelist + self.get_output_args(output_name) + [source_name], cwd=work_dir)
pc.wait() pc.wait()
if pc.returncode != 0: if pc.returncode != 0:
@ -1872,9 +1863,8 @@ class VisualStudioCCompiler(CCompiler):
code = 'int i;\n' code = 'int i;\n'
(fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix) (fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
os.close(fd) os.close(fd)
ofile = open(srcname, 'w') with open(srcname, 'w') as ofile:
ofile.write(code) ofile.write(code)
ofile.close()
# Read c_args/cpp_args/etc from the cross-info file (if needed) # Read c_args/cpp_args/etc from the cross-info file (if needed)
extra_args = self.get_cross_extra_flags(env, compile=True, link=False) extra_args = self.get_cross_extra_flags(env, compile=True, link=False)
extra_args += self.get_compile_only_args() extra_args += self.get_compile_only_args()
@ -2286,12 +2276,11 @@ class FortranCompiler(Compiler):
def sanity_check(self, work_dir, environment): def sanity_check(self, work_dir, environment):
source_name = os.path.join(work_dir, 'sanitycheckf.f90') source_name = os.path.join(work_dir, 'sanitycheckf.f90')
binary_name = os.path.join(work_dir, 'sanitycheckf') binary_name = os.path.join(work_dir, 'sanitycheckf')
ofile = open(source_name, 'w') with open(source_name, 'w') as ofile:
ofile.write('''program prog ofile.write('''program prog
print *, "Fortran compilation is working." print *, "Fortran compilation is working."
end program prog end program prog
''') ''')
ofile.close()
extra_flags = self.get_cross_extra_flags(environment, compile=True, link=True) extra_flags = self.get_cross_extra_flags(environment, compile=True, link=True)
pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name]) pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name])
pc.wait() pc.wait()

@ -154,7 +154,8 @@ class CoreData():
raise RuntimeError('Tried to set unknown builtin option %s.' % optname) raise RuntimeError('Tried to set unknown builtin option %s.' % optname)
def load(filename): def load(filename):
obj = pickle.load(open(filename, 'rb')) with open(filename, 'rb') as f:
obj = pickle.load(f)
if not isinstance(obj, CoreData): if not isinstance(obj, CoreData):
raise RuntimeError('Core data file is corrupted.') raise RuntimeError('Core data file is corrupted.')
if obj.version != version: if obj.version != version:
@ -165,7 +166,8 @@ def load(filename):
def save(obj, filename): def save(obj, filename):
if obj.version != version: if obj.version != version:
raise RuntimeError('Fatal version mismatch corruption.') raise RuntimeError('Fatal version mismatch corruption.')
pickle.dump(obj, open(filename, 'wb')) with open(filename, 'wb') as f:
pickle.dump(obj, f)
def get_builtin_options(): def get_builtin_options():
return list(builtin_options.keys()) return list(builtin_options.keys())

@ -228,10 +228,11 @@ class PkgConfigDependency(Dependency):
return self.is_found return self.is_found
def extract_field(self, la_file, fieldname): def extract_field(self, la_file, fieldname):
for line in open(la_file): with open(la_file) as f:
arr = line.strip().split('=') for line in f:
if arr[0] == fieldname: arr = line.strip().split('=')
return arr[1][1:-1] if arr[0] == fieldname:
return arr[1][1:-1]
return None return None
def extract_dlname_field(self, la_file): def extract_dlname_field(self, la_file):
@ -374,7 +375,8 @@ class ExternalProgram():
shebang and manually parse it to figure out the interpreter to use shebang and manually parse it to figure out the interpreter to use
""" """
try: try:
first_line = open(script).readline().strip() with open(script) as f:
first_line = f.readline().strip()
if first_line.startswith('#!'): if first_line.startswith('#!'):
commands = first_line[2:].split('#')[0].strip().split() commands = first_line[2:].split('#')[0].strip().split()
if mesonlib.is_windows(): if mesonlib.is_windows():
@ -552,12 +554,13 @@ class BoostDependency(Dependency):
except FileNotFoundError: except FileNotFoundError:
self.version = None self.version = None
return return
for line in ifile: with ifile:
if line.startswith("#define") and 'BOOST_LIB_VERSION' in line: for line in ifile:
ver = line.split()[-1] if line.startswith("#define") and 'BOOST_LIB_VERSION' in line:
ver = ver[1:-1] ver = line.split()[-1]
self.version = ver.replace('_', '.') ver = ver[1:-1]
return self.version = ver.replace('_', '.')
return
self.version = None self.version = None
def detect_src_modules(self): def detect_src_modules(self):

@ -1032,7 +1032,8 @@ class Interpreter():
mesonfile = os.path.join(self.source_root, self.subdir, environment.build_filename) mesonfile = os.path.join(self.source_root, self.subdir, environment.build_filename)
if not os.path.isfile(mesonfile): if not os.path.isfile(mesonfile):
raise InvalidArguments('Missing Meson file in %s' % mesonfile) raise InvalidArguments('Missing Meson file in %s' % mesonfile)
code = open(mesonfile, encoding='utf8').read() with open(mesonfile, encoding='utf8') as mf:
code = mf.read()
if len(code.strip()) == 0: if len(code.strip()) == 0:
raise InvalidCode('Builder file is empty.') raise InvalidCode('Builder file is empty.')
assert(isinstance(code, str)) assert(isinstance(code, str))
@ -2006,7 +2007,8 @@ class Interpreter():
if not os.path.isfile(absname): if not os.path.isfile(absname):
self.subdir = prev_subdir self.subdir = prev_subdir
raise InterpreterException('Nonexistant build def file %s.' % buildfilename) raise InterpreterException('Nonexistant build def file %s.' % buildfilename)
code = open(absname, encoding='utf8').read() with open(absname, encoding='utf8') as f:
code = f.read()
assert(isinstance(code, str)) assert(isinstance(code, str))
try: try:
codeblock = mparser.Parser(code).parse() codeblock = mparser.Parser(code).parse()

@ -36,15 +36,18 @@ class Conf:
self.build_file = os.path.join(build_dir, 'meson-private/build.dat') self.build_file = os.path.join(build_dir, 'meson-private/build.dat')
if not os.path.isfile(self.coredata_file) or not os.path.isfile(self.build_file): if not os.path.isfile(self.coredata_file) or not os.path.isfile(self.build_file):
raise ConfException('Directory %s does not seem to be a Meson build directory.' % build_dir) raise ConfException('Directory %s does not seem to be a Meson build directory.' % build_dir)
self.coredata = pickle.load(open(self.coredata_file, 'rb')) with open(self.coredata_file, 'rb') as f:
self.build = pickle.load(open(self.build_file, 'rb')) self.coredata = pickle.load(f)
with open(self.build_file, 'rb') as f:
self.build = pickle.load(f)
if self.coredata.version != coredata.version: if self.coredata.version != coredata.version:
raise ConfException('Version mismatch (%s vs %s)' % raise ConfException('Version mismatch (%s vs %s)' %
(coredata.version, self.coredata.version)) (coredata.version, self.coredata.version))
def save(self): def save(self):
# Only called if something has changed so overwrite unconditionally. # Only called if something has changed so overwrite unconditionally.
pickle.dump(self.coredata, open(self.coredata_file, 'wb')) with open(self.coredata_file, 'wb') as f:
pickle.dump(self.coredata, f)
# We don't write the build file because any changes to it # We don't write the build file because any changes to it
# are erased when Meson is executed the nex time, i.e. the next # are erased when Meson is executed the nex time, i.e. the next
# time Ninja is run. # time Ninja is run.

@ -96,7 +96,8 @@ def is_32bit():
def is_debianlike(): def is_debianlike():
try: try:
open('/etc/debian_version', 'r') with open('/etc/debian_version', 'r'):
pass
return True return True
except FileNotFoundError: except FileNotFoundError:
return False return False
@ -262,7 +263,8 @@ def do_mesondefine(line, confdata):
def do_conf_file(src, dst, confdata): def do_conf_file(src, dst, confdata):
try: try:
data = open(src).readlines() with open(src) as f:
data = f.readlines()
except Exception: except Exception:
raise MesonException('Could not read input file %s.' % src) raise MesonException('Could not read input file %s.' % src)
# Only allow (a-z, A-Z, 0-9, _, -) as valid characters for a define # Only allow (a-z, A-Z, 0-9, _, -) as valid characters for a define
@ -276,7 +278,8 @@ def do_conf_file(src, dst, confdata):
line = do_replacement(regex, line, confdata) line = do_replacement(regex, line, confdata)
result.append(line) result.append(line)
dst_tmp = dst + '~' dst_tmp = dst + '~'
open(dst_tmp, 'w').writelines(result) with open(dst_tmp, 'w') as f:
f.writelines(result)
shutil.copymode(src, dst_tmp) shutil.copymode(src, dst_tmp)
replace_if_different(dst, dst_tmp) replace_if_different(dst, dst_tmp)
@ -306,9 +309,10 @@ def replace_if_different(dst, dst_tmp):
# If contents are identical, don't touch the file to prevent # If contents are identical, don't touch the file to prevent
# unnecessary rebuilds. # unnecessary rebuilds.
try: try:
if open(dst, 'r').read() == open(dst_tmp, 'r').read(): with open(dst, 'r') as f1, open(dst_tmp, 'r') as f2:
os.unlink(dst_tmp) if f1.read() == f2.read():
return os.unlink(dst_tmp)
return
except FileNotFoundError: except FileNotFoundError:
pass pass
os.replace(dst_tmp, dst) os.replace(dst_tmp, dst)

@ -169,7 +169,8 @@ itself as required.'''
g.generate(intr) g.generate(intr)
g.run_postconf_scripts() g.run_postconf_scripts()
dumpfile = os.path.join(env.get_scratch_dir(), 'build.dat') dumpfile = os.path.join(env.get_scratch_dir(), 'build.dat')
pickle.dump(b, open(dumpfile, 'wb')) with open(dumpfile, 'wb') as f:
pickle.dump(b, f)
# Write this last since we use the existence of this file to check if # Write this last since we use the existence of this file to check if
# we generated the build file successfully, so we don't want an error # we generated the build file successfully, so we don't want an error
# that pops up during generation, post-conf scripts, etc to cause us to # that pops up during generation, post-conf scripts, etc to cause us to

@ -177,10 +177,14 @@ def run(args):
buildfile = os.path.join(bdir, 'meson-private/build.dat') buildfile = os.path.join(bdir, 'meson-private/build.dat')
testfile = os.path.join(bdir, 'meson-private/meson_test_setup.dat') testfile = os.path.join(bdir, 'meson-private/meson_test_setup.dat')
benchmarkfile = os.path.join(bdir, 'meson-private/meson_benchmark_setup.dat') benchmarkfile = os.path.join(bdir, 'meson-private/meson_benchmark_setup.dat')
coredata = pickle.load(open(corefile, 'rb')) with open(corefile, 'rb') as f:
builddata = pickle.load(open(buildfile, 'rb')) coredata = pickle.load(f)
testdata = pickle.load(open(testfile, 'rb')) with open(buildfile, 'rb') as f:
benchmarkdata = pickle.load(open(benchmarkfile, 'rb')) builddata = pickle.load(f)
with open(testfile, 'rb') as f:
testdata = pickle.load(f)
with open(benchmarkfile, 'rb') as f:
benchmarkdata = pickle.load(f)
if options.list_targets: if options.list_targets:
list_targets(coredata, builddata) list_targets(coredata, builddata)
elif options.target_files is not None: elif options.target_files is not None:

@ -23,37 +23,41 @@ class PkgConfigModule:
def generate_pkgconfig_file(self, state, libraries, subdirs, name, description, version, filebase, def generate_pkgconfig_file(self, state, libraries, subdirs, name, description, version, filebase,
pub_reqs, priv_reqs, priv_libs): pub_reqs, priv_reqs, priv_libs):
coredata = state.environment.get_coredata()
outdir = state.environment.scratch_dir outdir = state.environment.scratch_dir
fname = os.path.join(outdir, filebase + '.pc') fname = os.path.join(outdir, filebase + '.pc')
ofile = open(fname, 'w') with open(fname, 'w') as ofile:
coredata = state.environment.get_coredata() ofile.write('prefix=%s\n' % coredata.get_builtin_option('prefix'))
ofile.write('prefix=%s\n' % coredata.get_builtin_option('prefix')) ofile.write('libdir=${prefix}/%s\n' %
ofile.write('libdir=${prefix}/%s\n' % coredata.get_builtin_option('libdir')) coredata.get_builtin_option('libdir'))
ofile.write('includedir=${prefix}/%s\n\n' % coredata.get_builtin_option('includedir')) ofile.write('includedir=${prefix}/%s\n\n' %
ofile.write('Name: %s\n' % name) coredata.get_builtin_option('includedir'))
if len(description) > 0: ofile.write('Name: %s\n' % name)
ofile.write('Description: %s\n' % description) if len(description) > 0:
if len(version) > 0: ofile.write('Description: %s\n' % description)
ofile.write('Version: %s\n' % version) if len(version) > 0:
if len(pub_reqs) > 0: ofile.write('Version: %s\n' % version)
ofile.write('Requires: {}\n'.format(' '.join(pub_reqs))) if len(pub_reqs) > 0:
if len(priv_reqs) > 0: ofile.write('Requires: {}\n'.format(' '.join(pub_reqs)))
ofile.write('Requires.private: {}\n'.format(' '.join(priv_reqs))) if len(priv_reqs) > 0:
if len(priv_libs) > 0: ofile.write(
ofile.write('Libraries.private: {}\n'.format(' '.join(priv_libs))) 'Requires.private: {}\n'.format(' '.join(priv_reqs)))
ofile.write('Libs: -L${libdir} ') if len(priv_libs) > 0:
for l in libraries: ofile.write(
if l.custom_install_dir: 'Libraries.private: {}\n'.format(' '.join(priv_libs)))
ofile.write('-L${prefix}/%s ' % l.custom_install_dir) ofile.write('Libs: -L${libdir} ')
ofile.write('-l%s ' % l.name) for l in libraries:
ofile.write('\n') if l.custom_install_dir:
ofile.write('CFlags: ') ofile.write('-L${prefix}/%s ' % l.custom_install_dir)
for h in subdirs: ofile.write('-l%s ' % l.name)
if h == '.': ofile.write('\n')
h = '' ofile.write('CFlags: ')
ofile.write(os.path.join('-I${includedir}', h)) for h in subdirs:
ofile.write(' ') if h == '.':
ofile.write('\n') h = ''
ofile.write(os.path.join('-I${includedir}', h))
ofile.write(' ')
ofile.write('\n')
def generate(self, state, args, kwargs): def generate(self, state, args, kwargs):
if len(args) > 0: if len(args) > 0:

@ -80,82 +80,87 @@ class RPMModule:
files.add('%%{_mandir}/man%u/%s.*' % (int(man_file.split('.')[-1]), man_file)) files.add('%%{_mandir}/man%u/%s.*' % (int(man_file.split('.')[-1]), man_file))
if len(files_devel) > 0: if len(files_devel) > 0:
devel_subpkg = True devel_subpkg = True
fn = open('%s.spec' % os.path.join(state.environment.get_build_dir(), proj), 'w+') filename = os.path.join(state.environment.get_build_dir(),
fn.write('Name: %s\n' % proj) '%s.spec' % proj)
fn.write('Version: # FIXME\n') with open(filename, 'w+') as fn:
fn.write('Release: 1%{?dist}\n') fn.write('Name: %s\n' % proj)
fn.write('Summary: # FIXME\n') fn.write('Version: # FIXME\n')
fn.write('License: # FIXME\n') fn.write('Release: 1%{?dist}\n')
fn.write('\n') fn.write('Summary: # FIXME\n')
fn.write('Source0: %{name}-%{version}.tar.xz # FIXME\n') fn.write('License: # FIXME\n')
fn.write('\n') fn.write('\n')
for compiler in compiler_deps: fn.write('Source0: %{name}-%{version}.tar.xz # FIXME\n')
fn.write('BuildRequires: %s\n' % compiler) fn.write('\n')
for dep in state.environment.coredata.deps: for compiler in compiler_deps:
fn.write('BuildRequires: pkgconfig(%s)\n' % dep) fn.write('BuildRequires: %s\n' % compiler)
for lib in state.environment.coredata.ext_libs.values(): for dep in state.environment.coredata.deps:
fn.write('BuildRequires: %s # FIXME\n' % lib.fullpath) fn.write('BuildRequires: pkgconfig(%s)\n' % dep)
mlog.log('Warning, replace', mlog.bold(lib.fullpath), 'with real package.', for lib in state.environment.coredata.ext_libs.values():
'You can use following command to find package which contains this lib:', fn.write('BuildRequires: %s # FIXME\n' % lib.fullpath)
mlog.bold('dnf provides %s' % lib.fullpath)) mlog.log('Warning, replace', mlog.bold(lib.fullpath),
for prog in state.environment.coredata.ext_progs.values(): 'with real package.',
if not prog.found(): 'You can use following command to find package which '
fn.write('BuildRequires: /usr/bin/%s # FIXME\n' % prog.get_name()) 'contains this lib:',
else: mlog.bold('dnf provides %s' % lib.fullpath))
fn.write('BuildRequires: %s\n' % ' '.join(prog.fullpath)) for prog in state.environment.coredata.ext_progs.values():
fn.write('BuildRequires: meson\n') if not prog.found():
fn.write('\n') fn.write('BuildRequires: /usr/bin/%s # FIXME\n' %
fn.write('%description\n') prog.get_name())
fn.write('\n') else:
if devel_subpkg: fn.write('BuildRequires: %s\n' % ' '.join(prog.fullpath))
fn.write('%package devel\n') fn.write('BuildRequires: meson\n')
fn.write('Summary: Development files for %{name}\n') fn.write('\n')
fn.write('Requires: %{name}%{?_isa} = %{version}-%{release}\n') fn.write('%description\n')
fn.write('\n') fn.write('\n')
fn.write('%description devel\n') if devel_subpkg:
fn.write('Development files for %{name}.\n') fn.write('%package devel\n')
fn.write('Summary: Development files for %{name}\n')
fn.write('Requires: %{name}%{?_isa} = %{version}-%{release}\n')
fn.write('\n')
fn.write('%description devel\n')
fn.write('Development files for %{name}.\n')
fn.write('\n')
fn.write('%prep\n')
fn.write('%autosetup\n')
fn.write('rm -rf rpmbuilddir && mkdir rpmbuilddir\n')
fn.write('\n') fn.write('\n')
fn.write('%prep\n') fn.write('%build\n')
fn.write('%autosetup\n') fn.write('pushd rpmbuilddir\n')
fn.write('rm -rf rpmbuilddir && mkdir rpmbuilddir\n') fn.write(' %meson ..\n')
fn.write('\n') fn.write(' ninja-build -v\n')
fn.write('%build\n') fn.write('popd\n')
fn.write('pushd rpmbuilddir\n') fn.write('\n')
fn.write(' %meson ..\n') fn.write('%install\n')
fn.write(' ninja-build -v\n') fn.write('pushd rpmbuilddir\n')
fn.write('popd\n') fn.write(' DESTDIR=%{buildroot} ninja-build -v install\n')
fn.write('\n') fn.write('popd\n')
fn.write('%install\n') if len(to_delete) > 0:
fn.write('pushd rpmbuilddir\n') fn.write('rm -rf %s\n' % ' '.join(to_delete))
fn.write(' DESTDIR=%{buildroot} ninja-build -v install\n') fn.write('\n')
fn.write('popd\n') fn.write('%check\n')
if len(to_delete) > 0: fn.write('pushd rpmbuilddir\n')
fn.write('rm -rf %s\n' % ' '.join(to_delete)) fn.write(' ninja-build -v test\n')
fn.write('\n') fn.write('popd\n')
fn.write('%check\n') fn.write('\n')
fn.write('pushd rpmbuilddir\n') fn.write('%files\n')
fn.write(' ninja-build -v test\n') for f in files:
fn.write('popd\n')
fn.write('\n')
fn.write('%files\n')
for f in files:
fn.write('%s\n' % f)
fn.write('\n')
if devel_subpkg:
fn.write('%files devel\n')
for f in files_devel:
fn.write('%s\n' % f) fn.write('%s\n' % f)
fn.write('\n') fn.write('\n')
if so_installed: if devel_subpkg:
fn.write('%post -p /sbin/ldconfig\n') fn.write('%files devel\n')
for f in files_devel:
fn.write('%s\n' % f)
fn.write('\n')
if so_installed:
fn.write('%post -p /sbin/ldconfig\n')
fn.write('\n')
fn.write('%postun -p /sbin/ldconfig\n')
fn.write('\n')
fn.write('%changelog\n')
fn.write('* %s meson <meson@example.com> - \n' %
datetime.date.today().strftime('%a %b %d %Y'))
fn.write('- \n')
fn.write('\n') fn.write('\n')
fn.write('%postun -p /sbin/ldconfig\n')
fn.write('\n')
fn.write('%changelog\n')
fn.write('* %s meson <meson@example.com> - \n' % datetime.date.today().strftime('%a %b %d %Y'))
fn.write('- \n')
fn.write('\n')
fn.close()
mlog.log('RPM spec template written to %s.spec.\n' % proj) mlog.log('RPM spec template written to %s.spec.\n' % proj)
def initialize(): def initialize():

@ -78,7 +78,8 @@ class OptionInterpreter:
def process(self, option_file): def process(self, option_file):
try: try:
ast = mparser.Parser(open(option_file, 'r', encoding='utf8').read()).parse() with open(option_file, 'r', encoding='utf8') as f:
ast = mparser.Parser(f.read()).parse()
except mesonlib.MesonException as me: except mesonlib.MesonException as me:
me.file = option_file me.file = option_file
raise me raise me

@ -115,11 +115,21 @@ class Elf(DataSizes):
self.bfile = bfile self.bfile = bfile
self.verbose = verbose self.verbose = verbose
self.bf = open(bfile, 'r+b') self.bf = open(bfile, 'r+b')
(self.ptrsize, self.is_le) = self.detect_elf_type() try:
super().__init__(self.ptrsize, self.is_le) (self.ptrsize, self.is_le) = self.detect_elf_type()
self.parse_header() super().__init__(self.ptrsize, self.is_le)
self.parse_sections() self.parse_header()
self.parse_dynamic() self.parse_sections()
self.parse_dynamic()
except:
self.bf.close()
raise
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.bf.close()
def detect_elf_type(self): def detect_elf_type(self):
data = self.bf.read(6) data = self.bf.read(6)
@ -308,13 +318,13 @@ def run(args):
print('Don\'t run this unless you know what you are doing.') print('Don\'t run this unless you know what you are doing.')
print('%s: <binary file> <prefix>' % sys.argv[0]) print('%s: <binary file> <prefix>' % sys.argv[0])
exit(1) exit(1)
e = Elf(args[0]) with Elf(args[0]) as e:
if len(args) == 1: if len(args) == 1:
e.print_rpath() e.print_rpath()
e.print_runpath() e.print_runpath()
else: else:
new_rpath = args[1] new_rpath = args[1]
e.fix_rpath(new_rpath) e.fix_rpath(new_rpath)
return 0 return 0
if __name__ == '__main__': if __name__ == '__main__':

@ -52,33 +52,34 @@ def run_benchmarks(options, datafile):
failed_tests = 0 failed_tests = 0
logfile_base = 'meson-logs/benchmarklog' logfile_base = 'meson-logs/benchmarklog'
jsonlogfilename = logfile_base+ '.json' jsonlogfilename = logfile_base+ '.json'
jsonlogfile = open(jsonlogfilename, 'w') with open(datafile, 'rb') as f:
tests = pickle.load(open(datafile, 'rb')) tests = pickle.load(f)
num_tests = len(tests) num_tests = len(tests)
if num_tests == 0: if num_tests == 0:
print('No benchmarks defined.') print('No benchmarks defined.')
return 0 return 0
iteration_count = 5 iteration_count = 5
wrap = [] # Benchmarks on cross builds are pointless so don't support them. wrap = [] # Benchmarks on cross builds are pointless so don't support them.
for i, test in enumerate(tests): with open(jsonlogfilename, 'w') as jsonlogfile:
runs = [] for i, test in enumerate(tests):
durations = [] runs = []
failed = False durations = []
for _ in range(iteration_count): failed = False
res = meson_test.run_single_test(wrap, test) for _ in range(iteration_count):
runs.append(res) res = meson_test.run_single_test(wrap, test)
durations.append(res.duration) runs.append(res)
if res.returncode != 0: durations.append(res.duration)
failed = True if res.returncode != 0:
mean = statistics.mean(durations) failed = True
stddev = statistics.stdev(durations) mean = statistics.mean(durations)
if failed: stddev = statistics.stdev(durations)
resultstr = 'FAIL' if failed:
failed_tests += 1 resultstr = 'FAIL'
else: failed_tests += 1
resultstr = 'OK' else:
print_stats(3, num_tests, test.name, resultstr, i, mean, stddev) resultstr = 'OK'
print_json_log(jsonlogfile, runs, test.name, i) print_stats(3, num_tests, test.name, resultstr, i, mean, stddev)
print_json_log(jsonlogfile, runs, test.name, i)
print('\nFull log written to meson-logs/benchmarklog.json.') print('\nFull log written to meson-logs/benchmarklog.json.')
return failed_tests return failed_tests

@ -74,7 +74,8 @@ def run(args):
print('Test runner for Meson. Do not run on your own, mmm\'kay?') print('Test runner for Meson. Do not run on your own, mmm\'kay?')
print(sys.argv[0] + ' [data file]') print(sys.argv[0] + ' [data file]')
exe_data_file = options.args[0] exe_data_file = options.args[0]
exe = pickle.load(open(exe_data_file, 'rb')) with open(exe_data_file, 'rb') as f:
exe = pickle.load(f)
return run_exe(exe) return run_exe(exe)
if __name__ == '__main__': if __name__ == '__main__':

@ -45,8 +45,8 @@ def get_destdir_path(d, path):
return output return output
def do_install(datafilename): def do_install(datafilename):
ifile = open(datafilename, 'rb') with open(datafilename, 'rb') as ifile:
d = pickle.load(ifile) d = pickle.load(ifile)
d.destdir = os.environ.get('DESTDIR', '') d.destdir = os.environ.get('DESTDIR', '')
d.fullprefix = destdir_join(d.destdir, d.prefix) d.fullprefix = destdir_join(d.destdir, d.prefix)
@ -110,7 +110,9 @@ def install_man(d):
os.makedirs(outdir, exist_ok=True) os.makedirs(outdir, exist_ok=True)
print('Installing %s to %s.' % (full_source_filename, outdir)) print('Installing %s to %s.' % (full_source_filename, outdir))
if outfilename.endswith('.gz') and not full_source_filename.endswith('.gz'): if outfilename.endswith('.gz') and not full_source_filename.endswith('.gz'):
open(outfilename, 'wb').write(gzip.compress(open(full_source_filename, 'rb').read())) with open(outfilename, 'wb') as of:
with open(full_source_filename, 'rb') as sf:
of.write(gzip.compress(sf.read()))
shutil.copystat(full_source_filename, outfilename) shutil.copystat(full_source_filename, outfilename)
append_to_log(outfilename) append_to_log(outfilename)
else: else:
@ -140,7 +142,8 @@ def run_install_script(d):
print('Running custom install script %s' % script) print('Running custom install script %s' % script)
suffix = os.path.splitext(script)[1].lower() suffix = os.path.splitext(script)[1].lower()
if platform.system().lower() == 'windows' and suffix != '.bat': if platform.system().lower() == 'windows' and suffix != '.bat':
first_line = open(script, encoding='latin_1', errors='ignore').readline().strip() with open(script, encoding='latin_1', errors='ignore') as f:
first_line = f.readline().strip()
if first_line.startswith('#!'): if first_line.startswith('#!'):
if shutil.which(first_line[2:]): if shutil.which(first_line[2:]):
commands = [first_line[2:]] commands = [first_line[2:]]

@ -202,10 +202,8 @@ def run_tests(datafilename):
wrap = [options.wrapper] wrap = [options.wrapper]
logfilename = logfile_base + '-' + options.wrapper.replace(' ', '_') + '.txt' logfilename = logfile_base + '-' + options.wrapper.replace(' ', '_') + '.txt'
jsonlogfilename = logfile_base + '-' + options.wrapper.replace(' ', '_') + '.json' jsonlogfilename = logfile_base + '-' + options.wrapper.replace(' ', '_') + '.json'
logfile = open(logfilename, 'w') with open(datafilename, 'rb') as f:
jsonlogfile = open(jsonlogfilename, 'w') tests = pickle.load(f)
logfile.write('Log of Meson test suite run on %s.\n\n' % datetime.datetime.now().isoformat())
tests = pickle.load(open(datafilename, 'rb'))
if len(tests) == 0: if len(tests) == 0:
print('No tests defined.') print('No tests defined.')
return return
@ -222,24 +220,31 @@ def run_tests(datafilename):
executor = conc.ThreadPoolExecutor(max_workers=num_workers) executor = conc.ThreadPoolExecutor(max_workers=num_workers)
futures = [] futures = []
filtered_tests = filter_tests(options.suite, tests) filtered_tests = filter_tests(options.suite, tests)
for i, test in enumerate(filtered_tests):
if test.suite[0] == '': with open(jsonlogfilename, 'w') as jsonlogfile, \
visible_name = test.name open(logfilename, 'w') as logfile:
else: logfile.write('Log of Meson test suite run on %s.\n\n' %
if options.suite is not None: datetime.datetime.now().isoformat())
visible_name = options.suite + ' / ' + test.name for i, test in enumerate(filtered_tests):
if test.suite[0] == '':
visible_name = test.name
else: else:
visible_name = test.suite[0] + ' / ' + test.name if options.suite is not None:
visible_name = options.suite + ' / ' + test.name
else:
visible_name = test.suite[0] + ' / ' + test.name
if not test.is_parallel: if not test.is_parallel:
drain_futures(futures) drain_futures(futures)
futures = [] futures = []
res = run_single_test(wrap, test) res = run_single_test(wrap, test)
print_stats(numlen, filtered_tests, visible_name, res, i, logfile, jsonlogfile) print_stats(numlen, filtered_tests, visible_name, res, i,
else: logfile, jsonlogfile)
f = executor.submit(run_single_test, wrap, test) else:
futures.append((f, numlen, filtered_tests, visible_name, i, logfile, jsonlogfile)) f = executor.submit(run_single_test, wrap, test)
drain_futures(futures) futures.append((f, numlen, filtered_tests, visible_name, i,
logfile, jsonlogfile))
drain_futures(futures)
return logfilename return logfilename
def run(args): def run(args):

@ -48,8 +48,10 @@ def run(args):
private_dir = args[0] private_dir = args[0]
dumpfile = os.path.join(private_dir, 'regeninfo.dump') dumpfile = os.path.join(private_dir, 'regeninfo.dump')
coredata = os.path.join(private_dir, 'coredata.dat') coredata = os.path.join(private_dir, 'coredata.dat')
regeninfo = pickle.load(open(dumpfile, 'rb')) with open(dumpfile, 'rb') as f:
coredata = pickle.load(open(coredata, 'rb')) regeninfo = pickle.load(f)
with open(coredata, 'rb') as f:
coredata = pickle.load(f)
mesonscript = coredata.meson_script_file mesonscript = coredata.meson_script_file
backend = coredata.get_builtin_option('backend') backend = coredata.get_builtin_option('backend')
regen_timestamp = os.stat(dumpfile).st_mtime regen_timestamp = os.stat(dumpfile).st_mtime

@ -34,16 +34,19 @@ parser.add_argument('args', nargs='+')
def dummy_syms(outfilename): def dummy_syms(outfilename):
"""Just touch it so relinking happens always.""" """Just touch it so relinking happens always."""
open(outfilename, 'w').close() with open(outfilename, 'w'):
pass
def write_if_changed(text, outfilename): def write_if_changed(text, outfilename):
try: try:
oldtext = open(outfilename, 'r').read() with open(outfilename, 'r') as f:
oldtext = f.read()
if text == oldtext: if text == oldtext:
return return
except FileNotFoundError: except FileNotFoundError:
pass pass
open(outfilename, 'w').write(text) with open(outfilename, 'w') as f:
f.write(text)
def linux_syms(libfilename, outfilename): def linux_syms(libfilename, outfilename):
pe = subprocess.Popen(['readelf', '-d', libfilename], stdout=subprocess.PIPE, stderr=subprocess.PIPE) pe = subprocess.Popen(['readelf', '-d', libfilename], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

@ -23,9 +23,16 @@ def config_vcs_tag(infile, outfile, fallback, source_dir, replace_string, regex_
except Exception: except Exception:
new_string = fallback new_string = fallback
new_data = open(infile).read().replace(replace_string, new_string) with open(infile) as f:
if (not os.path.exists(outfile)) or (open(outfile).read() != new_data): new_data = f.read().replace(replace_string, new_string)
open(outfile, 'w').write(new_data) if os.path.exists(outfile):
with open(outfile) as f:
needs_update = (f.read() != new_data)
else:
needs_update = True
if needs_update:
with open(outfile, 'w') as f:
f.write(new_data)
def run(args): def run(args):
infile, outfile, fallback, source_dir, replace_string, regex_selector = args[0:6] infile, outfile, fallback, source_dir, replace_string, regex_selector = args[0:6]

@ -13,6 +13,7 @@
# limitations under the License. # limitations under the License.
from .. import mlog from .. import mlog
import contextlib
import urllib.request, os, hashlib, shutil import urllib.request, os, hashlib, shutil
import subprocess import subprocess
import sys import sys
@ -58,23 +59,23 @@ def open_wrapdburl(urlstring):
class PackageDefinition: class PackageDefinition:
def __init__(self, fname): def __init__(self, fname):
self.values = {} self.values = {}
ifile = open(fname) with open(fname) as ifile:
first = ifile.readline().strip() first = ifile.readline().strip()
if first == '[wrap-file]': if first == '[wrap-file]':
self.type = 'file' self.type = 'file'
elif first == '[wrap-git]': elif first == '[wrap-git]':
self.type = 'git' self.type = 'git'
else: else:
raise RuntimeError('Invalid format of package file') raise RuntimeError('Invalid format of package file')
for line in ifile: for line in ifile:
line = line.strip() line = line.strip()
if line == '': if line == '':
continue continue
(k, v) = line.split('=', 1) (k, v) = line.split('=', 1)
k = k.strip() k = k.strip()
v = v.strip() v = v.strip()
self.values[k] = v self.values[k] = v
def get(self, key): def get(self, key):
return self.values[key] return self.values[key]
@ -137,26 +138,26 @@ class Resolver:
resp = open_wrapdburl(url) resp = open_wrapdburl(url)
else: else:
resp = urllib.request.urlopen(url) resp = urllib.request.urlopen(url)
dlsize = int(resp.info()['Content-Length']) with contextlib.closing(resp) as resp:
print('Download size:', dlsize) dlsize = int(resp.info()['Content-Length'])
print('Downloading: ', end='') print('Download size:', dlsize)
sys.stdout.flush() print('Downloading: ', end='')
printed_dots = 0 sys.stdout.flush()
blocks = [] printed_dots = 0
downloaded = 0 blocks = []
while True: downloaded = 0
block = resp.read(blocksize) while True:
if block == b'': block = resp.read(blocksize)
break if block == b'':
downloaded += len(block) break
blocks.append(block) downloaded += len(block)
ratio = int(downloaded/dlsize * 10) blocks.append(block)
while printed_dots < ratio: ratio = int(downloaded/dlsize * 10)
print('.', end='') while printed_dots < ratio:
sys.stdout.flush() print('.', end='')
printed_dots += 1 sys.stdout.flush()
print('') printed_dots += 1
resp.close() print('')
return b''.join(blocks) return b''.join(blocks)
def get_hash(self, data): def get_hash(self, data):
@ -177,7 +178,8 @@ class Resolver:
expected = p.get('source_hash') expected = p.get('source_hash')
if dhash != expected: if dhash != expected:
raise RuntimeError('Incorrect hash for source %s:\n %s expected\n %s actual.' % (packagename, expected, dhash)) raise RuntimeError('Incorrect hash for source %s:\n %s expected\n %s actual.' % (packagename, expected, dhash))
open(ofname, 'wb').write(srcdata) with open(ofname, 'wb') as f:
f.write(srcdata)
if p.has_patch(): if p.has_patch():
purl = p.get('patch_url') purl = p.get('patch_url')
mlog.log('Downloading patch from', mlog.bold(purl)) mlog.log('Downloading patch from', mlog.bold(purl))
@ -186,7 +188,9 @@ class Resolver:
expected = p.get('patch_hash') expected = p.get('patch_hash')
if phash != expected: if phash != expected:
raise RuntimeError('Incorrect hash for patch %s:\n %s expected\n %s actual' % (packagename, expected, phash)) raise RuntimeError('Incorrect hash for patch %s:\n %s expected\n %s actual' % (packagename, expected, phash))
open(os.path.join(self.cachedir, p.get('patch_filename')), 'wb').write(pdata) filename = os.path.join(self.cachedir, p.get('patch_filename'))
with open(filename, 'wb') as f:
f.write(pdata)
else: else:
mlog.log('Package does not require patch.') mlog.log('Package does not require patch.')

@ -92,7 +92,8 @@ def install(name):
(branch, revision) = get_latest_version(name) (branch, revision) = get_latest_version(name)
u = open_wrapdburl(API_ROOT + 'projects/%s/%s/%s/get_wrap' % (name, branch, revision)) u = open_wrapdburl(API_ROOT + 'projects/%s/%s/%s/get_wrap' % (name, branch, revision))
data = u.read() data = u.read()
open(wrapfile, 'wb').write(data) with open(wrapfile, 'wb') as f:
f.write(data)
print('Installed', name, 'branch', branch, 'revision', revision) print('Installed', name, 'branch', branch, 'revision', revision)
def get_current_version(wrapfile): def get_current_version(wrapfile):
@ -129,7 +130,8 @@ def update(name):
os.unlink(os.path.join('subprojects/packagecache', patch_file)) os.unlink(os.path.join('subprojects/packagecache', patch_file))
except FileNotFoundError: except FileNotFoundError:
pass pass
open(wrapfile, 'wb').write(data) with open(wrapfile, 'wb') as f:
f.write(data)
print('Updated', name, 'to branch', new_branch, 'revision', new_revision) print('Updated', name, 'to branch', new_branch, 'revision', new_revision)
def info(name): def info(name):

@ -156,8 +156,9 @@ def validate_install(srcdir, installdir):
if os.path.exists(os.path.join(installdir, noinst_file)): if os.path.exists(os.path.join(installdir, noinst_file)):
expected[noinst_file] = False expected[noinst_file] = False
elif os.path.exists(info_file): elif os.path.exists(info_file):
for line in open(info_file): with open(info_file) as f:
expected[platform_fix_exe_name(line.strip())] = False for line in f:
expected[platform_fix_exe_name(line.strip())] = False
# Check if expected files were found # Check if expected files were found
for fname in expected: for fname in expected:
if os.path.exists(os.path.join(installdir, fname)): if os.path.exists(os.path.join(installdir, fname)):
@ -249,7 +250,8 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, flags, compile_c
(returncode, stdo, stde) = run_configure_inprocess(gen_command) (returncode, stdo, stde) = run_configure_inprocess(gen_command)
try: try:
logfile = os.path.join(test_build_dir, 'meson-logs/meson-log.txt') logfile = os.path.join(test_build_dir, 'meson-logs/meson-log.txt')
mesonlog = open(logfile, errors='ignore').read() with open(logfile, errors='ignore') as f:
mesonlog = f.read()
except Exception: except Exception:
mesonlog = 'No meson-log.txt found.' mesonlog = 'No meson-log.txt found.'
gen_time = time.time() - gen_start gen_time = time.time() - gen_start
@ -401,7 +403,9 @@ def run_tests(extra_args):
def check_file(fname): def check_file(fname):
linenum = 1 linenum = 1
for line in open(fname, 'rb').readlines(): with open(fname, 'rb') as f:
lines = f.readlines()
for line in lines:
if b'\t' in line: if b'\t' in line:
print("File %s contains a literal tab on line %d. Only spaces are permitted." % (fname, linenum)) print("File %s contains a literal tab on line %d. Only spaces are permitted." % (fname, linenum))
sys.exit(1) sys.exit(1)

@ -6,7 +6,8 @@
import sys, os import sys, os
import shutil, subprocess import shutil, subprocess
funcname = open(sys.argv[1]).readline().strip() with open(sys.argv[1]) as f:
funcname = f.readline().strip()
outdir = sys.argv[2] outdir = sys.argv[2]
if not os.path.isdir(outdir): if not os.path.isdir(outdir):
@ -44,19 +45,22 @@ outc = os.path.join(outdir, funcname + '.c')
tmpc = 'diibadaaba.c' tmpc = 'diibadaaba.c'
tmpo = 'diibadaaba' + objsuffix tmpo = 'diibadaaba' + objsuffix
open(outc, 'w').write('''#include"%s.h" with open(outc, 'w') as f:
f.write('''#include"%s.h"
int %s_in_src() { int %s_in_src() {
return 0; return 0;
} }
''' % (funcname, funcname)) ''' % (funcname, funcname))
open(outh, 'w').write('''#pragma once with open(outh, 'w') as f:
f.write('''#pragma once
int %s_in_lib(); int %s_in_lib();
int %s_in_obj(); int %s_in_obj();
int %s_in_src(); int %s_in_src();
''' % (funcname, funcname, funcname)) ''' % (funcname, funcname, funcname))
open(tmpc, 'w').write('''int %s_in_obj() { with open(tmpc, 'w') as f:
f.write('''int %s_in_obj() {
return 0; return 0;
} }
''' % funcname) ''' % funcname)
@ -66,7 +70,8 @@ if is_vs:
else: else:
subprocess.check_call([compiler, '-c', '-o', outo, tmpc]) subprocess.check_call([compiler, '-c', '-o', outo, tmpc])
open(tmpc, 'w').write('''int %s_in_lib() { with open(tmpc, 'w') as f:
f.write('''int %s_in_lib() {
return 0; return 0;
} }
''' % funcname) ''' % funcname)

@ -7,5 +7,10 @@ template = '''#pragma once
#define THE_NUMBER {} #define THE_NUMBER {}
''' '''
data = open(os.path.join(os.environ['MESON_SOURCE_ROOT'], 'raw.dat')).readline().strip() input_file = os.path.join(os.environ['MESON_SOURCE_ROOT'], 'raw.dat')
open(os.path.join(os.environ['MESON_BUILD_ROOT'], 'generated.h'), 'w').write(template.format(data)) output_file = os.path.join(os.environ['MESON_BUILD_ROOT'], 'generated.h')
with open(input_file) as f:
data = f.readline().strip()
with open(output_file, 'w') as f:
f.write(template.format(data))

@ -9,5 +9,10 @@ template = '''#pragma once
#define THE_ARG2 {} #define THE_ARG2 {}
''' '''
data = open(os.path.join(os.environ['MESON_SOURCE_ROOT'], 'raw.dat')).readline().strip() input_file = os.path.join(os.environ['MESON_SOURCE_ROOT'], 'raw.dat')
open(os.path.join(os.environ['MESON_BUILD_ROOT'], 'generated.h'), 'w').write(template.format(data, sys.argv[1], sys.argv[2])) output_file = os.path.join(os.environ['MESON_BUILD_ROOT'], 'generated.h')
with open(input_file) as f:
data = f.readline().strip()
with open(output_file, 'w') as f:
f.write(template.format(data, sys.argv[1], sys.argv[2]))

@ -8,6 +8,7 @@ inputs = sys.argv[1:-1]
with open(output, 'w') as ofile: with open(output, 'w') as ofile:
ofile.write('#pragma once\n') ofile.write('#pragma once\n')
for i in inputs: for i in inputs:
content = open(i, 'r').read() with open(i, 'r') as ifile:
content = ifile.read()
ofile.write(content) ofile.write(content)
ofile.write('\n') ofile.write('\n')

@ -5,7 +5,9 @@ import sys, os
ifile = sys.argv[1] ifile = sys.argv[1]
ofile = sys.argv[2] ofile = sys.argv[2]
resname = open(ifile, 'r').readline().strip() with open(ifile, 'r') as f:
resname = f.readline().strip()
templ = 'const char %s[] = "%s";\n' templ = 'const char %s[] = "%s";\n'
open(ofile, 'w').write(templ % (resname, resname)) with open(ofile, 'w') as f:
f.write(templ % (resname, resname))

@ -6,7 +6,8 @@ if __name__ == '__main__':
if len(sys.argv) != 2: if len(sys.argv) != 2:
print(sys.argv[0], 'input_file') print(sys.argv[0], 'input_file')
sys.exit(1) sys.exit(1)
ifile = open(sys.argv[1]).read() with open(sys.argv[1]) as f:
ifile = f.read()
if ifile != 'This is a text only input file.\n': if ifile != 'This is a text only input file.\n':
print('Malformed input') print('Malformed input')
sys.exit(1) sys.exit(1)

@ -6,8 +6,8 @@ if len(sys.argv) != 3:
print("Wrong amount of parameters.") print("Wrong amount of parameters.")
# Just test that it exists. # Just test that it exists.
ifile = open(sys.argv[1], 'r') with open(sys.argv[1], 'r') as ifile:
pass
ofile = open(sys.argv[2], 'w') with open(sys.argv[2], 'w') as ofile:
ofile.write("#define ZERO_RESULT 0\n") ofile.write("#define ZERO_RESULT 0\n")
ofile.close()

@ -2,5 +2,6 @@
import sys import sys
if open(sys.argv[1]).read() != 'contents\n': with open(sys.argv[1]) as f:
sys.exit(1) if f.read() != 'contents\n':
sys.exit(1)

@ -9,5 +9,7 @@ depfiles = glob(os.path.join(srcdir, '*'))
quoted_depfiles = [x.replace(' ', '\ ') for x in depfiles] quoted_depfiles = [x.replace(' ', '\ ') for x in depfiles]
open(output, 'w').write('I am the result of globbing.') with open(output, 'w') as f:
open(depfile, 'w').write('%s: %s\n' % (output, ' '.join(quoted_depfiles))) f.write('I am the result of globbing.')
with open(depfile, 'w') as f:
f.write('%s: %s\n' % (output, ' '.join(quoted_depfiles)))

@ -6,9 +6,10 @@ if __name__ == '__main__':
if len(sys.argv) != 3: if len(sys.argv) != 3:
print(sys.argv[0], 'input_file output_file') print(sys.argv[0], 'input_file output_file')
sys.exit(1) sys.exit(1)
ifile = open(sys.argv[1]).read() with open(sys.argv[1]) as f:
ifile = f.read()
if ifile != 'This is a text only input file.\n': if ifile != 'This is a text only input file.\n':
print('Malformed input') print('Malformed input')
sys.exit(1) sys.exit(1)
ofile = open(sys.argv[2], 'w') with open(sys.argv[2], 'w') as ofile:
ofile.write('This is a binary output file.\n') ofile.write('This is a binary output file.\n')

@ -6,9 +6,10 @@ if __name__ == '__main__':
if len(sys.argv) != 3: if len(sys.argv) != 3:
print(sys.argv[0], 'input_file output_file') print(sys.argv[0], 'input_file output_file')
sys.exit(1) sys.exit(1)
ifile = open(sys.argv[1]).read() with open(sys.argv[1]) as f:
ifile = f.read()
if ifile != 'This is a text only input file.\n': if ifile != 'This is a text only input file.\n':
print('Malformed input') print('Malformed input')
sys.exit(1) sys.exit(1)
ofile = open(sys.argv[2], 'w') with open(sys.argv[2], 'w') as ofile:
ofile.write('This is a binary output file.\n') ofile.write('This is a binary output file.\n')

@ -6,9 +6,10 @@ if __name__ == '__main__':
if len(sys.argv) != 3: if len(sys.argv) != 3:
print(sys.argv[0], 'input_file output_file') print(sys.argv[0], 'input_file output_file')
sys.exit(1) sys.exit(1)
ifile = open(sys.argv[1]).read() with open(sys.argv[1]) as f:
ifile = f.read()
if ifile != 'This is a binary output file.\n': if ifile != 'This is a binary output file.\n':
print('Malformed input') print('Malformed input')
sys.exit(1) sys.exit(1)
ofile = open(sys.argv[2], 'w') with open(sys.argv[2], 'w') as ofile:
ofile.write('This is a different binary output file.\n') ofile.write('This is a different binary output file.\n')

@ -3,5 +3,5 @@
import sys, os import sys, os
with open(sys.argv[1], 'rb') as ifile: with open(sys.argv[1], 'rb') as ifile:
open(sys.argv[2], 'w').write('Everything ok.\n') with open(sys.argv[2], 'w') as ofile:
ofile.write('Everything ok.\n')

@ -2,4 +2,5 @@
import sys import sys
open(sys.argv[2], 'wb').write(open(sys.argv[1], 'rb').read()) with open(sys.argv[1], 'rb') as ifile, open(sys.argv[2], 'wb') as ofile:
ofile.write(ifile.read())

@ -5,7 +5,8 @@ import sys
plain_arg = sys.argv[1] plain_arg = sys.argv[1]
_, filename, _ = plain_arg.split(':') _, filename, _ = plain_arg.split(':')
try: try:
content = open(filename, 'rb').read() with open(filename, 'rb') as f:
content = f.read()
except FileNotFoundError: except FileNotFoundError:
print('Could not open file. Missing dependency?') print('Could not open file. Missing dependency?')
sys.exit(1) sys.exit(1)

@ -7,8 +7,10 @@ if len(sys.argv) != 2:
odir = sys.argv[1] odir = sys.argv[1]
open(os.path.join(odir, 'mylib.h'), 'w').write('int func();\n') with open(os.path.join(odir, 'mylib.h'), 'w') as f:
open(os.path.join(odir, 'mylib.c'), 'w').write('''int func() { f.write('int func();\n')
with open(os.path.join(odir, 'mylib.c'), 'w') as f:
f.write('''int func() {
return 0; return 0;
} }
''') ''')

@ -6,5 +6,7 @@
import sys import sys
template = '#define RET_VAL %s\n' template = '#define RET_VAL %s\n'
output = template % (open(sys.argv[1]).readline().strip()) with open(sys.argv[1]) as f:
open(sys.argv[2], 'w').write(output) output = template % (f.readline().strip(), )
with open(sys.argv[2], 'w') as f:
f.write(output)

@ -6,14 +6,17 @@ if len(sys.argv) != 3:
print("You is fail.") print("You is fail.")
sys.exit(1) sys.exit(1)
val = open(sys.argv[1]).read().strip() with open(sys.argv[1]) as f:
val = f.read().strip()
outdir = sys.argv[2] outdir = sys.argv[2]
outhdr = os.path.join(outdir, 'source%s.h' % val) outhdr = os.path.join(outdir, 'source%s.h' % val)
outsrc = os.path.join(outdir, 'source%s.cpp' % val) outsrc = os.path.join(outdir, 'source%s.cpp' % val)
open(outhdr, 'w').write('int func%s();\n' % val) with open(outhdr, 'w') as f:
open(outsrc, 'w').write('''int func%s() { f.write('int func%s();\n' % val)
with open(outsrc, 'w') as f:
f.write('''int func%s() {
return 0; return 0;
} }
''' % val) ''' % val)

@ -14,14 +14,17 @@ def generate(infile, outfile, fallback):
version = stdo.decode().strip() version = stdo.decode().strip()
except: except:
pass pass
newdata = open(infile).read().replace('@VERSION@', version) with open(infile) as f:
newdata = f.read().replace('@VERSION@', version)
try: try:
olddata = open(outfile).read() with open(outfile) as f:
olddata = f.read()
if olddata == newdata: if olddata == newdata:
return return
except: except:
pass pass
open(outfile, 'w').write(newdata) with open(outfile, 'w') as f:
f.write(newdata)
if __name__ == '__main__': if __name__ == '__main__':
infile = sys.argv[1] infile = sys.argv[1]

@ -2,7 +2,8 @@
import sys import sys
ifile = open(sys.argv[1]) with open(sys.argv[1]) as ifile:
if ifile.readline().strip() != '42': if ifile.readline().strip() != '42':
print('Incorrect input') print('Incorrect input')
open(sys.argv[2], 'w').write('Success\n') with open(sys.argv[2], 'w') as ofile:
ofile.write('Success\n')

@ -6,5 +6,7 @@ import time, sys
# is missing. # is missing.
time.sleep(0.5) time.sleep(0.5)
contents = open(sys.argv[1], 'r').read() with open(sys.argv[1], 'r') as f:
open(sys.argv[2], 'w').write(contents) contents = f.read()
with open(sys.argv[2], 'w') as f:
f.write(contents)

@ -6,4 +6,5 @@ from glob import glob
files = glob(os.path.join(sys.argv[1], '*.tmp')) files = glob(os.path.join(sys.argv[1], '*.tmp'))
assert(len(files) == 1) assert(len(files) == 1)
open(sys.argv[2], 'w').write(open(files[0], 'r').read()) with open(files[0], 'r') as ifile, open(sys.argv[2], 'w') as ofile:
ofile.write(ifile.read())

@ -26,5 +26,7 @@ hfile = os.path.join(outdir, base + '.h')
c_code = c_templ % (base, base) c_code = c_templ % (base, base)
h_code = h_templ % base h_code = h_templ % base
open(cfile, 'w').write(c_code) with open(cfile, 'w') as f:
open(hfile, 'w').write(h_code) f.write(c_code)
with open(hfile, 'w') as f:
f.write(h_code)

@ -19,8 +19,10 @@ c_templ = '''int %s() {
options = parser.parse_args(sys.argv[1:]) options = parser.parse_args(sys.argv[1:])
funcname = open(options.input).readline().strip() with open(options.input) as f:
funcname = f.readline().strip()
if options.upper: if options.upper:
funcname = funcname.upper() funcname = funcname.upper()
open(options.output, 'w').write(c_templ % funcname) with open(options.output, 'w') as f:
f.write(c_templ % funcname)

@ -25,28 +25,6 @@ that are unrelated to configure checks.
import sys 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. # Add stuff here as it is encountered.
function_data = \ function_data = \
@ -242,18 +220,71 @@ function_data = \
'HAVE_PTHREAD_SET_NAME_NP': ('pthread_set_name_np', 'pthread.h'), '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]): print('''cc = meson.get_compiler('c')
try: cdata = configuration_data()''')
token = line.split()[1]
if token in function_data: # Convert header checks.
fdata = function_data[token]
print(" ['%s', '%s', '#include<%s>']," % (token, fdata[0], fdata[1])) print('check_headers = [')
elif token.startswith('HAVE_') and not token.endswith('_H'): for token, hname in headers:
print('# check token', token) print(" ['%s', '%s']," % (token, hname))
except Exception: print(']\n')
pass
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(']\n')
print('''foreach f : check_functions print('''foreach f : check_functions
@ -265,14 +296,8 @@ endforeach
# Convert sizeof checks. # Convert sizeof checks.
for line in open(sys.argv[1]): for elem, typename in size:
arr = line.strip().split() print("cdata.set('%s', cc.sizeof('%s'))" % (elem, typename))
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))
print(''' print('''
configure_file(input : 'config.h.meson', configure_file(input : 'config.h.meson',

@ -252,39 +252,46 @@ class Converter:
subdir = self.cmake_root subdir = self.cmake_root
cfile = os.path.join(subdir, 'CMakeLists.txt') cfile = os.path.join(subdir, 'CMakeLists.txt')
try: try:
cmakecode = open(cfile).read() with open(cfile) as f:
cmakecode = f.read()
except FileNotFoundError: except FileNotFoundError:
print('\nWarning: No CMakeLists.txt in', subdir, '\n') print('\nWarning: No CMakeLists.txt in', subdir, '\n')
return return
p = Parser(cmakecode) p = Parser(cmakecode)
outfile = open(os.path.join(subdir, 'meson.build'), 'w') with open(os.path.join(subdir, 'meson.build'), 'w') as outfile:
for t in p.parse(): for t in p.parse():
if t.name == 'add_subdirectory': if t.name == 'add_subdirectory':
#print('\nRecursing to subdir', os.path.join(self.cmake_root, t.args[0].value), '\n') # print('\nRecursing to subdir',
self.convert(os.path.join(subdir, t.args[0].value)) # os.path.join(self.cmake_root, t.args[0].value),
#print('\nReturning to', self.cmake_root, '\n') # '\n')
self.write_entry(outfile, t) 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: if subdir == self.cmake_root and len(self.options) > 0:
self.write_options() self.write_options()
def write_options(self): def write_options(self):
optfile = open(os.path.join(self.cmake_root, 'meson_options.txt'), 'w') filename = os.path.join(self.cmake_root, 'meson_options.txt')
for o in self.options: with open(filename, 'w') as optfile:
(optname, description, default) = o for o in self.options:
if default is None: (optname, description, default) = o
defaultstr = '' if default is None:
else: defaultstr = ''
if default == 'OFF':
typestr = ' type : boolean,'
default = 'false'
elif default == 'ON':
default = 'true'
typestr = ' type : boolean,'
else: else:
typestr = ' type : string,' if default == 'OFF':
defaultstr = ' value : %s,' % default typestr = ' type : boolean,'
line = "option(%s,%s%s description : '%s')\n" % (optname, typestr, defaultstr, description) default = 'false'
optfile.write(line) 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 __name__ == '__main__':
if len(sys.argv) != 2: if len(sys.argv) != 2:

Loading…
Cancel
Save