2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Extracts information from a library.dsc file."""
15 print >> sys
.stderr
, 'dsc_info: %s' % msg
19 def FindTarget(tree
, target_name
):
20 targets
= tree
['TARGETS']
21 for target
in targets
:
22 if target
['NAME'] == target_name
:
24 Error('Target %s not found' % target_name
)
27 def GetSources(lib_dir
, tree
, target_name
):
29 target
= FindTarget(tree
, target_name
)
30 for filename
in target
['SOURCES']:
31 result
.append('/'.join([lib_dir
, filename
]))
36 "Entry point for gyp's pymod_do_main command."
37 parser
= optparse
.OptionParser(usage
='%prog: [OPTIONS] TARGET')
38 # Give a clearer error message when this is used as a module.
39 parser
.prog
= 'dsc_info'
40 parser
.add_option('-s', '--sources',
41 help='Print a list of source files for the target',
42 action
='store_true', default
=False)
43 parser
.add_option('-l', '--libdir',
44 help='Directory where the library.dsc file is located',
46 options
, args
= parser
.parse_args(argv
)
48 parser
.error('Expecting exactly one argument.')
50 libdir
= options
.libdir
or ''
51 tree
= parse_dsc
.LoadProject(os
.path
.join(libdir
, 'library.dsc'))
53 return '\n'.join(GetSources(libdir
, tree
, target
))
54 parser
.error('No action specified')
58 print DoMain(argv
[1:])
61 if __name__
== '__main__':
63 sys
.exit(main(sys
.argv
))
64 except KeyboardInterrupt: