Added meson-info.json

pull/4732/head
Daniel Mensinger 6 years ago
parent 38241f5fce
commit ab32f1fe00
  1. 4
      mesonbuild/mconf.py
  2. 53
      mesonbuild/mintro.py
  3. 18
      mesonbuild/msetup.py
  4. 14
      run_unittests.py

@ -149,6 +149,7 @@ class Conf:
def run(options):
coredata.parse_cmd_line_options(options)
builddir = os.path.abspath(os.path.realpath(options.builddir))
c = None
try:
c = Conf(builddir)
save = False
@ -164,7 +165,10 @@ def run(options):
if save:
c.save()
mintro.update_build_options(c.coredata, c.build.environment.info_dir)
mintro.write_meson_info_file(c.build, [])
except ConfException as e:
print('Meson configurator encountered an error:')
if c is not None and c.build is not None:
mintro.write_meson_info_file(c.build, [e])
raise e
return 0

@ -556,7 +556,10 @@ def run(options):
print(json.dumps(out, indent=indent))
return 0
updated_introspection_files = []
def write_intro_info(intro_info, info_dir):
global updated_introspection_files
for i in intro_info:
out_file = os.path.join(info_dir, 'intro-{}.json'.format(i[0]))
tmp_file = os.path.join(info_dir, 'tmp_dump.json')
@ -564,6 +567,7 @@ def write_intro_info(intro_info, info_dir):
json.dump(i[1], fp)
fp.flush() # Not sure if this is needed
os.replace(tmp_file, out_file)
updated_introspection_files += [i[0]]
def generate_introspection_file(builddata: build.Build, backend: backends.Backend):
coredata = builddata.environment.get_coredata()
@ -581,3 +585,52 @@ def update_build_options(coredata: cdata.CoreData, info_dir):
]
write_intro_info(intro_info, info_dir)
def split_version_string(version: str):
vers_list = version.split('.')
return {
'full': version,
'major': int(vers_list[0] if len(vers_list) > 0 else 0),
'minor': int(vers_list[1] if len(vers_list) > 1 else 0),
'patch': int(vers_list[2] if len(vers_list) > 2 else 0)
}
def write_meson_info_file(builddata: build.Build, errors: list, build_files_updated: bool = False):
global updated_introspection_files
info_dir = builddata.environment.info_dir
info_file = get_meson_info_file(info_dir)
intro_types = get_meson_introspection_types()
intro_info = {}
for i in intro_types.keys():
intro_info[i] = {
'file': 'intro-{}.json'.format(i),
'updated': i in updated_introspection_files
}
info_data = {
'meson_version': split_version_string(cdata.version),
'directories': {
'source': builddata.environment.get_source_dir(),
'build': builddata.environment.get_build_dir(),
'info': info_dir,
},
'introspection': {
'version': split_version_string(get_meson_introspection_version()),
'information': intro_info,
},
'build_files_updated': build_files_updated,
}
if len(errors) > 0:
info_data['error'] = True
info_data['error_list'] = [x if isinstance(x, str) else str(x) for x in errors]
else:
info_data['error'] = False
# Write the data to disc
tmp_file = os.path.join(info_dir, 'tmp_dump.json')
with open(tmp_file, 'w') as fp:
json.dump(info_data, fp)
fp.flush()
os.replace(tmp_file, info_file)

@ -184,11 +184,15 @@ class MesonApp:
mlog.log('Target machine cpu:', mlog.bold(intr.builtin['target_machine'].cpu_method([], {})))
mlog.log('Build machine cpu family:', mlog.bold(intr.builtin['build_machine'].cpu_family_method([], {})))
mlog.log('Build machine cpu:', mlog.bold(intr.builtin['build_machine'].cpu_method([], {})))
if self.options.profile:
fname = os.path.join(self.build_dir, 'meson-private', 'profile-interpreter.log')
profile.runctx('intr.run()', globals(), locals(), filename=fname)
else:
intr.run()
try:
if self.options.profile:
fname = os.path.join(self.build_dir, 'meson-private', 'profile-interpreter.log')
profile.runctx('intr.run()', globals(), locals(), filename=fname)
else:
intr.run()
except Exception as e:
mintro.write_meson_info_file(b, [e])
raise
# Print all default option values that don't match the current value
for def_opt_name, def_opt_value, cur_opt_value in intr.get_non_matching_default_options():
mlog.log('Option', mlog.bold(def_opt_name), 'is:',
@ -223,7 +227,9 @@ class MesonApp:
profile.runctx('mintro.generate_introspection_file(b, intr.backend)', globals(), locals(), filename=fname)
else:
mintro.generate_introspection_file(b, intr.backend)
except:
mintro.write_meson_info_file(b, [], True)
except Exception as e:
mintro.write_meson_info_file(b, [e])
if 'cdf' in locals():
old_cdf = cdf + '.prev'
if os.path.exists(old_cdf):

@ -3291,6 +3291,20 @@ recommended as it is not supported on some platforms''')
self.assertEqual(res_all, res_file)
def test_introspect_meson_info(self):
testdir = os.path.join(self.unit_test_dir, '49 introspection')
introfile = os.path.join(self.builddir, 'meson-info', 'meson-info.json')
self.init(testdir)
self.assertPathExists(introfile)
with open(introfile, 'r') as fp:
res1 = json.load(fp)
for i in ['meson_version', 'directories', 'introspection', 'build_files_updated', 'error']:
self.assertIn(i, res1)
self.assertEqual(res1['error'], False)
self.assertEqual(res1['build_files_updated'], True)
def test_introspect_config_update(self):
testdir = os.path.join(self.unit_test_dir, '49 introspection')
introfile = os.path.join(self.builddir, 'meson-info', 'intro-buildoptions.json')

Loading…
Cancel
Save