Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.py 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. #! /usr/bin/env python2
  2. """
  3. mbed SDK
  4. Copyright (c) 2011-2013 ARM Limited
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. LIBRARIES BUILD
  15. """
  16. import sys
  17. from time import time
  18. from os.path import join, abspath, dirname
  19. # Be sure that the tools directory is in the search path
  20. ROOT = abspath(join(dirname(__file__), ".."))
  21. sys.path.insert(0, ROOT)
  22. from workspace_tools.toolchains import TOOLCHAINS
  23. from workspace_tools.toolchains import print_notify_verbose
  24. from workspace_tools.targets import TARGET_NAMES, TARGET_MAP
  25. from workspace_tools.options import get_default_options_parser
  26. from workspace_tools.build_api import build_mbed_libs, build_lib
  27. from workspace_tools.build_api import mcu_toolchain_matrix
  28. from workspace_tools.build_api import static_analysis_scan, static_analysis_scan_lib, static_analysis_scan_library
  29. from workspace_tools.build_api import print_build_results
  30. from workspace_tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT
  31. if __name__ == '__main__':
  32. start = time()
  33. # Parse Options
  34. parser = get_default_options_parser()
  35. # Extra libraries
  36. parser.add_option("-r", "--rtos",
  37. action="store_true",
  38. dest="rtos",
  39. default=False,
  40. help="Compile the rtos")
  41. parser.add_option("-e", "--eth",
  42. action="store_true", dest="eth",
  43. default=False,
  44. help="Compile the ethernet library")
  45. parser.add_option("-U", "--usb_host",
  46. action="store_true",
  47. dest="usb_host",
  48. default=False,
  49. help="Compile the USB Host library")
  50. parser.add_option("-u", "--usb",
  51. action="store_true",
  52. dest="usb",
  53. default=False,
  54. help="Compile the USB Device library")
  55. parser.add_option("-d", "--dsp",
  56. action="store_true",
  57. dest="dsp",
  58. default=False,
  59. help="Compile the DSP library")
  60. parser.add_option("-F", "--fat",
  61. action="store_true",
  62. dest="fat",
  63. default=False,
  64. help="Compile FS ad SD card file system library")
  65. parser.add_option("-b", "--ublox",
  66. action="store_true",
  67. dest="ublox",
  68. default=False,
  69. help="Compile the u-blox library")
  70. parser.add_option("", "--cpputest",
  71. action="store_true",
  72. dest="cpputest_lib",
  73. default=False,
  74. help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)")
  75. parser.add_option("-D", "",
  76. action="append",
  77. dest="macros",
  78. help="Add a macro definition")
  79. parser.add_option("-S", "--supported-toolchains",
  80. action="store_true",
  81. dest="supported_toolchains",
  82. default=False,
  83. help="Displays supported matrix of MCUs and toolchains")
  84. parser.add_option("", "--cppcheck",
  85. action="store_true",
  86. dest="cppcheck_validation",
  87. default=False,
  88. help="Forces 'cppcheck' static code analysis")
  89. parser.add_option('-f', '--filter',
  90. dest='general_filter_regex',
  91. default=None,
  92. help='For some commands you can use filter to filter out results')
  93. parser.add_option("-j", "--jobs", type="int", dest="jobs",
  94. default=1, help="Number of concurrent jobs (default 1). Use 0 for auto based on host machine's number of CPUs")
  95. parser.add_option("-v", "--verbose",
  96. action="store_true",
  97. dest="verbose",
  98. default=False,
  99. help="Verbose diagnostic output")
  100. parser.add_option("--silent",
  101. action="store_true",
  102. dest="silent",
  103. default=False,
  104. help="Silent diagnostic output (no copy, compile notification)")
  105. parser.add_option("-x", "--extra-verbose-notifications",
  106. action="store_true",
  107. dest="extra_verbose_notify",
  108. default=False,
  109. help="Makes compiler more verbose, CI friendly.")
  110. (options, args) = parser.parse_args()
  111. # Only prints matrix of supported toolchains
  112. if options.supported_toolchains:
  113. print mcu_toolchain_matrix(platform_filter=options.general_filter_regex)
  114. exit(0)
  115. # Get target list
  116. if options.mcu:
  117. mcu_list = (options.mcu).split(",")
  118. for mcu in mcu_list:
  119. if mcu not in TARGET_NAMES:
  120. print "Given MCU '%s' not into the supported list:\n%s" % (mcu, TARGET_NAMES)
  121. sys.exit(1)
  122. targets = mcu_list
  123. else:
  124. targets = TARGET_NAMES
  125. # Get toolchains list
  126. if options.tool:
  127. toolchain_list = (options.tool).split(",")
  128. for tc in toolchain_list:
  129. if tc not in TOOLCHAINS:
  130. print "Given toolchain '%s' not into the supported list:\n%s" % (tc, TOOLCHAINS)
  131. sys.exit(1)
  132. toolchains = toolchain_list
  133. else:
  134. toolchains = TOOLCHAINS
  135. # Get libraries list
  136. libraries = []
  137. # Additional Libraries
  138. if options.rtos:
  139. libraries.extend(["rtx", "rtos"])
  140. if options.eth:
  141. libraries.append("eth")
  142. if options.usb:
  143. libraries.append("usb")
  144. if options.usb_host:
  145. libraries.append("usb_host")
  146. if options.dsp:
  147. libraries.extend(["cmsis_dsp", "dsp"])
  148. if options.fat:
  149. libraries.extend(["fat"])
  150. if options.ublox:
  151. libraries.extend(["rtx", "rtos", "usb_host", "ublox"])
  152. if options.cpputest_lib:
  153. libraries.extend(["cpputest"])
  154. notify = print_notify_verbose if options.extra_verbose_notify else None # Special notify for CI (more verbose)
  155. # Build results
  156. failures = []
  157. successes = []
  158. skipped = []
  159. # CPPCHECK code validation
  160. if options.cppcheck_validation:
  161. for toolchain in toolchains:
  162. for target in targets:
  163. try:
  164. mcu = TARGET_MAP[target]
  165. # CMSIS and MBED libs analysis
  166. static_analysis_scan(mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, verbose=options.verbose, jobs=options.jobs)
  167. for lib_id in libraries:
  168. # Static check for library
  169. static_analysis_scan_lib(lib_id, mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT,
  170. options=options.options,
  171. notify=notify, verbose=options.verbose, jobs=options.jobs, clean=options.clean,
  172. macros=options.macros)
  173. pass
  174. except Exception, e:
  175. if options.verbose:
  176. import traceback
  177. traceback.print_exc(file=sys.stdout)
  178. sys.exit(1)
  179. print e
  180. else:
  181. # Build
  182. for toolchain in toolchains:
  183. for target in targets:
  184. tt_id = "%s::%s" % (toolchain, target)
  185. try:
  186. mcu = TARGET_MAP[target]
  187. lib_build_res = build_mbed_libs(mcu, toolchain,
  188. options=options.options,
  189. notify=notify,
  190. verbose=options.verbose,
  191. silent=options.silent,
  192. jobs=options.jobs,
  193. clean=options.clean,
  194. macros=options.macros)
  195. for lib_id in libraries:
  196. notify = print_notify_verbose if options.extra_verbose_notify else None # Special notify for CI (more verbose)
  197. build_lib(lib_id, mcu, toolchain,
  198. options=options.options,
  199. notify=notify,
  200. verbose=options.verbose,
  201. silent=options.silent,
  202. clean=options.clean,
  203. macros=options.macros,
  204. jobs=options.jobs)
  205. if lib_build_res:
  206. successes.append(tt_id)
  207. else:
  208. skipped.append(tt_id)
  209. except Exception, e:
  210. if options.verbose:
  211. import traceback
  212. traceback.print_exc(file=sys.stdout)
  213. sys.exit(1)
  214. failures.append(tt_id)
  215. print e
  216. # Write summary of the builds
  217. print
  218. print "Completed in: (%.2f)s" % (time() - start)
  219. print
  220. print print_build_results(successes, "Build successes:"),
  221. print print_build_results(skipped, "Build skipped:"),
  222. print print_build_results(failures, "Build failures:"),
  223. if failures:
  224. sys.exit(1)