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