The Meson Build System
http://mesonbuild.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
213 lines
7.8 KiB
213 lines
7.8 KiB
11 years ago
|
#!/usr/bin/env python3
|
||
|
|
||
9 years ago
|
# Copyright 2014-2016 The Meson development team
|
||
11 years ago
|
|
||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
# you may not use this file except in compliance with the License.
|
||
|
# You may obtain a copy of the License at
|
||
|
|
||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||
|
|
||
|
# Unless required by applicable law or agreed to in writing, software
|
||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
# See the License for the specific language governing permissions and
|
||
|
# limitations under the License.
|
||
|
|
||
|
"""This is a helper script for IDE developers. It allows you to
|
||
|
extract information such as list of targets, files, compiler flags,
|
||
|
tests and so on. All output is in JSON for simple parsing.
|
||
|
|
||
|
Currently only works for the Ninja backend. Others use generated
|
||
|
project files and don't need this info."""
|
||
|
|
||
|
import json, pickle
|
||
9 years ago
|
from . import coredata, build, mesonlib
|
||
10 years ago
|
import argparse
|
||
11 years ago
|
import sys, os
|
||
|
|
||
10 years ago
|
parser = argparse.ArgumentParser()
|
||
|
parser.add_argument('--targets', action='store_true', dest='list_targets', default=False,
|
||
10 years ago
|
help='List top level targets.')
|
||
10 years ago
|
parser.add_argument('--target-files', action='store', dest='target_files', default=None,
|
||
10 years ago
|
help='List source files for a given target.')
|
||
10 years ago
|
parser.add_argument('--buildsystem-files', action='store_true', dest='buildsystem_files', default=False,
|
||
10 years ago
|
help='List files that make up the build system.')
|
||
10 years ago
|
parser.add_argument('--buildoptions', action='store_true', dest='buildoptions', default=False,
|
||
10 years ago
|
help='List all build options.')
|
||
10 years ago
|
parser.add_argument('--tests', action='store_true', dest='tests', default=False,
|
||
10 years ago
|
help='List all unit tests.')
|
||
9 years ago
|
parser.add_argument('--benchmarks', action='store_true', dest='benchmarks', default=False,
|
||
|
help='List all benchmarks.')
|
||
9 years ago
|
parser.add_argument('--dependencies', action='store_true', dest='dependencies', default=False,
|
||
|
help='list external dependencies.')
|
||
10 years ago
|
parser.add_argument('args', nargs='+')
|
||
11 years ago
|
|
||
|
def list_targets(coredata, builddata):
|
||
|
tlist = []
|
||
9 years ago
|
for (idname, target) in builddata.get_targets().items():
|
||
11 years ago
|
t = {}
|
||
|
t['name'] = target.get_basename()
|
||
9 years ago
|
t['id'] = idname
|
||
10 years ago
|
fname = target.get_filename()
|
||
|
if isinstance(fname, list):
|
||
|
fname = [os.path.join(target.subdir, x) for x in fname]
|
||
|
else:
|
||
|
fname = os.path.join(target.subdir, fname)
|
||
|
t['filename'] = fname
|
||
11 years ago
|
if isinstance(target, build.Executable):
|
||
|
typename = 'executable'
|
||
|
elif isinstance(target, build.SharedLibrary):
|
||
|
typename = 'shared library'
|
||
|
elif isinstance(target, build.StaticLibrary):
|
||
|
typename = 'static library'
|
||
11 years ago
|
elif isinstance(target, build.CustomTarget):
|
||
|
typename = 'custom'
|
||
11 years ago
|
elif isinstance(target, build.RunTarget):
|
||
|
typename = 'run'
|
||
11 years ago
|
else:
|
||
|
typename = 'unknown'
|
||
|
t['type'] = typename
|
||
|
if target.should_install():
|
||
|
t['installed'] = True
|
||
|
else:
|
||
|
t['installed'] = False
|
||
|
tlist.append(t)
|
||
|
print(json.dumps(tlist))
|
||
|
|
||
11 years ago
|
def list_target_files(target_name, coredata, builddata):
|
||
|
try:
|
||
11 years ago
|
t = builddata.targets[target_name]
|
||
|
sources = t.sources + t.extra_files
|
||
|
subdir = t.subdir
|
||
11 years ago
|
except KeyError:
|
||
|
print("Unknown target %s." % target_name)
|
||
|
sys.exit(1)
|
||
9 years ago
|
sources = [os.path.join(i.subdir, i.fname) for i in sources]
|
||
11 years ago
|
print(json.dumps(sources))
|
||
11 years ago
|
|
||
11 years ago
|
def list_buildoptions(coredata, builddata):
|
||
|
buildtype= {'choices': ['plain', 'debug', 'debugoptimized', 'release'],
|
||
|
'type' : 'combo',
|
||
|
'value' : coredata.buildtype,
|
||
|
'description' : 'Build type',
|
||
|
'name' : 'type'}
|
||
|
strip = {'value' : coredata.strip,
|
||
|
'type' : 'boolean',
|
||
|
'description' : 'Strip on install',
|
||
|
'name' : 'strip'}
|
||
|
coverage = {'value': coredata.coverage,
|
||
|
'type' : 'boolean',
|
||
|
'description' : 'Enable coverage',
|
||
|
'name' : 'coverage'}
|
||
|
pch = {'value' : coredata.use_pch,
|
||
|
'type' : 'boolean',
|
||
|
'description' : 'Use precompiled headers',
|
||
|
'name' : 'pch'}
|
||
|
unity = {'value' : coredata.unity,
|
||
|
'type' : 'boolean',
|
||
|
'description' : 'Unity build',
|
||
|
'name' : 'unity'}
|
||
|
optlist = [buildtype, strip, coverage, pch, unity]
|
||
9 years ago
|
add_keys(optlist, coredata.user_options)
|
||
|
add_keys(optlist, coredata.compiler_options)
|
||
|
print(json.dumps(optlist))
|
||
|
|
||
|
def add_keys(optlist, options):
|
||
11 years ago
|
keys = list(options.keys())
|
||
|
keys.sort()
|
||
|
for key in keys:
|
||
|
opt = options[key]
|
||
|
optdict = {}
|
||
|
optdict['name'] = key
|
||
|
optdict['value'] = opt.value
|
||
9 years ago
|
if isinstance(opt, mesonlib.UserStringOption):
|
||
11 years ago
|
typestr = 'string'
|
||
9 years ago
|
elif isinstance(opt, mesonlib.UserBooleanOption):
|
||
11 years ago
|
typestr = 'boolean'
|
||
9 years ago
|
elif isinstance(opt, mesonlib.UserComboOption):
|
||
11 years ago
|
optdict['choices'] = opt.choices
|
||
|
typestr = 'combo'
|
||
9 years ago
|
elif isinstance(opt, mesonlib.UserStringArrayOption):
|
||
|
typestr = 'stringarray'
|
||
11 years ago
|
else:
|
||
|
raise RuntimeError("Unknown option type")
|
||
|
optdict['type'] = typestr
|
||
|
optdict['description'] = opt.description
|
||
|
optlist.append(optdict)
|
||
|
|
||
11 years ago
|
def list_buildsystem_files(coredata, builddata):
|
||
|
src_dir = builddata.environment.get_source_dir()
|
||
|
# I feel dirty about this. But only slightly.
|
||
|
filelist = []
|
||
11 years ago
|
for root, _, files in os.walk(src_dir):
|
||
11 years ago
|
for f in files:
|
||
|
if f == 'meson.build' or f == 'meson_options.txt':
|
||
|
filelist.append(os.path.relpath(os.path.join(root, f), src_dir))
|
||
|
print(json.dumps(filelist))
|
||
|
|
||
9 years ago
|
def list_deps(coredata):
|
||
|
result = {}
|
||
|
for d in coredata.deps.values():
|
||
|
if d.found():
|
||
|
args = {'compile_args': d.get_compile_args(),
|
||
|
'link_args': d.get_link_args()}
|
||
|
result[d.name] = args
|
||
|
print(json.dumps(result))
|
||
|
|
||
11 years ago
|
def list_tests(testdata):
|
||
|
result = []
|
||
|
for t in testdata:
|
||
|
to = {}
|
||
9 years ago
|
if isinstance(t.fname, str):
|
||
|
fname = [t.fname]
|
||
|
else:
|
||
|
fname = t.fname
|
||
|
to['cmd'] = fname + t.cmd_args
|
||
11 years ago
|
to['env'] = t.env
|
||
|
to['name'] = t.name
|
||
9 years ago
|
to['workdir'] = t.workdir
|
||
|
to['timeout'] = t.timeout
|
||
9 years ago
|
to['suite'] = t.suite
|
||
11 years ago
|
result.append(to)
|
||
|
print(json.dumps(result))
|
||
|
|
||
9 years ago
|
def run(args):
|
||
|
options = parser.parse_args(args)
|
||
10 years ago
|
if len(options.args) > 1:
|
||
11 years ago
|
print('Too many arguments')
|
||
9 years ago
|
return 1
|
||
10 years ago
|
elif len(options.args) == 1:
|
||
|
bdir = options.args[0]
|
||
11 years ago
|
else:
|
||
11 years ago
|
bdir = ''
|
||
11 years ago
|
corefile = os.path.join(bdir, 'meson-private/coredata.dat')
|
||
|
buildfile = os.path.join(bdir, 'meson-private/build.dat')
|
||
11 years ago
|
testfile = os.path.join(bdir, 'meson-private/meson_test_setup.dat')
|
||
9 years ago
|
benchmarkfile = os.path.join(bdir, 'meson-private/meson_benchmark_setup.dat')
|
||
11 years ago
|
coredata = pickle.load(open(corefile, 'rb'))
|
||
|
builddata = pickle.load(open(buildfile, 'rb'))
|
||
11 years ago
|
testdata = pickle.load(open(testfile, 'rb'))
|
||
9 years ago
|
benchmarkdata = pickle.load(open(benchmarkfile, 'rb'))
|
||
11 years ago
|
if options.list_targets:
|
||
|
list_targets(coredata, builddata)
|
||
11 years ago
|
elif options.target_files is not None:
|
||
|
list_target_files(options.target_files, coredata, builddata)
|
||
11 years ago
|
elif options.buildsystem_files:
|
||
|
list_buildsystem_files(coredata, builddata)
|
||
11 years ago
|
elif options.buildoptions:
|
||
|
list_buildoptions(coredata, builddata)
|
||
11 years ago
|
elif options.tests:
|
||
|
list_tests(testdata)
|
||
9 years ago
|
elif options.benchmarks:
|
||
|
list_tests(benchmarkdata)
|
||
9 years ago
|
elif options.dependencies:
|
||
|
list_deps(coredata)
|
||
11 years ago
|
else:
|
||
|
print('No command specified')
|
||
9 years ago
|
return 1
|
||
|
return 0
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
sys.exit(run(sys.argv[1:]))
|