292
|
1 #!/usr/bin/env python
|
104
|
2
|
287
|
3 import sys
|
331
|
4 import os
|
287
|
5 import argparse
|
|
6 import logging
|
|
7
|
329
|
8 from ppci.tasks import TaskRunner
|
377
|
9 import ppci.buildtasks
|
331
|
10 from ppci.report import RstFormatter
|
334
|
11 from ppci.objectfile import ObjectFile
|
366
|
12 from ppci.target.target_list import targets, targetnames
|
342
|
13 from ppci.recipe import RecipeLoader
|
331
|
14 import ppci
|
281
|
15
|
289
|
16
|
253
|
17 def logLevel(s):
|
312
|
18 """ Converts a string to a valid logging level """
|
253
|
19 numeric_level = getattr(logging, s.upper(), None)
|
|
20 if not isinstance(numeric_level, int):
|
|
21 raise ValueError('Invalid log level: {}'.format(s))
|
|
22 return numeric_level
|
105
|
23
|
289
|
24
|
331
|
25 def make_parser():
|
|
26 parser = argparse.ArgumentParser(description='lcfos Compiler')
|
|
27
|
|
28 parser.add_argument('--log', help='Log level (INFO,DEBUG,[WARN])',
|
334
|
29 type=logLevel, default='INFO')
|
348
|
30 parser.add_argument('--report',
|
|
31 help='Specify a file to write the compile report to',
|
|
32 type=argparse.FileType('w'))
|
377
|
33 parser.add_argument('--buildfile',
|
|
34 help='use buildfile, otherwise build.xml is the default',
|
|
35 default='build.xml')
|
331
|
36
|
377
|
37 parser.add_argument('targets', metavar='target', nargs='*')
|
331
|
38 return parser
|
|
39
|
287
|
40
|
249
|
41 def main(args):
|
315
|
42 # Configure some logging:
|
|
43 logging.getLogger().setLevel(logging.DEBUG)
|
|
44 ch = logging.StreamHandler()
|
331
|
45 ch.setFormatter(logging.Formatter(ppci.logformat))
|
315
|
46 ch.setLevel(args.log)
|
|
47 logging.getLogger().addHandler(ch)
|
329
|
48
|
348
|
49 if args.report:
|
|
50 fh = logging.StreamHandler(args.report)
|
|
51 fh.setFormatter(RstFormatter())
|
|
52 logging.getLogger().addHandler(fh)
|
|
53
|
377
|
54 recipe_loader = RecipeLoader()
|
|
55 try:
|
|
56 project = recipe_loader.load_file(args.buildfile)
|
|
57 except OSError as e:
|
|
58 res = 1
|
|
59
|
331
|
60 runner = TaskRunner()
|
377
|
61 res = runner.run(project, args.targets)
|
104
|
62
|
348
|
63 if args.report:
|
|
64 logging.getLogger().removeHandler(fh)
|
|
65 args.report.close()
|
|
66
|
315
|
67 logging.getLogger().removeHandler(ch)
|
331
|
68 return res
|
246
|
69
|
288
|
70
|
207
|
71 if __name__ == '__main__':
|
331
|
72 parser = make_parser()
|
213
|
73 arguments = parser.parse_args()
|
276
|
74 sys.exit(main(arguments))
|