annotate python/ppci/buildtasks.py @ 397:5d03c10fe19d

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