Clone of official tools

Revision:
43:2a7da56ebd24
Parent:
40:7d3fa6b99b2b
--- a/export/mcuxpresso/__init__.py	Mon Nov 06 13:17:14 2017 -0600
+++ b/export/mcuxpresso/__init__.py	Tue Sep 25 13:43:09 2018 -0500
@@ -22,6 +22,8 @@
 Based on GNU ARM Eclipse Exporter from Liviu Ionescu <ilg@livius.net>
 modified for MCUXpresso by Johannes Stratmann <jojos62@online.de>
 """
+from __future__ import print_function, absolute_import
+from builtins import str
 
 import copy
 import tempfile
@@ -39,9 +41,6 @@
 from tools.build_api import prepare_toolchain
 
 
-# =============================================================================
-
-
 POST_BINARY_WHITELIST = set([
     "TEENSY3_1Code.binary_hook",
     "MCU_NRF51Code.binary_hook",
@@ -73,22 +72,17 @@
         if not self.resources.linker_script:
             raise NotSupportedException("No linker script found.")
 
-        print
-        print 'Create a GNU ARM Eclipse C++ managed project'
-        print 'Project name: {0}'.format(self.project_name)
-        print 'Target: {0}'.format(self.toolchain.target.name)
-        print 'Toolchain: {0}'.format(self.TOOLCHAIN)
-
         self.resources.win_to_unix()
 
         # TODO: use some logger to display additional info if verbose
 
-        self.libraries = []
+        libraries = []
         # print 'libraries'
         # print self.resources.libraries
-        for lib in self.resources.libraries:
+        for lib in self.libraries:
             l, _ = splitext(basename(lib))
-            self.libraries.append(l[3:])
+            libraries.append(l[3:])
+        self.libraries = libraries
 
         self.system_libraries = [
             'stdc++', 'supc++', 'm', 'c', 'gcc', 'nosys'
@@ -115,16 +109,13 @@
 
         self.include_path = [
             self.filter_dot(s) for s in self.resources.inc_dirs]
-        print 'Include folders: {0}'.format(len(self.include_path))
 
         self.as_defines = self.toolchain.get_symbols(True)
         self.c_defines = self.toolchain.get_symbols()
         self.cpp_defines = self.c_defines
-        print 'Symbols: {0}'.format(len(self.c_defines))
 
         self.ld_script = self.filter_dot(
             self.resources.linker_script)
-        print 'Linker script: {0}'.format(self.ld_script)
 
         self.options = {}
         profile_ids.remove('develop')
@@ -143,7 +134,6 @@
             opts['name'] = opts['id'].capitalize()
 
             print
-            print 'Build configuration: {0}'.format(opts['name'])
 
             profile = profiles[id]
 
@@ -159,12 +149,6 @@
 
             flags = self.toolchain_flags(toolchain)
 
-            print 'Common flags:', ' '.join(flags['common_flags'])
-            print 'C++ flags:', ' '.join(flags['cxx_flags'])
-            print 'C flags:', ' '.join(flags['c_flags'])
-            print 'ASM flags:', ' '.join(flags['asm_flags'])
-            print 'Linker flags:', ' '.join(flags['ld_flags'])
-
             # Most GNU ARM Eclipse options have a parent,
             # either debug or release.
             if '-O0' in flags['common_flags'] or '-Og' in flags['common_flags']:
@@ -224,10 +208,22 @@
                       '.cproject', trim_blocks=True, lstrip_blocks=True)
         self.gen_file('mcuxpresso/makefile.targets.tmpl', jinja_ctx,
                       'makefile.targets', trim_blocks=True, lstrip_blocks=True)
-        self.gen_file('mcuxpresso/mbedignore.tmpl', jinja_ctx, '.mbedignore')
+        self.gen_file_nonoverwrite('mcuxpresso/mbedignore.tmpl', jinja_ctx,
+                                   '.mbedignore')
+
+        print('Done. Import the \'{0}\' project in MCUXpresso.'.format(
+            self.project_name))
 
-        print
-        print 'Done. Import the \'{0}\' project in Eclipse.'.format(self.project_name)
+    @staticmethod
+    def clean(_):
+        remove('.project')
+        remove('.cproject')
+        if exists('Debug'):
+            shutil.rmtree('Debug')
+        if exists('Release'):
+            shutil.rmtree('Release')
+        if exists('makefile.targets'):
+            remove('makefile.targets')
 
     # override
     @staticmethod
@@ -284,7 +280,7 @@
         else:
             ret_string = "FAILURE: build returned %s \n" % ret_code
 
-        print "%s\n%s\n%s\n%s" % (stdout_string, out, err_string, ret_string)
+        print("%s\n%s\n%s\n%s" % (stdout_string, out, err_string, ret_string))
 
         if log_name:
             # Write the output to the log file
@@ -298,14 +294,7 @@
         if cleanup:
             if exists(log_name):
                 remove(log_name)
-            remove('.project')
-            remove('.cproject')
-            if exists('Debug'):
-                shutil.rmtree('Debug')
-            if exists('Release'):
-                shutil.rmtree('Release')
-            if exists('makefile.targets'):
-                remove('makefile.targets')
+            MCUXpresso.clean(project_name)
 
         # Always remove the temporary folder.
         if exists(tmp_folder):
@@ -341,14 +330,6 @@
         # Make a copy of the flags, to be one by one removed after processing.
         flags = copy.deepcopy(flags_in)
 
-        if False:
-            print
-            print 'common_flags', flags['common_flags']
-            print 'asm_flags', flags['asm_flags']
-            print 'c_flags', flags['c_flags']
-            print 'cxx_flags', flags['cxx_flags']
-            print 'ld_flags', flags['ld_flags']
-
         # Initialise the 'last resort' options where all unrecognised
         # options will be collected.
         opts['as']['other'] = ''
@@ -728,15 +709,3 @@
         opts['c']['other'] = opts['c']['other'].strip()
         opts['cpp']['other'] = opts['cpp']['other'].strip()
         opts['ld']['other'] = opts['ld']['other'].strip()
-
-        if False:
-            print
-            print opts
-
-            print
-            print 'common_flags', flags['common_flags']
-            print 'asm_flags', flags['asm_flags']
-            print 'c_flags', flags['c_flags']
-            print 'cxx_flags', flags['cxx_flags']
-            print 'ld_flags', flags['ld_flags']
-