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 |
|
|
90 |
parser.add_option("-f","--logfile",action="store",dest="logfile",
|
|
91 |
help="Name of the log file, or '-' for stdout.")
|
|
92 |
|
|
93 |
parser.add_option("--filters",action="store",dest="filter_list",
|
|
94 |
help="Comma-separated list of names of the filters to use (case sensitive).")
|
|
95 |
|
|
96 |
parser.add_option("-i","--ignore-os-detection",action="store_true",dest="ignore_os_detection",
|
|
97 |
help="Disables automatic application of OS variant based upon the OS version detected from each epoc32 tree.")
|
|
98 |
|
|
99 |
parser.add_option("-j","--jobs",action="store",dest="number_of_jobs",
|
|
100 |
help="The maximum number of jobs that make should try and run in parallel (on a single machine).")
|
|
101 |
|
|
102 |
parser.add_option("-k","--keepgoing",action="store_true",dest="keepgoing",
|
|
103 |
help="Continue building, even if some build commands fail.")
|
|
104 |
|
|
105 |
parser.add_option("-l","--layer",action="append",dest="sys_def_layer",
|
|
106 |
help="Build a specific layer in the System Definition XML File. Multiple -l options can be given.")
|
|
107 |
|
|
108 |
parser.add_option("-m","--makefile",action="store",dest="makefile",
|
|
109 |
help="Top-level makefile to be created.")
|
|
110 |
|
|
111 |
parser.add_option("--mo",action="append",dest="make_option",
|
|
112 |
help="Option that must be passed through to the make engine. Multiple --mo options can be given.")
|
|
113 |
|
|
114 |
parser.add_option("-n","--nobuild",action="store_true",dest="nobuild",
|
|
115 |
help="Just create makefiles, do not build anything.")
|
|
116 |
|
|
117 |
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.")
|
|
119 |
|
|
120 |
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 |
|
|
123 |
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 |
|
|
126 |
parser.add_option("-q","--quiet",action="store_true",dest="quiet",
|
|
127 |
help="Run quietly, not generating output messages.")
|
|
128 |
|
|
129 |
parser.add_option("-s","--sysdef",action="store",dest="sys_def_file",
|
|
130 |
help="System Definition XML filename.")
|
|
131 |
|
|
132 |
parser.add_option("--source-target",action="append",dest="source_target",
|
|
133 |
help="Build the listed source or resource file in isolation - do not perform any dependent processing. Multiple --source-target options can be given.")
|
|
134 |
|
|
135 |
parser.add_option("-t","--tries",action="store",dest="tries",
|
|
136 |
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.")
|
|
137 |
|
|
138 |
parser.add_option("--toolcheck",action="store",dest="toolcheck",
|
|
139 |
help= \
|
|
140 |
"""Possible values are:
|
|
141 |
"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.
|
|
142 |
|
|
143 |
"off" - Do not check tool versions whatsoever.
|
|
144 |
|
|
145 |
"forced" - Check all tool versions. Don't use cached results.
|
|
146 |
""")
|
|
147 |
parser.add_option("--pp",action="store",dest="parallel_parsing",
|
|
148 |
help="""Controls how metadata (e.g. bld.infs) are parsed in Parallel.
|
|
149 |
Possible values are:
|
|
150 |
"on" - Parse bld.infs in parallel (should be faster on clusters/multicore machines)
|
5
|
151 |
"slave" - used internally by Raptor
|
3
|
152 |
"off" - Parse bld.infs serially
|
|
153 |
""")
|
|
154 |
|
|
155 |
parser.add_option("-v","--version",action="store_true",dest="version",
|
|
156 |
help="Print the version number and exit.")
|
|
157 |
|
|
158 |
parser.add_option("--what",action="store_true",dest="what",
|
|
159 |
help="Print out the names of the files created by the build. Do not build anything.")
|
|
160 |
|
|
161 |
def GetArgs(Raptor, args):
|
|
162 |
"Process command line arguments for a Raptor object"
|
|
163 |
return DoRaptor(Raptor,args)
|
|
164 |
|
|
165 |
def ReadCommandFile(filename, used):
|
|
166 |
if filename in used:
|
|
167 |
raise IOError("command file '%s' refers to itself" % filename)
|
|
168 |
|
|
169 |
args = []
|
|
170 |
try:
|
|
171 |
file = open(filename, "r")
|
|
172 |
for line in file.readlines():
|
|
173 |
args.extend(line.split())
|
|
174 |
file.close()
|
|
175 |
except:
|
|
176 |
raise IOError("couldn't read command file '%s'" % filename)
|
|
177 |
|
|
178 |
# expand any command files in the options we just read.
|
|
179 |
# making sure we don't get stuck in a loop.
|
|
180 |
usedPlusThis = used[:]
|
|
181 |
usedPlusThis.append(filename)
|
|
182 |
return ExpandCommandOptions(args, usedPlusThis)
|
|
183 |
|
|
184 |
def ExpandCommandOptions(args, files = []):
|
|
185 |
"""recursively expand --command options."""
|
|
186 |
expanded = []
|
|
187 |
previousWasOpt = False
|
|
188 |
|
|
189 |
for a in args:
|
|
190 |
if previousWasOpt: # then this one is the filename
|
|
191 |
expanded.extend(ReadCommandFile(a, files))
|
|
192 |
previousWasOpt = False
|
|
193 |
continue
|
|
194 |
|
|
195 |
if a.startswith(miniCommandOption):
|
|
196 |
if "=" in a: # then this is opt=filename
|
|
197 |
opt = a.split("=")
|
|
198 |
if fullCommandOption.startswith(opt[0]):
|
|
199 |
expanded.extend(ReadCommandFile(opt[1], files))
|
|
200 |
continue
|
|
201 |
else: # the next one is the filename
|
|
202 |
if fullCommandOption.startswith(a):
|
|
203 |
previousWasOpt = True
|
|
204 |
continue
|
|
205 |
|
|
206 |
expanded.append(a) # an ordinary arg, nothing to do with command files
|
|
207 |
|
|
208 |
return expanded
|
|
209 |
|
|
210 |
def DoRaptor(Raptor, args):
|
|
211 |
"Process raptor arguments"
|
|
212 |
#
|
|
213 |
# This should parse the args list and call methods on
|
|
214 |
# the Raptor object to store the appropriate data.
|
|
215 |
|
|
216 |
# Expand --command=file options, replacing them with the contents of the
|
|
217 |
# command file.
|
|
218 |
|
|
219 |
non_ascii_error = "Non-ASCII character in argument or command file"
|
|
220 |
|
|
221 |
try:
|
|
222 |
expanded_args = ExpandCommandOptions(args)
|
|
223 |
for arg in expanded_args:
|
|
224 |
for c in arg:
|
|
225 |
if ord(c) > 127:
|
|
226 |
Raptor.Error(non_ascii_error)
|
|
227 |
return False
|
|
228 |
except IOError, e:
|
|
229 |
Raptor.Error(str(e))
|
|
230 |
return False
|
|
231 |
except UnicodeDecodeError:
|
|
232 |
Raptor.Error(non_ascii_error)
|
|
233 |
return False
|
|
234 |
|
|
235 |
# parse the full set of arguments
|
|
236 |
(options, leftover_args) = parser.parse_args(expanded_args)
|
|
237 |
|
|
238 |
# the leftover_args are either variable assignments of the form a=b
|
|
239 |
# or target names.
|
|
240 |
regex = re.compile("^(.+)=(.*)$")
|
|
241 |
for leftover in leftover_args:
|
|
242 |
assignment = regex.findall(leftover)
|
|
243 |
if len(assignment) > 0:
|
|
244 |
Raptor.SetEnv(assignment[0][0],assignment[0][1])
|
|
245 |
else:
|
|
246 |
Raptor.AddTarget(leftover)
|
|
247 |
|
|
248 |
# Define the dictionary of functions to be used.
|
|
249 |
# Attributes and function names can be added easily.
|
|
250 |
# The calling attribute should be the same
|
|
251 |
# as specified when creating the add_option
|
|
252 |
functions = {'config_name': Raptor.AddConfigName,
|
|
253 |
'config_list':Raptor.AddConfigList,
|
|
254 |
'sys_def_file' : Raptor.SetSysDefFile,
|
|
255 |
'sys_def_base' : Raptor.SetSysDefBase,
|
|
256 |
'sys_def_layer' : Raptor.AddSysDefLayer,
|
|
257 |
'sys_def_order_layers' : Raptor.SetSysDefOrderLayers,
|
|
258 |
'bld_inf_file' : Raptor.AddBuildInfoFile,
|
|
259 |
'logfile' : Raptor.SetLogFileName,
|
|
260 |
'makefile' : Raptor.SetTopMakefile,
|
|
261 |
'quiet' : Raptor.RunQuietly,
|
|
262 |
'debugoutput' : Raptor.SetDebugOutput,
|
|
263 |
'doExportOnly' : Raptor.SetExportOnly,
|
|
264 |
'keepgoing': Raptor.SetKeepGoing,
|
|
265 |
'nobuild' : Raptor.SetNoBuild,
|
|
266 |
'make_engine': Raptor.SetMakeEngine,
|
|
267 |
'make_option': Raptor.AddMakeOption,
|
|
268 |
'noDependInclude': Raptor.SetNoDependInclude,
|
|
269 |
'number_of_jobs': Raptor.SetJobs,
|
|
270 |
'project_name' : Raptor.AddProject,
|
|
271 |
'filter_list' : Raptor.FilterList,
|
|
272 |
'ignore_os_detection': Raptor.IgnoreOsDetection,
|
|
273 |
'check' : Raptor.SetCheck,
|
|
274 |
'what' : Raptor.SetWhat,
|
|
275 |
'tries' : Raptor.SetTries,
|
|
276 |
'toolcheck' : Raptor.SetToolCheck,
|
|
277 |
'source_target' : Raptor.AddSourceTarget,
|
|
278 |
'command_file' : CommandFile,
|
|
279 |
'parallel_parsing' : Raptor.SetParallelParsing,
|
|
280 |
'version' : Raptor.PrintVersion
|
|
281 |
}
|
|
282 |
|
|
283 |
# Check if Quiet mode has been specified (otherwise we will make noise)
|
|
284 |
if parser.values.quiet:
|
|
285 |
Raptor.RunQuietly(True)
|
|
286 |
|
|
287 |
# some options imply that Raptor should exit immediately (e.g. --version)
|
|
288 |
keepGoing = True
|
|
289 |
|
|
290 |
if parser.values.version:
|
|
291 |
keepGoing = False
|
|
292 |
|
|
293 |
# Parse through the command line arguments passed, and call the
|
|
294 |
# corresponding function with the correct parameter.
|
|
295 |
# Since options is a OptParse.Value instance, it can be iterated over.
|
|
296 |
# This implementation helps avoid lengthy if-else statements
|
|
297 |
for opt in options.__dict__.items():
|
|
298 |
call_function = functions[str(opt[0])]
|
|
299 |
values = opt[1]
|
|
300 |
if not values:
|
|
301 |
pass
|
|
302 |
else:
|
|
303 |
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
|
|
304 |
for val in values:
|
|
305 |
keepGoing = (call_function(val) and keepGoing)
|
|
306 |
else:
|
|
307 |
keepGoing = (call_function(values) and keepGoing)
|
|
308 |
|
|
309 |
return keepGoing
|
|
310 |
|
|
311 |
def CommandFile(file):
|
|
312 |
"this should never be called because we expand --command in this module."
|
|
313 |
print raptor.name + ": error: command file '%s' was not expanded" % file
|
|
314 |
return False
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
# end of the raptor_cli module
|
|
320 |
|
|
321 |
|