annotate python/ppci/buildtasks.py @ 392:bb4289c84907

Added some sort of drop event test
author Windel Bouwman
date Fri, 16 May 2014 13:05:10 +0200
parents d056b552d3f4
children 6ae782a085e0
rev   line source
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
1
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
2 """
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
3 Defines task classes that can compile, link etc..
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
4 Task can depend upon one another.
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
5 """
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
6
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
7 import logging
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
8
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
9 from .tasks import Task, TaskError, register_task
385
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
10 from .buildfunctions import c3compile, link, assemble, fix_object
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
11 from pyyacc import ParserException
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
12 from . import CompilerError
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
13
335
582a1aaa3983 Added long branch format
Windel Bouwman
parents: 334
diff changeset
14
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
15 @register_task("empty")
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
16 class EmptyTask(Task):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
17 """ Basic task that does nothing """
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
18 def run(self):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
19 pass
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
20
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
21
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
22 @register_task("echo")
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
23 class EchoTask(Task):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
24 """ Simple task that echoes a message """
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
25 def run(self):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
26 message = self.arguments['message']
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
27 print(message)
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 354
diff changeset
28
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 354
diff changeset
29
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
30 @register_task("property")
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
31 class Property(Task):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
32 """ Sets a property to a value """
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
33 def run(self):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
34 name = self.arguments['name']
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
35 value = self.arguments['value']
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
36 self.target.project.set_property(name, value)
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
37
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
38
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
39 @register_task("assemble")
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
40 class AssembleTask(Task):
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
41 """ Task that can runs the assembler over the source and enters the
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
42 output into an object file """
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
43
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
44 def run(self):
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
45 target = self.get_argument('target')
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
46 source = self.relpath(self.get_argument('source'))
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
47 output_filename = self.relpath(self.get_argument('output'))
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
48
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
49 try:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
50 output = assemble(source, target)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
51 except ParserException as e:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
52 raise TaskError('Error during assembly:' + str(e))
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
53 except CompilerError as e:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
54 raise TaskError('Error during assembly:' + str(e))
381
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 377
diff changeset
55 except OSError as e:
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 377
diff changeset
56 raise TaskError('Error:' + str(e))
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
57 with open(output_filename, 'w') as f:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
58 output.save(f)
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 354
diff changeset
59 self.logger.debug('Assembling finished')
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
60
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
61
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
62 @register_task("compile")
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
63 class C3cTask(Task):
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
64 """ Task that compiles C3 source for some target into an object file """
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
65 def run(self):
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
66 target = self.get_argument('target')
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
67 sources = self.open_file_set(self.arguments['sources'])
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
68 output_filename = self.relpath(self.get_argument('output'))
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
69 if 'includes' in self.arguments:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
70 includes = self.open_file_set(self.arguments['includes'])
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
71 else:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
72 includes = []
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
73
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
74 output = c3compile(sources, includes, target)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
75 # Store output:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
76 with open(output_filename, 'w') as f:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
77 output.save(f)
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
78
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
79
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
80 @register_task("link")
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
81 class LinkTask(Task):
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
82 """ Link together a collection of object files """
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
83 def run(self):
383
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
84 layout = self.relpath(self.get_argument('layout'))
385
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
85 target = self.get_argument('target')
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
86 objects = self.open_file_set(self.get_argument('objects'))
385
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
87 output_filename = self.relpath(self.get_argument('output'))
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
88
337
b00219172a42 Added cool lm3s811 qemu project
Windel Bouwman
parents: 336
diff changeset
89 try:
385
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
90 output_obj = link(objects, layout, target)
337
b00219172a42 Added cool lm3s811 qemu project
Windel Bouwman
parents: 336
diff changeset
91 except CompilerError as e:
b00219172a42 Added cool lm3s811 qemu project
Windel Bouwman
parents: 336
diff changeset
92 raise TaskError(e.msg)
385
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
93
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
94 # Store output:
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
95 with open(output_filename, 'w') as f:
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
96 output_obj.save(f)
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
97
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
98
385
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
99 @register_task("objcopy")
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
100 class ObjCopyTask(Task):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 366
diff changeset
101 def run(self):
385
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
102 image_name = self.get_argument('imagename')
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
103 output_filename = self.relpath(self.get_argument('output'))
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
104 object_filename = self.relpath(self.get_argument('objectfile'))
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
105
385
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
106 obj = fix_object(object_filename)
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
107 image = obj.get_image(image_name)
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
108 with open(output_filename, 'wb') as f:
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
109 f.write(image)
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
110