annotate python/zcc.py @ 391:a139da1f44f6

Merge
author Windel Bouwman
date Fri, 16 May 2014 12:30:10 +0200
parents 6df89163e114
children 6ae782a085e0
rev   line source
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
1 #!/usr/bin/env python
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
2
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
3 import sys
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
4 import argparse
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
5 import logging
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
6
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents: 323
diff changeset
7 from ppci.tasks import TaskRunner
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
8 from ppci.report import RstFormatter
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
9 from ppci.recipe import RecipeLoader
381
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 377
diff changeset
10 import ppci.buildtasks # Include not used, but it registers build tasks.
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
11 import ppci
281
4496cae24d7f Improved logview
Windel Bouwman
parents: 276
diff changeset
12
289
bd2593de3ff8 Semifix burn2
Windel Bouwman
parents: 288
diff changeset
13
253
74c6a20302d5 Added better logging
Windel Bouwman
parents: 252
diff changeset
14 def logLevel(s):
312
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
15 """ Converts a string to a valid logging level """
253
74c6a20302d5 Added better logging
Windel Bouwman
parents: 252
diff changeset
16 numeric_level = getattr(logging, s.upper(), None)
74c6a20302d5 Added better logging
Windel Bouwman
parents: 252
diff changeset
17 if not isinstance(numeric_level, int):
74c6a20302d5 Added better logging
Windel Bouwman
parents: 252
diff changeset
18 raise ValueError('Invalid log level: {}'.format(s))
74c6a20302d5 Added better logging
Windel Bouwman
parents: 252
diff changeset
19 return numeric_level
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
20
289
bd2593de3ff8 Semifix burn2
Windel Bouwman
parents: 288
diff changeset
21
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
22 def make_parser():
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
23 parser = argparse.ArgumentParser(description='lcfos Compiler')
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
24
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
25 parser.add_argument('--log', help='Log level (INFO,DEBUG,[WARN])',
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
26 type=logLevel, default='INFO')
348
442fb043d149 Added log option to zcc
Windel Bouwman
parents: 342
diff changeset
27 parser.add_argument('--report',
442fb043d149 Added log option to zcc
Windel Bouwman
parents: 342
diff changeset
28 help='Specify a file to write the compile report to',
442fb043d149 Added log option to zcc
Windel Bouwman
parents: 342
diff changeset
29 type=argparse.FileType('w'))
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
30 parser.add_argument('--buildfile',
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
31 help='use buildfile, otherwise build.xml is the default',
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
32 default='build.xml')
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
33
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
34 parser.add_argument('targets', metavar='target', nargs='*')
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
35 return parser
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
36
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
37
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 246
diff changeset
38 def main(args):
315
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
39 # Configure some logging:
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
40 logging.getLogger().setLevel(logging.DEBUG)
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
41 ch = logging.StreamHandler()
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
42 ch.setFormatter(logging.Formatter(ppci.logformat))
315
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
43 ch.setLevel(args.log)
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
44 logging.getLogger().addHandler(ch)
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents: 323
diff changeset
45
348
442fb043d149 Added log option to zcc
Windel Bouwman
parents: 342
diff changeset
46 if args.report:
442fb043d149 Added log option to zcc
Windel Bouwman
parents: 342
diff changeset
47 fh = logging.StreamHandler(args.report)
442fb043d149 Added log option to zcc
Windel Bouwman
parents: 342
diff changeset
48 fh.setFormatter(RstFormatter())
442fb043d149 Added log option to zcc
Windel Bouwman
parents: 342
diff changeset
49 logging.getLogger().addHandler(fh)
442fb043d149 Added log option to zcc
Windel Bouwman
parents: 342
diff changeset
50
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
51 recipe_loader = RecipeLoader()
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
52 try:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
53 project = recipe_loader.load_file(args.buildfile)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
54 except OSError as e:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
55 res = 1
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
56
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
57 runner = TaskRunner()
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
58 res = runner.run(project, args.targets)
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
59
348
442fb043d149 Added log option to zcc
Windel Bouwman
parents: 342
diff changeset
60 if args.report:
442fb043d149 Added log option to zcc
Windel Bouwman
parents: 342
diff changeset
61 logging.getLogger().removeHandler(fh)
442fb043d149 Added log option to zcc
Windel Bouwman
parents: 342
diff changeset
62 args.report.close()
442fb043d149 Added log option to zcc
Windel Bouwman
parents: 342
diff changeset
63
315
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
64 logging.getLogger().removeHandler(ch)
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
65 return res
246
f254b87258e6 Added hexfile to zcc
Windel Bouwman
parents: 239
diff changeset
66
288
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
67
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
68 if __name__ == '__main__':
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
69 parser = make_parser()
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 207
diff changeset
70 arguments = parser.parse_args()
276
Windel Bouwman
parents: 272
diff changeset
71 sys.exit(main(arguments))