Keyboard firmwares for Atmel AVR and Cortex-M
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

__init__.py 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. """
  2. mbed SDK
  3. Copyright (c) 2011-2013 ARM Limited
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. """
  14. import os, tempfile
  15. from os.path import join, exists, basename
  16. from shutil import copytree, rmtree, copy
  17. from workspace_tools.utils import mkdir
  18. from workspace_tools.export import uvision4, codesourcery, codered, gccarm, ds5_5, iar, emblocks, coide, kds, zip
  19. from workspace_tools.export.exporters import zip_working_directory_and_clean_up, OldLibrariesException
  20. from workspace_tools.targets import TARGET_NAMES, EXPORT_MAP
  21. EXPORTERS = {
  22. 'uvision': uvision4.Uvision4,
  23. 'lpcxpresso': codered.CodeRed,
  24. 'codesourcery': codesourcery.CodeSourcery,
  25. 'gcc_arm': gccarm.GccArm,
  26. 'ds5_5': ds5_5.DS5_5,
  27. 'iar': iar.IAREmbeddedWorkbench,
  28. 'emblocks' : emblocks.IntermediateFile,
  29. 'coide' : coide.CoIDE,
  30. 'kds' : kds.KDS,
  31. }
  32. ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN = """
  33. Sorry, the target %s is not currently supported on the %s toolchain.
  34. Please refer to <a href='/handbook/Exporting-to-offline-toolchains' target='_blank'>Exporting to offline toolchains</a> for more information.
  35. """
  36. ERROR_MESSAGE_NOT_EXPORT_LIBS = """
  37. To export this project please <a href='http://mbed.org/compiler/?import=http://mbed.org/users/mbed_official/code/mbed-export/k&mode=lib' target='_blank'>import the export version of the mbed library</a>.
  38. """
  39. def online_build_url_resolver(url):
  40. # TODO: Retrieve the path and name of an online library build URL
  41. return {'path':'', 'name':''}
  42. def export(project_path, project_name, ide, target, destination='/tmp/',
  43. tempdir=None, clean=True, extra_symbols=None, build_url_resolver=online_build_url_resolver):
  44. # Convention: we are using capitals for toolchain and target names
  45. if target is not None:
  46. target = target.upper()
  47. if tempdir is None:
  48. tempdir = tempfile.mkdtemp()
  49. report = {'success': False}
  50. if ide is None or ide == "zip":
  51. # Simple ZIP exporter
  52. try:
  53. ide = "zip"
  54. exporter = zip.ZIP(target, tempdir, project_name, build_url_resolver, extra_symbols=extra_symbols)
  55. exporter.scan_and_copy_resources(project_path, tempdir)
  56. exporter.generate()
  57. report['success'] = True
  58. except OldLibrariesException, e:
  59. report['errormsg'] = ERROR_MESSAGE_NOT_EXPORT_LIBS
  60. else:
  61. if ide not in EXPORTERS:
  62. report['errormsg'] = "Unsupported toolchain"
  63. else:
  64. Exporter = EXPORTERS[ide]
  65. target = EXPORT_MAP.get(target, target)
  66. if target not in Exporter.TARGETS:
  67. report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)
  68. else:
  69. try:
  70. exporter = Exporter(target, tempdir, project_name, build_url_resolver, extra_symbols=extra_symbols)
  71. exporter.scan_and_copy_resources(project_path, tempdir)
  72. exporter.generate()
  73. report['success'] = True
  74. except OldLibrariesException, e:
  75. report['errormsg'] = ERROR_MESSAGE_NOT_EXPORT_LIBS
  76. zip_path = None
  77. if report['success']:
  78. # add readme file to every offline export.
  79. open(os.path.join(tempdir, 'GettingStarted.htm'),'w').write('<meta http-equiv="refresh" content="0; url=http://mbed.org/handbook/Getting-Started-mbed-Exporters#%s"/>'% (ide))
  80. # copy .hgignore file to exported direcotry as well.
  81. copy(os.path.join(exporter.TEMPLATE_DIR,'.hgignore'),tempdir)
  82. zip_path = zip_working_directory_and_clean_up(tempdir, destination, project_name, clean)
  83. return zip_path, report
  84. ###############################################################################
  85. # Generate project folders following the online conventions
  86. ###############################################################################
  87. def copy_tree(src, dst, clean=True):
  88. if exists(dst):
  89. if clean:
  90. rmtree(dst)
  91. else:
  92. return
  93. copytree(src, dst)
  94. def setup_user_prj(user_dir, prj_path, lib_paths=None):
  95. """
  96. Setup a project with the same directory structure of the mbed online IDE
  97. """
  98. mkdir(user_dir)
  99. # Project Path
  100. copy_tree(prj_path, join(user_dir, "src"))
  101. # Project Libraries
  102. user_lib = join(user_dir, "lib")
  103. mkdir(user_lib)
  104. if lib_paths is not None:
  105. for lib_path in lib_paths:
  106. copy_tree(lib_path, join(user_lib, basename(lib_path)))
  107. def mcu_ide_matrix(verbose_html=False, platform_filter=None):
  108. """ Shows target map using prettytable """
  109. supported_ides = []
  110. for key in EXPORTERS.iterkeys():
  111. supported_ides.append(key)
  112. supported_ides.sort()
  113. from prettytable import PrettyTable, ALL # Only use it in this function so building works without extra modules
  114. # All tests status table print
  115. columns = ["Platform"] + supported_ides
  116. pt = PrettyTable(columns)
  117. # Align table
  118. for col in columns:
  119. pt.align[col] = "c"
  120. pt.align["Platform"] = "l"
  121. perm_counter = 0
  122. target_counter = 0
  123. for target in sorted(TARGET_NAMES):
  124. target_counter += 1
  125. row = [target] # First column is platform name
  126. for ide in supported_ides:
  127. text = "-"
  128. if target in EXPORTERS[ide].TARGETS:
  129. if verbose_html:
  130. text = "&#10003;"
  131. else:
  132. text = "x"
  133. perm_counter += 1
  134. row.append(text)
  135. pt.add_row(row)
  136. pt.border = True
  137. pt.vrules = ALL
  138. pt.hrules = ALL
  139. # creates a html page suitable for a browser
  140. # result = pt.get_html_string(format=True) if verbose_html else pt.get_string()
  141. # creates a html page in a shorter format suitable for readme.md
  142. result = pt.get_html_string() if verbose_html else pt.get_string()
  143. result += "\n"
  144. result += "Total IDEs: %d\n"% (len(supported_ides))
  145. if verbose_html: result += "<br>"
  146. result += "Total platforms: %d\n"% (target_counter)
  147. if verbose_html: result += "<br>"
  148. result += "Total permutations: %d"% (perm_counter)
  149. if verbose_html: result = result.replace("&amp;", "&")
  150. return result