upload
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

project.py 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import sys
  2. from os.path import join, abspath, dirname, exists
  3. ROOT = abspath(join(dirname(__file__), ".."))
  4. sys.path.insert(0, ROOT)
  5. from shutil import move, rmtree
  6. from optparse import OptionParser
  7. from workspace_tools.paths import EXPORT_DIR, EXPORT_WORKSPACE, EXPORT_TMP
  8. from workspace_tools.paths import MBED_BASE, MBED_LIBRARIES
  9. from workspace_tools.export import export, setup_user_prj, EXPORTERS, mcu_ide_matrix
  10. from workspace_tools.utils import args_error
  11. from workspace_tools.tests import TESTS, Test, TEST_MAP
  12. from workspace_tools.targets import TARGET_NAMES
  13. from workspace_tools.libraries import LIBRARIES
  14. try:
  15. import workspace_tools.private_settings as ps
  16. except:
  17. ps = object()
  18. if __name__ == '__main__':
  19. # Parse Options
  20. parser = OptionParser()
  21. targetnames = TARGET_NAMES
  22. targetnames.sort()
  23. toolchainlist = EXPORTERS.keys()
  24. toolchainlist.sort()
  25. parser.add_option("-m", "--mcu",
  26. metavar="MCU",
  27. default='LPC1768',
  28. help="generate project for the given MCU (%s)"% ', '.join(targetnames))
  29. parser.add_option("-i",
  30. dest="ide",
  31. default='uvision',
  32. help="The target IDE: %s"% str(toolchainlist))
  33. parser.add_option("-c", "--clean",
  34. action="store_true",
  35. default=False,
  36. help="clean the export directory")
  37. parser.add_option("-p",
  38. type="int",
  39. dest="program",
  40. help="The index of the desired test program: [0-%d]"% (len(TESTS)-1))
  41. parser.add_option("-n",
  42. dest="program_name",
  43. help="The name of the desired test program")
  44. parser.add_option("-b",
  45. dest="build",
  46. action="store_true",
  47. default=False,
  48. help="use the mbed library build, instead of the sources")
  49. parser.add_option("-L", "--list-tests",
  50. action="store_true",
  51. dest="list_tests",
  52. default=False,
  53. help="list available programs in order and exit")
  54. parser.add_option("-S", "--list-matrix",
  55. action="store_true",
  56. dest="supported_ides",
  57. default=False,
  58. help="displays supported matrix of MCUs and IDEs")
  59. parser.add_option("-E",
  60. action="store_true",
  61. dest="supported_ides_html",
  62. default=False,
  63. help="writes workspace_tools/export/README.md")
  64. (options, args) = parser.parse_args()
  65. # Print available tests in order and exit
  66. if options.list_tests is True:
  67. print '\n'.join(map(str, sorted(TEST_MAP.values())))
  68. sys.exit()
  69. # Only prints matrix of supported IDEs
  70. if options.supported_ides:
  71. print mcu_ide_matrix()
  72. exit(0)
  73. # Only prints matrix of supported IDEs
  74. if options.supported_ides_html:
  75. html = mcu_ide_matrix(verbose_html=True)
  76. try:
  77. with open("./export/README.md","w") as f:
  78. f.write("Exporter IDE/Platform Support\n")
  79. f.write("-----------------------------------\n")
  80. f.write("\n")
  81. f.write(html)
  82. except IOError as e:
  83. print "I/O error({0}): {1}".format(e.errno, e.strerror)
  84. except:
  85. print "Unexpected error:", sys.exc_info()[0]
  86. raise
  87. exit(0)
  88. # Clean Export Directory
  89. if options.clean:
  90. if exists(EXPORT_DIR):
  91. rmtree(EXPORT_DIR)
  92. # Target
  93. if options.mcu is None :
  94. args_error(parser, "[ERROR] You should specify an MCU")
  95. mcus = options.mcu
  96. # IDE
  97. if options.ide is None:
  98. args_error(parser, "[ERROR] You should specify an IDE")
  99. ide = options.ide
  100. # Export results
  101. successes = []
  102. failures = []
  103. for mcu in mcus.split(','):
  104. # Program Number or name
  105. p, n = options.program, options.program_name
  106. if n is not None and p is not None:
  107. args_error(parser, "[ERROR] specify either '-n' or '-p', not both")
  108. if n:
  109. if not n in TEST_MAP.keys():
  110. # Check if there is an alias for this in private_settings.py
  111. if getattr(ps, "test_alias", None) is not None:
  112. alias = ps.test_alias.get(n, "")
  113. if not alias in TEST_MAP.keys():
  114. args_error(parser, "[ERROR] Program with name '%s' not found" % n)
  115. else:
  116. n = alias
  117. else:
  118. args_error(parser, "[ERROR] Program with name '%s' not found" % n)
  119. p = TEST_MAP[n].n
  120. if p is None or (p < 0) or (p > (len(TESTS)-1)):
  121. message = "[ERROR] You have to specify one of the following tests:\n"
  122. message += '\n'.join(map(str, sorted(TEST_MAP.values())))
  123. args_error(parser, message)
  124. # Project
  125. if p is None or (p < 0) or (p > (len(TESTS)-1)):
  126. message = "[ERROR] You have to specify one of the following tests:\n"
  127. message += '\n'.join(map(str, sorted(TEST_MAP.values())))
  128. args_error(parser, message)
  129. test = Test(p)
  130. # Some libraries have extra macros (called by exporter symbols) to we need to pass
  131. # them to maintain compilation macros integrity between compiled library and
  132. # header files we might use with it
  133. lib_symbols = []
  134. for lib in LIBRARIES:
  135. if lib['build_dir'] in test.dependencies:
  136. lib_macros = lib.get('macros', None)
  137. if lib_macros is not None:
  138. lib_symbols.extend(lib_macros)
  139. if not options.build:
  140. # Substitute the library builds with the sources
  141. # TODO: Substitute also the other library build paths
  142. if MBED_LIBRARIES in test.dependencies:
  143. test.dependencies.remove(MBED_LIBRARIES)
  144. test.dependencies.append(MBED_BASE)
  145. # Build the project with the same directory structure of the mbed online IDE
  146. project_dir = join(EXPORT_WORKSPACE, test.id)
  147. setup_user_prj(project_dir, test.source_dir, test.dependencies)
  148. # Export to selected toolchain
  149. tmp_path, report = export(project_dir, test.id, ide, mcu, EXPORT_WORKSPACE, EXPORT_TMP, extra_symbols=lib_symbols)
  150. if report['success']:
  151. zip_path = join(EXPORT_DIR, "%s_%s_%s.zip" % (test.id, ide, mcu))
  152. move(tmp_path, zip_path)
  153. successes.append("%s::%s\t%s"% (mcu, ide, zip_path))
  154. else:
  155. failures.append("%s::%s\t%s"% (mcu, ide, report['errormsg']))
  156. # Prints export results
  157. print
  158. if len(successes) > 0:
  159. print "Successful exports:"
  160. for success in successes:
  161. print " * %s"% success
  162. if len(failures) > 0:
  163. print "Failed exports:"
  164. for failure in failures:
  165. print " * %s"% failure