raptor_cli.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. #
  2. # Copyright (c) 2006-2010 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. import types
  21. import raptor
  22. from optparse import OptionParser # for parsing command line parameters
  23. from raptor_utilities import expand_command_options
  24. # raptor_cli module attributes
  25. parser = OptionParser(prog = raptor.name,
  26. usage = """%prog [--help] [options] [target] ...
  27. Targets:
  28. BITMAP Create bitmap files
  29. CLEAN Remove built files and intermediates, but not exported files
  30. CLEANEXPORT Remove exported files
  31. EXPORT Copy exported files to destinations
  32. FINAL Allow extension makefiles to execute final commands
  33. FREEZE Freeze exported functions in a .DEF file
  34. LIBRARY Create import libraries from frozen .DEF files
  35. LISTING Create assembler listing files for source files
  36. PREPROCESS Create preprocessor output files alongside source files
  37. REALLYCLEAN Same as CLEAN but also remove exported files
  38. RESOURCE Create resource files
  39. ROMFILE Create an IBY file to be included in a ROM
  40. TARGET Create main executables
  41. WHAT List all releaseable targets
  42. Examples:
  43. sbs -b my/group/bld.inf -c armv5 # build my component for target ARMV5
  44. sbs -b my/group/bld.inf -c armv5.test # build my tests for target ARMV5
  45. sbs -c winscw CLEAN # clean emulator files
  46. sbs REALLYCLEAN # delete everything""")
  47. parser.add_option("-a","--sysdefbase",action="store",dest="sys_def_base",
  48. help="Root directory for relative paths in the System Definition XML file.")
  49. parser.add_option("-b","--bldinf",action="append",dest="bld_inf_file",
  50. help="Build information filename. Multiple -b options can be given.")
  51. parser.add_option("-c","--config",action="append",dest="config_name",
  52. help="Configuration name to build. Multiple -c options can be given. The standard configs are all, armv5, armv7, default, tools, tools2 and winscw.")
  53. parser.add_option("--configpath", action="append",dest="config_list",
  54. 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.")
  55. parser.add_option("--check",action="store_true",dest="check",
  56. help="Test for the existence of files created by the build, printing the ones which are missing. Do not build anything.")
  57. parser.add_option("--command",action="append",dest="command_file",
  58. help="Provide a set of command-line options in a file.")
  59. parser.add_option("-d","--debug",action="store_true",dest="debugoutput",
  60. help="Display information useful for debugging.")
  61. parser.add_option("-e","--engine",action="store",dest="make_engine",
  62. help="Name of the make engine which runs the build.")
  63. parser.add_option("--export-only",action="store_true",dest="doExportOnly",
  64. help="Generate exports only and do not create any make files.")
  65. parser.add_option("--noexport",action="store_true",dest="doExport",
  66. help="Don't export any files - useful in some builds when you know exports have already been done.")
  67. parser.add_option("-f","--logfile",action="store",dest="logfile",
  68. help="Name of the log file, or '-' for stdout.")
  69. parser.add_option("--filters",action="store",dest="filter_list",
  70. help="Comma-separated list of names of the filters to use (case sensitive).")
  71. parser.add_option("-i","--ignore-os-detection",action="store_true",dest="ignore_os_detection",
  72. help="Disables automatic application of OS variant based upon the OS version detected from each epoc32 tree.")
  73. parser.add_option("--ip",action="store",dest="incremental_parsing",
  74. help=
  75. "Reuse makefiles from previous builds if they are still "
  76. "relevant. i.e if no bld.infs/mmps or other metadata has "
  77. "changed and if the environment has not altered either. "
  78. "This option can improve raptor's performance but it "
  79. "is possible that it may sometimes be too optimistic "
  80. "and reuse makefiles that really should be regenerated. "
  81. "It cannot currently be used with the parallel parsing "
  82. "option (--pp=on). It is not likely to save time when "
  83. "the --qtpro option is used as there is no way to get the "
  84. "dependencies of a .pro file so qmake must always reparse "
  85. "them and regenerate their bld.inf files."
  86. )
  87. parser.add_option("-j","--jobs",action="store",dest="number_of_jobs",
  88. help="The maximum number of jobs that make should try and run in parallel (on a single machine).")
  89. parser.add_option("-k","--keepgoing",action="store_true",dest="keepgoing",
  90. help="Continue building, even if some build commands fail.")
  91. parser.add_option("-l","--layer",action="append",dest="sys_def_layer",
  92. help="Build a specific layer in the System Definition XML File. Multiple -l options can be given.")
  93. parser.add_option("-m","--makefile",action="store",dest="makefile",
  94. help="Top-level makefile to be created.")
  95. parser.add_option("--mo",action="append",dest="make_option",
  96. help="Option that must be passed through to the make engine. Multiple --mo options can be given.")
  97. parser.add_option("-n","--nobuild",action="store_true",dest="nobuild",
  98. help="Just create makefiles, do not build anything.")
  99. parser.add_option("--no-depend-include",action="store_true",dest="noDependInclude",
  100. help="Do not include generated dependency files. This is only useful for extremely large non-incremental builds.")
  101. parser.add_option("--no-depend-generate",action="store_true",dest="noDependGenerate",
  102. help="Do not generate dependency files. This is only useful for extremely large non-incremental builds. Implies --no-depend-include.")
  103. parser.add_option("-o","--orderlayers",action="store_true",dest="sys_def_order_layers",
  104. help="Build layers in the System Definition XML file in the order listed or, if given, in the order of -l options.")
  105. parser.add_option("-p","--project",action="append",dest="project_name",
  106. help="Build a specific project (mmp or extension) in the given bld.inf file. Multiple -p options can be given.")
  107. parser.add_option("-q","--quiet",action="store_true",dest="quiet",
  108. help="Run quietly, not generating output messages.")
  109. parser.add_option("--qtpro",action="append",dest="qt_pro_file",
  110. help="Qt project (.pro) file name. Multiple --qtpro options can be given.")
  111. parser.add_option("--query",action="append",dest="query",
  112. help="""Access various build settings and options using a basic API. The current options are:
  113. * aliases - return all the values that can be sensibly used with the sbs -c option.
  114. * products - return all the values that can be "." appended to an alias to specialise it for a product build.
  115. * 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.
  116. Multiple --query options can be given.
  117. """)
  118. parser.add_option("-s","--sysdef",action="store",dest="sys_def_file",
  119. help="System Definition XML filename.")
  120. parser.add_option("--source-target",action="append",dest="source_target",
  121. help="Build the listed source or resource file in isolation - do not perform any dependent processing. Multiple --source-target options can be given.")
  122. parser.add_option("-t","--tries",action="store",dest="tries",
  123. 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.")
  124. parser.add_option("--toolcheck",action="store",dest="toolcheck",
  125. help= \
  126. """Possible values are:
  127. "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.
  128. "off" - Do not check tool versions whatsoever.
  129. "forced" - Check all tool versions. Don't use cached results.
  130. """)
  131. parser.add_option("--timing",action="store_true",dest="timing",
  132. help="Show extra timing information for various processes in the build.")
  133. parser.add_option("--pp",action="store",dest="parallel_parsing",
  134. help="""Controls how metadata (e.g. bld.infs) are parsed in Parallel.
  135. Possible values are:
  136. "on" - Parse bld.infs in parallel (should be faster on clusters/multicore machines)
  137. "slave" - used internally by Raptor
  138. "off" - Parse bld.infs serially
  139. """)
  140. parser.add_option("--use-rsg-casefolding", action="store_true", dest="resource_rsg_casefolding",
  141. help="""This option should not be used permanently to work around case issues on Linux. Case issues need to be fixed and this option should only be used before that has been done.
  142. Generate resource rsg files in lowercase regardless what is specified in mmp file.
  143. """)
  144. parser.add_option("-v","--version",action="store_true",dest="version",
  145. help="Print the version number and exit.")
  146. parser.add_option("--what",action="store_true",dest="what",
  147. help="Print out the names of the files created by the build. Do not build anything.")
  148. def GetArgs(Raptor, args):
  149. "Process command line arguments for a Raptor object"
  150. return DoRaptor(Raptor,args)
  151. def DoRaptor(Raptor, args):
  152. "Process raptor arguments"
  153. #
  154. # This should parse the args list and call methods on
  155. # the Raptor object to store the appropriate data.
  156. # Expand --command=file options, replacing them with the contents of the
  157. # command file.
  158. non_ascii_error = "Non-ASCII character in argument or command file"
  159. try:
  160. expanded_args = expand_command_options(args)
  161. for arg in expanded_args:
  162. for c in arg:
  163. if ord(c) > 127:
  164. Raptor.Error(non_ascii_error)
  165. return False
  166. except IOError, e:
  167. Raptor.Error(str(e))
  168. return False
  169. except UnicodeDecodeError:
  170. Raptor.Error(non_ascii_error)
  171. return False
  172. # parse the full set of arguments
  173. (options, leftover_args) = parser.parse_args(expanded_args)
  174. # the leftover_args are target names.
  175. for leftover in leftover_args:
  176. Raptor.AddTarget(leftover)
  177. # Define the dictionary of functions to be used.
  178. # Attributes and function names can be added easily.
  179. # The calling attribute should be the same
  180. # as specified when creating the add_option
  181. functions = {'config_name': Raptor.AddConfigName,
  182. 'config_list':Raptor.AddConfigList,
  183. 'sys_def_file' : Raptor.SetSysDefFile,
  184. 'sys_def_base' : Raptor.SetSysDefBase,
  185. 'sys_def_layer' : Raptor.AddSysDefLayer,
  186. 'sys_def_order_layers' : Raptor.SetSysDefOrderLayers,
  187. 'bld_inf_file' : Raptor.AddBuildInfoFile,
  188. 'logfile' : Raptor.SetLogFileName,
  189. 'makefile' : Raptor.SetTopMakefile,
  190. 'qt_pro_file' : Raptor.AddQtProFile,
  191. 'quiet' : Raptor.RunQuietly,
  192. 'debugoutput' : Raptor.SetDebugOutput,
  193. 'doExportOnly' : Raptor.SetExportOnly,
  194. 'doExport' : Raptor.SetNoExport,
  195. 'keepgoing': Raptor.SetKeepGoing,
  196. 'nobuild' : Raptor.SetNoBuild,
  197. 'make_engine': Raptor.SetMakeEngine,
  198. 'make_option': Raptor.AddMakeOption,
  199. 'noDependInclude': Raptor.SetNoDependInclude,
  200. 'noDependGenerate': Raptor.SetNoDependGenerate,
  201. 'number_of_jobs': Raptor.SetJobs,
  202. 'project_name' : Raptor.AddProject,
  203. 'query' : Raptor.AddQuery,
  204. 'filter_list' : Raptor.FilterList,
  205. 'ignore_os_detection': Raptor.IgnoreOsDetection,
  206. 'check' : Raptor.SetCheck,
  207. 'what' : Raptor.SetWhat,
  208. 'tries' : Raptor.SetTries,
  209. 'toolcheck' : Raptor.SetToolCheck,
  210. 'timing' : Raptor.SetTiming,
  211. 'source_target' : Raptor.AddSourceTarget,
  212. 'command_file' : CommandFile,
  213. 'parallel_parsing' : Raptor.SetParallelParsing,
  214. 'resource_rsg_casefolding' : Raptor.SetRsgCaseFolding,
  215. 'incremental_parsing' : Raptor.SetIncrementalParsing,
  216. 'version' : Raptor.PrintVersion
  217. }
  218. # Check if Quiet mode has been specified (otherwise we will make noise)
  219. if parser.values.quiet:
  220. Raptor.RunQuietly(True)
  221. # only return True if there are no command-line errors
  222. keepGoing = True
  223. # Parse through the command line arguments passed, and call the
  224. # corresponding function with the correct parameter.
  225. # Since options is a OptParse.Value instance, it can be iterated over.
  226. # This implementation helps avoid lengthy if-else statements
  227. for opt in options.__dict__.items():
  228. call_function = functions[str(opt[0])]
  229. values = opt[1]
  230. if not values:
  231. pass
  232. else:
  233. 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
  234. for val in values:
  235. keepGoing = (call_function(val) and keepGoing)
  236. else:
  237. keepGoing = (call_function(values) and keepGoing)
  238. return keepGoing
  239. def CommandFile(file):
  240. "this should never be called because we expand --command in this module."
  241. print raptor.name + ": error: command file '%s' was not expanded" % file
  242. return False
  243. # end of the raptor_cli module