16 # This module represents a Command Line Interpreter (CLI) for Raptor. |
16 # This module represents a Command Line Interpreter (CLI) for Raptor. |
17 # The interface with Raptor is the GetArgs() function, which is called |
17 # The interface with Raptor is the GetArgs() function, which is called |
18 # by a raptor.Raptor object. |
18 # by a raptor.Raptor object. |
19 # |
19 # |
20 |
20 |
21 import re |
|
22 import types |
21 import types |
23 import raptor |
22 import raptor |
24 import os |
|
25 import sys |
|
26 import tempfile |
|
27 from raptor_utilities import getOSPlatform |
|
28 |
23 |
29 from optparse import OptionParser # for parsing command line parameters |
24 from optparse import OptionParser # for parsing command line parameters |
30 |
25 |
31 fullCommandOption = "--command" |
26 fullCommandOption = "--command" |
32 miniCommandOption = "--co" # update this if another "co" option is added |
27 miniCommandOption = "--co" # update this if another "co" option is added |
33 |
28 |
34 # raptor_cli module attributes |
29 # raptor_cli module attributes |
35 |
30 |
36 parser = OptionParser(prog = raptor.name, |
31 parser = OptionParser(prog = raptor.name, |
37 usage = """%prog [--help] [options] [variable=value] [target] ... |
32 usage = """%prog [--help] [options] [target] ... |
38 |
33 |
39 Targets: |
34 Targets: |
40 |
35 |
41 BITMAP Create bitmap files |
36 BITMAP Create bitmap files |
42 CLEAN Remove built files and intermediates, but not exported files |
37 CLEAN Remove built files and intermediates, but not exported files |
45 FINAL Allow extension makefiles to execute final commands |
40 FINAL Allow extension makefiles to execute final commands |
46 FREEZE Freeze exported functions in a .DEF file |
41 FREEZE Freeze exported functions in a .DEF file |
47 LIBRARY Create import libraries from frozen .DEF files |
42 LIBRARY Create import libraries from frozen .DEF files |
48 LISTING Create assembler listing files for source files |
43 LISTING Create assembler listing files for source files |
49 REALLYCLEAN Same as CLEAN but also remove exported files |
44 REALLYCLEAN Same as CLEAN but also remove exported files |
50 RESOURCE Create resource files and AIFs |
45 RESOURCE Create resource files |
51 ROMFILE Create an IBY file to be included in a ROM |
46 ROMFILE Create an IBY file to be included in a ROM |
52 TARGET Create main executables |
47 TARGET Create main executables |
53 WHAT List all releaseable targets |
48 WHAT List all releaseable targets |
54 |
49 |
55 Examples: |
50 Examples: |
85 help="Name of the make engine which runs the build.") |
80 help="Name of the make engine which runs the build.") |
86 |
81 |
87 parser.add_option("--export-only",action="store_true",dest="doExportOnly", |
82 parser.add_option("--export-only",action="store_true",dest="doExportOnly", |
88 help="Generate exports only and do not create any make files.") |
83 help="Generate exports only and do not create any make files.") |
89 |
84 |
|
85 parser.add_option("--noexport",action="store_true",dest="doExport", |
|
86 help="Don't export any files - useful in some builds when you know exports have already been done.") |
|
87 |
90 parser.add_option("-f","--logfile",action="store",dest="logfile", |
88 parser.add_option("-f","--logfile",action="store",dest="logfile", |
91 help="Name of the log file, or '-' for stdout.") |
89 help="Name of the log file, or '-' for stdout.") |
92 |
90 |
93 parser.add_option("--filters",action="store",dest="filter_list", |
91 parser.add_option("--filters",action="store",dest="filter_list", |
94 help="Comma-separated list of names of the filters to use (case sensitive).") |
92 help="Comma-separated list of names of the filters to use (case sensitive).") |
114 parser.add_option("-n","--nobuild",action="store_true",dest="nobuild", |
112 parser.add_option("-n","--nobuild",action="store_true",dest="nobuild", |
115 help="Just create makefiles, do not build anything.") |
113 help="Just create makefiles, do not build anything.") |
116 |
114 |
117 parser.add_option("--no-depend-include",action="store_true",dest="noDependInclude", |
115 parser.add_option("--no-depend-include",action="store_true",dest="noDependInclude", |
118 help="Do not include generated dependency files. This is only useful for extremely large non-incremental builds.") |
116 help="Do not include generated dependency files. This is only useful for extremely large non-incremental builds.") |
|
117 |
|
118 parser.add_option("--no-depend-generate",action="store_true",dest="noDependGenerate", |
|
119 help="Do not generate dependency files. This is only useful for extremely large non-incremental builds. Implies --no-depend-include.") |
119 |
120 |
120 parser.add_option("-o","--orderlayers",action="store_true",dest="sys_def_order_layers", |
121 parser.add_option("-o","--orderlayers",action="store_true",dest="sys_def_order_layers", |
121 help="Build layers in the System Definition XML file in the order listed or, if given, in the order of -l options.") |
122 help="Build layers in the System Definition XML file in the order listed or, if given, in the order of -l options.") |
122 |
123 |
123 parser.add_option("-p","--project",action="append",dest="project_name", |
124 parser.add_option("-p","--project",action="append",dest="project_name", |
124 help="Build a specific project (mmp or extension) in the given bld.inf file. Multiple -p options can be given.") |
125 help="Build a specific project (mmp or extension) in the given bld.inf file. Multiple -p options can be given.") |
125 |
126 |
126 parser.add_option("-q","--quiet",action="store_true",dest="quiet", |
127 parser.add_option("-q","--quiet",action="store_true",dest="quiet", |
127 help="Run quietly, not generating output messages.") |
128 help="Run quietly, not generating output messages.") |
|
129 |
|
130 parser.add_option("--query",action="append",dest="query", |
|
131 help="""Access various build settings and options using a basic API. The current options are: |
|
132 |
|
133 * aliases - return all the values that can be sensibly used with the sbs -c option. |
|
134 |
|
135 * products - return all the values that can be "." appended to an alias to specialise it for a product build. |
|
136 |
|
137 * config[x] - return a set of values that represent the build configuration "x". Typically "x" will be an alias name or an alias followed by "." followed by a product. |
|
138 |
|
139 Multiple --query options can be given. |
|
140 """) |
128 |
141 |
129 parser.add_option("-s","--sysdef",action="store",dest="sys_def_file", |
142 parser.add_option("-s","--sysdef",action="store",dest="sys_def_file", |
130 help="System Definition XML filename.") |
143 help="System Definition XML filename.") |
131 |
144 |
132 parser.add_option("--source-target",action="append",dest="source_target", |
145 parser.add_option("--source-target",action="append",dest="source_target", |
142 |
155 |
143 "off" - Do not check tool versions whatsoever. |
156 "off" - Do not check tool versions whatsoever. |
144 |
157 |
145 "forced" - Check all tool versions. Don't use cached results. |
158 "forced" - Check all tool versions. Don't use cached results. |
146 """) |
159 """) |
|
160 |
|
161 parser.add_option("--timing",action="store_true",dest="timing", |
|
162 help="Show extra timing information for various processes in the build.") |
|
163 |
147 parser.add_option("--pp",action="store",dest="parallel_parsing", |
164 parser.add_option("--pp",action="store",dest="parallel_parsing", |
148 help="""Controls how metadata (e.g. bld.infs) are parsed in Parallel. |
165 help="""Controls how metadata (e.g. bld.infs) are parsed in Parallel. |
149 Possible values are: |
166 Possible values are: |
150 "on" - Parse bld.infs in parallel (should be faster on clusters/multicore machines) |
167 "on" - Parse bld.infs in parallel (should be faster on clusters/multicore machines) |
|
168 "slave" - used internally by Raptor |
151 "off" - Parse bld.infs serially |
169 "off" - Parse bld.infs serially |
152 """) |
170 """) |
153 |
171 |
154 parser.add_option("-v","--version",action="store_true",dest="version", |
172 parser.add_option("-v","--version",action="store_true",dest="version", |
155 help="Print the version number and exit.") |
173 help="Print the version number and exit.") |
232 return False |
250 return False |
233 |
251 |
234 # parse the full set of arguments |
252 # parse the full set of arguments |
235 (options, leftover_args) = parser.parse_args(expanded_args) |
253 (options, leftover_args) = parser.parse_args(expanded_args) |
236 |
254 |
237 # the leftover_args are either variable assignments of the form a=b |
255 # the leftover_args are target names. |
238 # or target names. |
|
239 regex = re.compile("^(.+)=(.*)$") |
|
240 for leftover in leftover_args: |
256 for leftover in leftover_args: |
241 assignment = regex.findall(leftover) |
257 Raptor.AddTarget(leftover) |
242 if len(assignment) > 0: |
|
243 Raptor.SetEnv(assignment[0][0],assignment[0][1]) |
|
244 else: |
|
245 Raptor.AddTarget(leftover) |
|
246 |
258 |
247 # Define the dictionary of functions to be used. |
259 # Define the dictionary of functions to be used. |
248 # Attributes and function names can be added easily. |
260 # Attributes and function names can be added easily. |
249 # The calling attribute should be the same |
261 # The calling attribute should be the same |
250 # as specified when creating the add_option |
262 # as specified when creating the add_option |
258 'logfile' : Raptor.SetLogFileName, |
270 'logfile' : Raptor.SetLogFileName, |
259 'makefile' : Raptor.SetTopMakefile, |
271 'makefile' : Raptor.SetTopMakefile, |
260 'quiet' : Raptor.RunQuietly, |
272 'quiet' : Raptor.RunQuietly, |
261 'debugoutput' : Raptor.SetDebugOutput, |
273 'debugoutput' : Raptor.SetDebugOutput, |
262 'doExportOnly' : Raptor.SetExportOnly, |
274 'doExportOnly' : Raptor.SetExportOnly, |
|
275 'doExport' : Raptor.SetNoExport, |
263 'keepgoing': Raptor.SetKeepGoing, |
276 'keepgoing': Raptor.SetKeepGoing, |
264 'nobuild' : Raptor.SetNoBuild, |
277 'nobuild' : Raptor.SetNoBuild, |
265 'make_engine': Raptor.SetMakeEngine, |
278 'make_engine': Raptor.SetMakeEngine, |
266 'make_option': Raptor.AddMakeOption, |
279 'make_option': Raptor.AddMakeOption, |
267 'noDependInclude': Raptor.SetNoDependInclude, |
280 'noDependInclude': Raptor.SetNoDependInclude, |
|
281 'noDependGenerate': Raptor.SetNoDependGenerate, |
268 'number_of_jobs': Raptor.SetJobs, |
282 'number_of_jobs': Raptor.SetJobs, |
269 'project_name' : Raptor.AddProject, |
283 'project_name' : Raptor.AddProject, |
|
284 'query' : Raptor.AddQuery, |
270 'filter_list' : Raptor.FilterList, |
285 'filter_list' : Raptor.FilterList, |
271 'ignore_os_detection': Raptor.IgnoreOsDetection, |
286 'ignore_os_detection': Raptor.IgnoreOsDetection, |
272 'check' : Raptor.SetCheck, |
287 'check' : Raptor.SetCheck, |
273 'what' : Raptor.SetWhat, |
288 'what' : Raptor.SetWhat, |
274 'tries' : Raptor.SetTries, |
289 'tries' : Raptor.SetTries, |
275 'toolcheck' : Raptor.SetToolCheck, |
290 'toolcheck' : Raptor.SetToolCheck, |
|
291 'timing' : Raptor.SetTiming, |
276 'source_target' : Raptor.AddSourceTarget, |
292 'source_target' : Raptor.AddSourceTarget, |
277 'command_file' : CommandFile, |
293 'command_file' : CommandFile, |
278 'parallel_parsing' : Raptor.SetParallelParsing, |
294 'parallel_parsing' : Raptor.SetParallelParsing, |
279 'version' : Raptor.PrintVersion |
295 'version' : Raptor.PrintVersion |
280 } |
296 } |
281 |
297 |
282 # Check if Quiet mode has been specified (otherwise we will make noise) |
298 # Check if Quiet mode has been specified (otherwise we will make noise) |
283 if parser.values.quiet: |
299 if parser.values.quiet: |
284 Raptor.RunQuietly(True) |
300 Raptor.RunQuietly(True) |