author | timothy.murphy@nokia.com |
Tue, 25 May 2010 12:38:07 +0100 | |
branch | fix |
changeset 574 | 819bc4ffb37b |
parent 498 | 564986768b79 |
permissions | -rw-r--r-- |
3 | 1 |
# |
225
d401dbd3a410
Ensure that parallel parsing sbs calls pass on --no-depend-generate and --no-depend-include (as these influence makefile generation).
Jon Chatten
parents:
220
diff
changeset
|
2 |
# Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 | 3 |
# All rights reserved. |
4 |
# This component and the accompanying materials are made available |
|
5 |
# under the terms of the License "Eclipse Public License v1.0" |
|
6 |
# which accompanies this distribution, and is available |
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
# |
|
9 |
# Initial Contributors: |
|
10 |
# Nokia Corporation - initial contribution. |
|
11 |
# |
|
12 |
# Contributors: |
|
13 |
# |
|
14 |
# Description: |
|
15 |
# raptor_cli module |
|
16 |
# This module represents a Command Line Interpreter (CLI) for Raptor. |
|
17 |
# The interface with Raptor is the GetArgs() function, which is called |
|
18 |
# by a raptor.Raptor object. |
|
19 |
# |
|
20 |
||
21 |
import types |
|
22 |
import raptor |
|
23 |
||
24 |
from optparse import OptionParser # for parsing command line parameters |
|
25 |
||
26 |
fullCommandOption = "--command" |
|
27 |
miniCommandOption = "--co" # update this if another "co" option is added |
|
28 |
||
29 |
# raptor_cli module attributes |
|
30 |
||
31 |
parser = OptionParser(prog = raptor.name, |
|
413
5eb26ea9cb49
Release note: SF bug 2134 Raptor does not pass overridden make variables into its makefiles
Dean Draper <dean.draper@nokia.com>
parents:
225
diff
changeset
|
32 |
usage = """%prog [--help] [options] [target] ... |
3 | 33 |
|
34 |
Targets: |
|
35 |
||
36 |
BITMAP Create bitmap files |
|
37 |
CLEAN Remove built files and intermediates, but not exported files |
|
38 |
CLEANEXPORT Remove exported files |
|
39 |
EXPORT Copy exported files to destinations |
|
40 |
FINAL Allow extension makefiles to execute final commands |
|
41 |
FREEZE Freeze exported functions in a .DEF file |
|
42 |
LIBRARY Create import libraries from frozen .DEF files |
|
43 |
LISTING Create assembler listing files for source files |
|
44 |
REALLYCLEAN Same as CLEAN but also remove exported files |
|
219 | 45 |
RESOURCE Create resource files |
3 | 46 |
ROMFILE Create an IBY file to be included in a ROM |
47 |
TARGET Create main executables |
|
48 |
WHAT List all releaseable targets |
|
49 |
||
50 |
Examples: |
|
51 |
||
52 |
sbs -b my/group/bld.inf -c armv5 # build my component for target ARMV5 |
|
53 |
sbs -b my/group/bld.inf -c armv5.test # build my tests for target ARMV5 |
|
54 |
||
55 |
sbs -c winscw CLEAN # clean emulator files |
|
56 |
sbs REALLYCLEAN # delete everything""") |
|
57 |
||
58 |
parser.add_option("-a","--sysdefbase",action="store",dest="sys_def_base", |
|
59 |
help="Root directory for relative paths in the System Definition XML file.") |
|
60 |
||
61 |
parser.add_option("-b","--bldinf",action="append",dest="bld_inf_file", |
|
62 |
help="Build information filename. Multiple -b options can be given.") |
|
63 |
||
64 |
parser.add_option("-c","--config",action="append",dest="config_name", |
|
65 |
help="Configuration name to build. Multiple -c options can be given. The standard configs are all, armv5, armv7, default, tools, tools2 and winscw.") |
|
66 |
||
67 |
parser.add_option("--configpath", action="append",dest="config_list", |
|
68 |
help="Append a list of paths to the default list of XML configuration folders. Use ';' as the separator on Windows, and ':' on Linux. Multiple --configpath options can be given.") |
|
69 |
||
70 |
parser.add_option("--check",action="store_true",dest="check", |
|
71 |
help="Test for the existence of files created by the build, printing the ones which are missing. Do not build anything.") |
|
72 |
||
73 |
parser.add_option("--command",action="append",dest="command_file", |
|
74 |
help="Provide a set of command-line options in a file.") |
|
75 |
||
76 |
parser.add_option("-d","--debug",action="store_true",dest="debugoutput", |
|
77 |
help="Display information useful for debugging.") |
|
78 |
||
79 |
parser.add_option("-e","--engine",action="store",dest="make_engine", |
|
80 |
help="Name of the make engine which runs the build.") |
|
81 |
||
82 |
parser.add_option("--export-only",action="store_true",dest="doExportOnly", |
|
83 |
help="Generate exports only and do not create any make files.") |
|
84 |
||
14 | 85 |
parser.add_option("--noexport",action="store_true",dest="doExport", |
11
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
86 |
help="Don't export any files - useful in some builds when you know exports have already been done.") |
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
87 |
|
3 | 88 |
parser.add_option("-f","--logfile",action="store",dest="logfile", |
89 |
help="Name of the log file, or '-' for stdout.") |
|
90 |
||
91 |
parser.add_option("--filters",action="store",dest="filter_list", |
|
92 |
help="Comma-separated list of names of the filters to use (case sensitive).") |
|
93 |
||
94 |
parser.add_option("-i","--ignore-os-detection",action="store_true",dest="ignore_os_detection", |
|
95 |
help="Disables automatic application of OS variant based upon the OS version detected from each epoc32 tree.") |
|
96 |
||
97 |
parser.add_option("-j","--jobs",action="store",dest="number_of_jobs", |
|
98 |
help="The maximum number of jobs that make should try and run in parallel (on a single machine).") |
|
99 |
||
100 |
parser.add_option("-k","--keepgoing",action="store_true",dest="keepgoing", |
|
101 |
help="Continue building, even if some build commands fail.") |
|
102 |
||
103 |
parser.add_option("-l","--layer",action="append",dest="sys_def_layer", |
|
104 |
help="Build a specific layer in the System Definition XML File. Multiple -l options can be given.") |
|
105 |
||
106 |
parser.add_option("-m","--makefile",action="store",dest="makefile", |
|
107 |
help="Top-level makefile to be created.") |
|
108 |
||
109 |
parser.add_option("--mo",action="append",dest="make_option", |
|
110 |
help="Option that must be passed through to the make engine. Multiple --mo options can be given.") |
|
111 |
||
112 |
parser.add_option("-n","--nobuild",action="store_true",dest="nobuild", |
|
113 |
help="Just create makefiles, do not build anything.") |
|
114 |
||
115 |
parser.add_option("--no-depend-include",action="store_true",dest="noDependInclude", |
|
116 |
help="Do not include generated dependency files. This is only useful for extremely large non-incremental builds.") |
|
219 | 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.") |
|
3 | 120 |
|
121 |
parser.add_option("-o","--orderlayers",action="store_true",dest="sys_def_order_layers", |
|
122 |
help="Build layers in the System Definition XML file in the order listed or, if given, in the order of -l options.") |
|
123 |
||
124 |
parser.add_option("-p","--project",action="append",dest="project_name", |
|
125 |
help="Build a specific project (mmp or extension) in the given bld.inf file. Multiple -p options can be given.") |
|
126 |
||
127 |
parser.add_option("-q","--quiet",action="store_true",dest="quiet", |
|
128 |
help="Run quietly, not generating output messages.") |
|
129 |
||
498
564986768b79
add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
413
diff
changeset
|
130 |
parser.add_option("--query",action="append",dest="query", |
564986768b79
add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
413
diff
changeset
|
131 |
help="""Access various build settings and options using a basic API. The current options are: |
564986768b79
add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
413
diff
changeset
|
132 |
|
564986768b79
add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
413
diff
changeset
|
133 |
* aliases - return all the values that can be sensibly used with the sbs -c option. |
564986768b79
add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
413
diff
changeset
|
134 |
|
564986768b79
add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
413
diff
changeset
|
135 |
* products - return all the values that can be "." appended to an alias to specialise it for a product build. |
564986768b79
add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
413
diff
changeset
|
136 |
|
564986768b79
add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
413
diff
changeset
|
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. |
564986768b79
add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
413
diff
changeset
|
138 |
|
564986768b79
add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
413
diff
changeset
|
139 |
Multiple --query options can be given. |
564986768b79
add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
413
diff
changeset
|
140 |
""") |
564986768b79
add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
413
diff
changeset
|
141 |
|
3 | 142 |
parser.add_option("-s","--sysdef",action="store",dest="sys_def_file", |
143 |
help="System Definition XML filename.") |
|
144 |
||
145 |
parser.add_option("--source-target",action="append",dest="source_target", |
|
146 |
help="Build the listed source or resource file in isolation - do not perform any dependent processing. Multiple --source-target options can be given.") |
|
147 |
||
148 |
parser.add_option("-t","--tries",action="store",dest="tries", |
|
149 |
help="How many times to run a command before recording an error. The default is 1. This is useful for builds where transient failures can occur.") |
|
150 |
||
151 |
parser.add_option("--toolcheck",action="store",dest="toolcheck", |
|
152 |
help= \ |
|
153 |
"""Possible values are: |
|
154 |
"on" - Check the versions of tools that will be used in the build. Use cached results from previous builds to save time. This is the default. |
|
155 |
||
156 |
"off" - Do not check tool versions whatsoever. |
|
157 |
||
158 |
"forced" - Check all tool versions. Don't use cached results. |
|
159 |
""") |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
14
diff
changeset
|
160 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
14
diff
changeset
|
161 |
parser.add_option("--timing",action="store_true",dest="timing", |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
14
diff
changeset
|
162 |
help="Show extra timing information for various processes in the build.") |
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
14
diff
changeset
|
163 |
|
3 | 164 |
parser.add_option("--pp",action="store",dest="parallel_parsing", |
165 |
help="""Controls how metadata (e.g. bld.infs) are parsed in Parallel. |
|
166 |
Possible values are: |
|
167 |
"on" - Parse bld.infs in parallel (should be faster on clusters/multicore machines) |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
14
diff
changeset
|
168 |
"slave" - used internally by Raptor |
3 | 169 |
"off" - Parse bld.infs serially |
170 |
""") |
|
171 |
||
172 |
parser.add_option("-v","--version",action="store_true",dest="version", |
|
173 |
help="Print the version number and exit.") |
|
174 |
||
175 |
parser.add_option("--what",action="store_true",dest="what", |
|
176 |
help="Print out the names of the files created by the build. Do not build anything.") |
|
177 |
||
178 |
def GetArgs(Raptor, args): |
|
179 |
"Process command line arguments for a Raptor object" |
|
180 |
return DoRaptor(Raptor,args) |
|
181 |
||
182 |
def ReadCommandFile(filename, used): |
|
183 |
if filename in used: |
|
184 |
raise IOError("command file '%s' refers to itself" % filename) |
|
185 |
||
186 |
args = [] |
|
187 |
try: |
|
188 |
file = open(filename, "r") |
|
189 |
for line in file.readlines(): |
|
190 |
args.extend(line.split()) |
|
191 |
file.close() |
|
192 |
except: |
|
193 |
raise IOError("couldn't read command file '%s'" % filename) |
|
194 |
||
195 |
# expand any command files in the options we just read. |
|
196 |
# making sure we don't get stuck in a loop. |
|
197 |
usedPlusThis = used[:] |
|
198 |
usedPlusThis.append(filename) |
|
199 |
return ExpandCommandOptions(args, usedPlusThis) |
|
200 |
||
201 |
def ExpandCommandOptions(args, files = []): |
|
202 |
"""recursively expand --command options.""" |
|
203 |
expanded = [] |
|
204 |
previousWasOpt = False |
|
205 |
||
206 |
for a in args: |
|
207 |
if previousWasOpt: # then this one is the filename |
|
208 |
expanded.extend(ReadCommandFile(a, files)) |
|
209 |
previousWasOpt = False |
|
210 |
continue |
|
211 |
||
212 |
if a.startswith(miniCommandOption): |
|
213 |
if "=" in a: # then this is opt=filename |
|
214 |
opt = a.split("=") |
|
215 |
if fullCommandOption.startswith(opt[0]): |
|
216 |
expanded.extend(ReadCommandFile(opt[1], files)) |
|
217 |
continue |
|
218 |
else: # the next one is the filename |
|
219 |
if fullCommandOption.startswith(a): |
|
220 |
previousWasOpt = True |
|
221 |
continue |
|
222 |
||
223 |
expanded.append(a) # an ordinary arg, nothing to do with command files |
|
224 |
||
225 |
return expanded |
|
226 |
||
227 |
def DoRaptor(Raptor, args): |
|
228 |
"Process raptor arguments" |
|
229 |
# |
|
230 |
# This should parse the args list and call methods on |
|
231 |
# the Raptor object to store the appropriate data. |
|
232 |
||
233 |
# Expand --command=file options, replacing them with the contents of the |
|
234 |
# command file. |
|
235 |
||
236 |
non_ascii_error = "Non-ASCII character in argument or command file" |
|
237 |
||
238 |
try: |
|
239 |
expanded_args = ExpandCommandOptions(args) |
|
240 |
for arg in expanded_args: |
|
241 |
for c in arg: |
|
242 |
if ord(c) > 127: |
|
243 |
Raptor.Error(non_ascii_error) |
|
244 |
return False |
|
245 |
except IOError, e: |
|
246 |
Raptor.Error(str(e)) |
|
247 |
return False |
|
248 |
except UnicodeDecodeError: |
|
249 |
Raptor.Error(non_ascii_error) |
|
250 |
return False |
|
251 |
||
252 |
# parse the full set of arguments |
|
253 |
(options, leftover_args) = parser.parse_args(expanded_args) |
|
254 |
||
498
564986768b79
add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
413
diff
changeset
|
255 |
# the leftover_args are target names. |
3 | 256 |
for leftover in leftover_args: |
413
5eb26ea9cb49
Release note: SF bug 2134 Raptor does not pass overridden make variables into its makefiles
Dean Draper <dean.draper@nokia.com>
parents:
225
diff
changeset
|
257 |
Raptor.AddTarget(leftover) |
3 | 258 |
|
259 |
# Define the dictionary of functions to be used. |
|
260 |
# Attributes and function names can be added easily. |
|
261 |
# The calling attribute should be the same |
|
262 |
# as specified when creating the add_option |
|
263 |
functions = {'config_name': Raptor.AddConfigName, |
|
264 |
'config_list':Raptor.AddConfigList, |
|
265 |
'sys_def_file' : Raptor.SetSysDefFile, |
|
266 |
'sys_def_base' : Raptor.SetSysDefBase, |
|
267 |
'sys_def_layer' : Raptor.AddSysDefLayer, |
|
268 |
'sys_def_order_layers' : Raptor.SetSysDefOrderLayers, |
|
269 |
'bld_inf_file' : Raptor.AddBuildInfoFile, |
|
270 |
'logfile' : Raptor.SetLogFileName, |
|
271 |
'makefile' : Raptor.SetTopMakefile, |
|
272 |
'quiet' : Raptor.RunQuietly, |
|
273 |
'debugoutput' : Raptor.SetDebugOutput, |
|
274 |
'doExportOnly' : Raptor.SetExportOnly, |
|
11
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
275 |
'doExport' : Raptor.SetNoExport, |
3 | 276 |
'keepgoing': Raptor.SetKeepGoing, |
277 |
'nobuild' : Raptor.SetNoBuild, |
|
278 |
'make_engine': Raptor.SetMakeEngine, |
|
279 |
'make_option': Raptor.AddMakeOption, |
|
280 |
'noDependInclude': Raptor.SetNoDependInclude, |
|
220
f7d68ecb923e
Add support for NO_DEPEND_GENERATE to makefile calls and respond accordingly in FLMs.
Jon Chatten
parents:
219
diff
changeset
|
281 |
'noDependGenerate': Raptor.SetNoDependGenerate, |
3 | 282 |
'number_of_jobs': Raptor.SetJobs, |
283 |
'project_name' : Raptor.AddProject, |
|
498
564986768b79
add --query option
Richard Taylor <richard.i.taylor@nokia.com>
parents:
413
diff
changeset
|
284 |
'query' : Raptor.AddQuery, |
3 | 285 |
'filter_list' : Raptor.FilterList, |
286 |
'ignore_os_detection': Raptor.IgnoreOsDetection, |
|
287 |
'check' : Raptor.SetCheck, |
|
288 |
'what' : Raptor.SetWhat, |
|
289 |
'tries' : Raptor.SetTries, |
|
290 |
'toolcheck' : Raptor.SetToolCheck, |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
14
diff
changeset
|
291 |
'timing' : Raptor.SetTiming, |
3 | 292 |
'source_target' : Raptor.AddSourceTarget, |
293 |
'command_file' : CommandFile, |
|
219 | 294 |
'parallel_parsing' : Raptor.SetParallelParsing, |
295 |
'version' : Raptor.PrintVersion |
|
3 | 296 |
} |
297 |
||
298 |
# Check if Quiet mode has been specified (otherwise we will make noise) |
|
299 |
if parser.values.quiet: |
|
300 |
Raptor.RunQuietly(True) |
|
301 |
||
302 |
# some options imply that Raptor should exit immediately (e.g. --version) |
|
303 |
keepGoing = True |
|
304 |
||
305 |
if parser.values.version: |
|
306 |
keepGoing = False |
|
307 |
||
308 |
# Parse through the command line arguments passed, and call the |
|
309 |
# corresponding function with the correct parameter. |
|
310 |
# Since options is a OptParse.Value instance, it can be iterated over. |
|
311 |
# This implementation helps avoid lengthy if-else statements |
|
312 |
for opt in options.__dict__.items(): |
|
313 |
call_function = functions[str(opt[0])] |
|
314 |
values = opt[1] |
|
315 |
if not values: |
|
316 |
pass |
|
317 |
else: |
|
318 |
if type(values) == types.ListType: # Check if the argument type is a list or a string. If list, then iterate through it and call the functions |
|
319 |
for val in values: |
|
320 |
keepGoing = (call_function(val) and keepGoing) |
|
321 |
else: |
|
322 |
keepGoing = (call_function(values) and keepGoing) |
|
323 |
||
324 |
return keepGoing |
|
325 |
||
326 |
def CommandFile(file): |
|
327 |
"this should never be called because we expand --command in this module." |
|
328 |
print raptor.name + ": error: command file '%s' was not expanded" % file |
|
329 |
return False |
|
330 |
||
331 |
||
332 |
||
333 |
||
334 |
# end of the raptor_cli module |
|
335 |
||
336 |