Beginning of introspection tool for IDEs.

pull/15/head
Jussi Pakkanen 11 years ago
parent c7e7d1a4c3
commit 849fe8bacf
  1. 71
      mesonintrospect.py

@ -0,0 +1,71 @@
#!/usr/bin/env python3
# Copyright 2014 Jussi Pakkanen
# 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
import coredata, build
from optparse import OptionParser
import sys, os
parser = OptionParser()
parser.add_option('--list-targets', action='store_true', dest='list_targets', default=False)
def list_targets(coredata, builddata):
tlist = []
for target in builddata.get_targets().values():
t = {}
t['name'] = target.get_basename()
t['filename'] = os.path.join(target.subdir, target.get_filename())
if isinstance(target, build.Executable):
typename = 'executable'
elif isinstance(target, build.SharedLibrary):
typename = 'shared library'
elif isinstance(target, build.StaticLibrary):
typename = 'static library'
else:
typename = 'unknown'
t['type'] = typename
if target.should_install():
t['installed'] = True
else:
t['installed'] = False
tlist.append(t)
print(json.dumps(tlist))
if __name__ == '__main__':
(options, args) = parser.parse_args()
if len(args) > 1:
print('Too many arguments')
sys.exit(1)
elif len(args) == 1:
bdir = args[0]
else:
bdir == ''
corefile = os.path.join(bdir, 'meson-private/coredata.dat')
buildfile = os.path.join(bdir, 'meson-private/build.dat')
coredata = pickle.load(open(corefile, 'rb'))
builddata = pickle.load(open(buildfile, 'rb'))
if options.list_targets:
list_targets(coredata, builddata)
else:
print('No command specified')
sys.exit(1)
Loading…
Cancel
Save