summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2009-02-05 17:36:35 -0500
committerColin Walters <walters@verbum.org>2009-02-11 15:03:16 -0500
commit44ea75378eb33fa6386e66e9e5a55f3122363fb8 (patch)
tree27385b5c523f7390193dba950df134540aabd838 /tools
parent1b5e689fe2fc105725fe71051c184e0f1c461223 (diff)
downloadgobject-introspection-44ea75378eb33fa6386e66e9e5a55f3122363fb8.tar.gz
Bug 567906 - Put pkg-config dependencies in .gir files
When generating a .gir file, we now first parse all of our .gir includes to pick up their <package> headers. Then, we merge that with the set of --pkg arguments passed to us, run pkg-config to gather the arguments, and finally save the merged pkg-config list to our new .gir file. This is useful for software which needs to map from .gir to pkg-config in a programmatic way.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/g-ir-scanner95
1 files changed, 56 insertions, 39 deletions
diff --git a/tools/g-ir-scanner b/tools/g-ir-scanner
index 2152611d..6b319258 100755
--- a/tools/g-ir-scanner
+++ b/tools/g-ir-scanner
@@ -195,6 +195,41 @@ def validate(assertions, path):
print "=== PASSED %s ===" % (assertions, )
return 0
+def process_packages(parser, options, packages):
+ args = ['pkg-config', '--cflags']
+ args.extend(packages)
+ output = subprocess.Popen(args,
+ stdout=subprocess.PIPE).communicate()[0]
+ if output is None:
+ # the error output should have already appeared on our stderr,
+ # so we just exit
+ sys.exit(1)
+ # Some pkg-config files on Windows have options we don't understand,
+ # so we explicitly filter to only the ones we need.
+ options_whitelist = ['-I', '-D', '-U', '-l', '-L']
+ def filter_option(opt):
+ for optstart in options_whitelist:
+ if opt.startswith(optstart):
+ return True
+ return False
+ output = output.split()
+ filtered_output = filter(filter_option, output)
+ pkg_options, unused = parser.parse_args(filtered_output)
+ options.cpp_includes.extend(pkg_options.cpp_includes)
+ options.cpp_defines.extend(pkg_options.cpp_defines)
+ options.cpp_undefines.extend(pkg_options.cpp_undefines)
+
+ args = ['pkg-config', '--libs-only-L']
+ args.extend(packages)
+ output = subprocess.Popen(args,
+ stdout=subprocess.PIPE).communicate()[0]
+ if output is None:
+ sys.exit(1)
+ output = output.split()
+ filtered_output = filter(filter_option, output)
+ pkg_options, unused = parser.parse_args(filtered_output)
+ options.library_paths.extend(pkg_options.library_paths)
+
def main(args):
parser = _get_option_parser()
(options, args) = parser.parse_args(args)
@@ -226,31 +261,6 @@ def main(args):
_error("Must specify --program or --library")
libraries = options.libraries
- for package in options.packages:
- output = subprocess.Popen(['pkg-config', '--cflags', package],
- stdout=subprocess.PIPE).communicate()[0]
- # Some pkg-config files on Windows have options we don't understand,
- # so we explicitly filter to only the ones we need.
- options_whitelist = ['-I', '-D', '-U', '-l', '-L']
- def filter_option(opt):
- for optstart in options_whitelist:
- if opt.startswith(optstart):
- return True
- return False
- output = output.split()
- filtered_output = filter(filter_option, output)
- pkg_options, unused = parser.parse_args(filtered_output)
- options.cpp_includes.extend(pkg_options.cpp_includes)
- options.cpp_defines.extend(pkg_options.cpp_defines)
- options.cpp_undefines.extend(pkg_options.cpp_undefines)
-
- output = subprocess.Popen(['pkg-config', '--libs-only-L', package],
- stdout=subprocess.PIPE).communicate()[0]
- output = output.split()
- filtered_output = filter(filter_option, output)
- pkg_options, unused = parser.parse_args(filtered_output)
- options.library_paths.extend(pkg_options.library_paths)
-
# FIXME: using LPATH is definitely not portable enough. Using Python's
# find_library for finding our shared libraries is not a portable enough
# anyway as it behaves differently depending on the OS
@@ -272,19 +282,9 @@ def main(args):
if not os.path.exists(arg):
_error('%s: no such a file or directory' % (arg, ))
filenames.append(arg)
-
- cachestore = CacheStore()
- # Run the preprocessor, tokenize and construct simple
- # objects representing the raw C symbols
- ss = SourceScanner()
- ss.set_cpp_options(options.cpp_includes,
- options.cpp_defines,
- options.cpp_undefines)
- ss.parse_files(filenames)
- ss.parse_macros(filenames)
-
- # Transform the C symbols into AST nodes
- transformer = Transformer(cachestore, ss,
+
+ cachestore = CacheStore()
+ transformer = Transformer(cachestore,
options.namespace_name,
options.namespace_version)
if options.strip_prefix:
@@ -298,6 +298,22 @@ def main(args):
raise ValueError("Invalid include path %r" % (include, ))
include_obj = Include.from_string(include)
transformer.register_include(include_obj)
+
+ packages = set(options.packages)
+ packages.update(transformer.get_pkgconfig_packages())
+ process_packages(parser, options, packages)
+
+ # Run the preprocessor, tokenize and construct simple
+ # objects representing the raw C symbols
+ ss = SourceScanner()
+ ss.set_cpp_options(options.cpp_includes,
+ options.cpp_defines,
+ options.cpp_undefines)
+ ss.parse_files(filenames)
+ ss.parse_macros(filenames)
+
+ # Transform the C symbols into AST nodes
+ transformer.set_source_ast(ss)
if options.program:
args=[options.program]
@@ -321,7 +337,8 @@ def main(args):
raise SystemExit("ERROR in annotation: %s" % (str(e), ))
# Write out AST
- writer = Writer(namespace, libraries, transformer.get_includes())
+ writer = Writer(namespace, libraries, transformer.get_includes(),
+ options.packages)
data = writer.get_xml()
if options.output:
fd = open(options.output, "w")