author | Richard Taylor <richard.i.taylor@nokia.com> |
Thu, 28 Jan 2010 16:06:25 +0000 | |
branch | fix |
changeset 176 | b601167a8189 |
parent 29 | ee00c00df073 |
child 219 | c3543adfd26e |
permissions | -rw-r--r-- |
3 | 1 |
# |
2 |
# Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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 |
|
50 |
RESOURCE Create resource files and AIFs |
|
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.") |
|
122 |
||
123 |
parser.add_option("-o","--orderlayers",action="store_true",dest="sys_def_order_layers", |
|
124 |
help="Build layers in the System Definition XML file in the order listed or, if given, in the order of -l options.") |
|
125 |
||
126 |
parser.add_option("-p","--project",action="append",dest="project_name", |
|
127 |
help="Build a specific project (mmp or extension) in the given bld.inf file. Multiple -p options can be given.") |
|
128 |
||
129 |
parser.add_option("-q","--quiet",action="store_true",dest="quiet", |
|
130 |
help="Run quietly, not generating output messages.") |
|
131 |
||
132 |
parser.add_option("-s","--sysdef",action="store",dest="sys_def_file", |
|
133 |
help="System Definition XML filename.") |
|
134 |
||
135 |
parser.add_option("--source-target",action="append",dest="source_target", |
|
136 |
help="Build the listed source or resource file in isolation - do not perform any dependent processing. Multiple --source-target options can be given.") |
|
137 |
||
138 |
parser.add_option("-t","--tries",action="store",dest="tries", |
|
139 |
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.") |
|
140 |
||
141 |
parser.add_option("--toolcheck",action="store",dest="toolcheck", |
|
142 |
help= \ |
|
143 |
"""Possible values are: |
|
144 |
"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. |
|
145 |
||
146 |
"off" - Do not check tool versions whatsoever. |
|
147 |
||
148 |
"forced" - Check all tool versions. Don't use cached results. |
|
149 |
""") |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
14
diff
changeset
|
150 |
|
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
14
diff
changeset
|
151 |
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
|
152 |
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
|
153 |
|
3 | 154 |
parser.add_option("--pp",action="store",dest="parallel_parsing", |
155 |
help="""Controls how metadata (e.g. bld.infs) are parsed in Parallel. |
|
156 |
Possible values are: |
|
157 |
"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
|
158 |
"slave" - used internally by Raptor |
3 | 159 |
"off" - Parse bld.infs serially |
160 |
""") |
|
161 |
||
162 |
parser.add_option("-v","--version",action="store_true",dest="version", |
|
163 |
help="Print the version number and exit.") |
|
164 |
||
165 |
parser.add_option("--what",action="store_true",dest="what", |
|
166 |
help="Print out the names of the files created by the build. Do not build anything.") |
|
167 |
||
168 |
def GetArgs(Raptor, args): |
|
169 |
"Process command line arguments for a Raptor object" |
|
170 |
return DoRaptor(Raptor,args) |
|
171 |
||
172 |
def ReadCommandFile(filename, used): |
|
173 |
if filename in used: |
|
174 |
raise IOError("command file '%s' refers to itself" % filename) |
|
175 |
||
176 |
args = [] |
|
177 |
try: |
|
178 |
file = open(filename, "r") |
|
179 |
for line in file.readlines(): |
|
180 |
args.extend(line.split()) |
|
181 |
file.close() |
|
182 |
except: |
|
183 |
raise IOError("couldn't read command file '%s'" % filename) |
|
184 |
||
185 |
# expand any command files in the options we just read. |
|
186 |
# making sure we don't get stuck in a loop. |
|
187 |
usedPlusThis = used[:] |
|
188 |
usedPlusThis.append(filename) |
|
189 |
return ExpandCommandOptions(args, usedPlusThis) |
|
190 |
||
191 |
def ExpandCommandOptions(args, files = []): |
|
192 |
"""recursively expand --command options.""" |
|
193 |
expanded = [] |
|
194 |
previousWasOpt = False |
|
195 |
||
196 |
for a in args: |
|
197 |
if previousWasOpt: # then this one is the filename |
|
198 |
expanded.extend(ReadCommandFile(a, files)) |
|
199 |
previousWasOpt = False |
|
200 |
continue |
|
201 |
||
202 |
if a.startswith(miniCommandOption): |
|
203 |
if "=" in a: # then this is opt=filename |
|
204 |
opt = a.split("=") |
|
205 |
if fullCommandOption.startswith(opt[0]): |
|
206 |
expanded.extend(ReadCommandFile(opt[1], files)) |
|
207 |
continue |
|
208 |
else: # the next one is the filename |
|
209 |
if fullCommandOption.startswith(a): |
|
210 |
previousWasOpt = True |
|
211 |
continue |
|
212 |
||
213 |
expanded.append(a) # an ordinary arg, nothing to do with command files |
|
214 |
||
215 |
return expanded |
|
216 |
||
217 |
def DoRaptor(Raptor, args): |
|
218 |
"Process raptor arguments" |
|
219 |
# |
|
220 |
# This should parse the args list and call methods on |
|
221 |
# the Raptor object to store the appropriate data. |
|
222 |
||
223 |
# Expand --command=file options, replacing them with the contents of the |
|
224 |
# command file. |
|
225 |
||
226 |
non_ascii_error = "Non-ASCII character in argument or command file" |
|
227 |
||
228 |
try: |
|
229 |
expanded_args = ExpandCommandOptions(args) |
|
230 |
for arg in expanded_args: |
|
231 |
for c in arg: |
|
232 |
if ord(c) > 127: |
|
233 |
Raptor.Error(non_ascii_error) |
|
234 |
return False |
|
235 |
except IOError, e: |
|
236 |
Raptor.Error(str(e)) |
|
237 |
return False |
|
238 |
except UnicodeDecodeError: |
|
239 |
Raptor.Error(non_ascii_error) |
|
240 |
return False |
|
241 |
||
242 |
# parse the full set of arguments |
|
243 |
(options, leftover_args) = parser.parse_args(expanded_args) |
|
244 |
||
245 |
# the leftover_args are either variable assignments of the form a=b |
|
246 |
# or target names. |
|
247 |
regex = re.compile("^(.+)=(.*)$") |
|
248 |
for leftover in leftover_args: |
|
249 |
assignment = regex.findall(leftover) |
|
250 |
if len(assignment) > 0: |
|
251 |
Raptor.SetEnv(assignment[0][0],assignment[0][1]) |
|
252 |
else: |
|
253 |
Raptor.AddTarget(leftover) |
|
254 |
||
255 |
# Define the dictionary of functions to be used. |
|
256 |
# Attributes and function names can be added easily. |
|
257 |
# The calling attribute should be the same |
|
258 |
# as specified when creating the add_option |
|
259 |
functions = {'config_name': Raptor.AddConfigName, |
|
260 |
'config_list':Raptor.AddConfigList, |
|
261 |
'sys_def_file' : Raptor.SetSysDefFile, |
|
262 |
'sys_def_base' : Raptor.SetSysDefBase, |
|
263 |
'sys_def_layer' : Raptor.AddSysDefLayer, |
|
264 |
'sys_def_order_layers' : Raptor.SetSysDefOrderLayers, |
|
265 |
'bld_inf_file' : Raptor.AddBuildInfoFile, |
|
266 |
'logfile' : Raptor.SetLogFileName, |
|
267 |
'makefile' : Raptor.SetTopMakefile, |
|
268 |
'quiet' : Raptor.RunQuietly, |
|
269 |
'debugoutput' : Raptor.SetDebugOutput, |
|
270 |
'doExportOnly' : Raptor.SetExportOnly, |
|
11
ea23b18a2ff6
Initial implementation of noexport
tnmurphy@4GBL06592.nokia.com
parents:
5
diff
changeset
|
271 |
'doExport' : Raptor.SetNoExport, |
3 | 272 |
'keepgoing': Raptor.SetKeepGoing, |
273 |
'nobuild' : Raptor.SetNoBuild, |
|
274 |
'make_engine': Raptor.SetMakeEngine, |
|
275 |
'make_option': Raptor.AddMakeOption, |
|
276 |
'noDependInclude': Raptor.SetNoDependInclude, |
|
277 |
'number_of_jobs': Raptor.SetJobs, |
|
278 |
'project_name' : Raptor.AddProject, |
|
279 |
'filter_list' : Raptor.FilterList, |
|
280 |
'ignore_os_detection': Raptor.IgnoreOsDetection, |
|
281 |
'check' : Raptor.SetCheck, |
|
282 |
'what' : Raptor.SetWhat, |
|
283 |
'tries' : Raptor.SetTries, |
|
284 |
'toolcheck' : Raptor.SetToolCheck, |
|
29
ee00c00df073
Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents:
14
diff
changeset
|
285 |
'timing' : Raptor.SetTiming, |
3 | 286 |
'source_target' : Raptor.AddSourceTarget, |
287 |
'command_file' : CommandFile, |
|
288 |
'parallel_parsing' : Raptor.SetParallelParsing, |
|
289 |
'version' : Raptor.PrintVersion |
|
290 |
} |
|
291 |
||
292 |
# Check if Quiet mode has been specified (otherwise we will make noise) |
|
293 |
if parser.values.quiet: |
|
294 |
Raptor.RunQuietly(True) |
|
295 |
||
296 |
# some options imply that Raptor should exit immediately (e.g. --version) |
|
297 |
keepGoing = True |
|
298 |
||
299 |
if parser.values.version: |
|
300 |
keepGoing = False |
|
301 |
||
302 |
# Parse through the command line arguments passed, and call the |
|
303 |
# corresponding function with the correct parameter. |
|
304 |
# Since options is a OptParse.Value instance, it can be iterated over. |
|
305 |
# This implementation helps avoid lengthy if-else statements |
|
306 |
for opt in options.__dict__.items(): |
|
307 |
call_function = functions[str(opt[0])] |
|
308 |
values = opt[1] |
|
309 |
if not values: |
|
310 |
pass |
|
311 |
else: |
|
312 |
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 |
|
313 |
for val in values: |
|
314 |
keepGoing = (call_function(val) and keepGoing) |
|
315 |
else: |
|
316 |
keepGoing = (call_function(values) and keepGoing) |
|
317 |
||
318 |
return keepGoing |
|
319 |
||
320 |
def CommandFile(file): |
|
321 |
"this should never be called because we expand --command in this module." |
|
322 |
print raptor.name + ": error: command file '%s' was not expanded" % file |
|
323 |
return False |
|
324 |
||
325 |
||
326 |
||
327 |
||
328 |
# end of the raptor_cli module |
|
329 |
||
330 |