Correct syntax for mbed export in Py3

pull/6192/head
Jimmy Brisson 2018-02-23 09:57:02 -06:00
parent 59c46001ff
commit 14255ca113
11 changed files with 56 additions and 149 deletions

View File

@ -14,6 +14,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from __future__ import print_function, absolute_import
from builtins import str
import re
import shutil
from os import remove, getcwd, chdir, mkdir
@ -162,7 +165,7 @@ class CMake(Exporter):
else:
out_string += "FAILURE"
print out_string
print(out_string)
if log_name:
# Write the output to the log file

View File

@ -21,6 +21,8 @@ the GNU ARM Eclipse plug-ins.
Author: Liviu Ionescu <ilg@livius.net>
"""
from __future__ import print_function, absolute_import
from builtins import str
import os
import copy
@ -139,8 +141,6 @@ class GNUARMEclipse(Exporter):
# TODO: use some logger to display additional info if verbose
libraries = []
# print 'libraries'
# print self.resources.libraries
for lib in self.resources.libraries:
l, _ = splitext(basename(lib))
libraries.append(l[3:])
@ -158,28 +158,22 @@ class GNUARMEclipse(Exporter):
# TODO: get the list from existing .cproject
build_folders = [s.capitalize() for s in profile_ids]
build_folders.append('BUILD')
# print build_folders
objects = [self.filter_dot(s) for s in self.resources.objects]
for bf in build_folders:
objects = [o for o in objects if not o.startswith(bf + '/')]
# print 'objects'
# print objects
self.compute_exclusions()
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 = {}
for id in profile_ids:
@ -196,8 +190,6 @@ class GNUARMEclipse(Exporter):
opts['id'] = id
opts['name'] = opts['id'].capitalize()
print
print 'Build configuration: {0}'.format(opts['name'])
profile = profiles[id]
@ -215,12 +207,6 @@ class GNUARMEclipse(Exporter):
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']:
@ -281,11 +267,6 @@ class GNUARMEclipse(Exporter):
"""
jinja_ctx = self.create_jinja_ctx()
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.gen_file('gnuarmeclipse/.project.tmpl', jinja_ctx,
'.project', trim_blocks=True, lstrip_blocks=True)
@ -296,8 +277,7 @@ class GNUARMEclipse(Exporter):
self.gen_file_nonoverwrite('gnuarmeclipse/mbedignore.tmpl', jinja_ctx,
'.mbedignore')
print
print 'Done. Import the \'{0}\' project in Eclipse.'.format(self.project_name)
print('Done. Import the \'{0}\' project in Eclipse.'.format(self.project_name))
@staticmethod
def clean(_):
@ -363,7 +343,7 @@ class GNUARMEclipse(Exporter):
if ret_code != 0:
ret_string += "FAILURE\n"
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
@ -397,11 +377,9 @@ class GNUARMEclipse(Exporter):
file_names = [join(tools_path, "profiles", fn) for fn in os.listdir(
join(tools_path, "profiles")) if fn.endswith(".json")]
# print file_names
profile_names = [basename(fn).replace(".json", "")
for fn in file_names]
# print profile_names
profiles = {}
@ -435,7 +413,6 @@ class GNUARMEclipse(Exporter):
src) for src in self.resources.c_sources + self.resources.cpp_sources + self.resources.s_sources)]
self.excluded_folders = set(self.resources.ignored_dirs) - set(self.resources.inc_dirs)
print 'Source folders: {0}, with {1} exclusions'.format(len(source_folders), len(self.excluded_folders))
# -------------------------------------------------------------------------
@ -460,7 +437,6 @@ class GNUARMEclipse(Exporter):
node = nodes[k]
parent_name = node['parent'][
'name'] if 'parent' in node.keys() else ''
print ' ' * depth, node['name'], node['is_used'], parent_name
if len(node['children'].keys()) != 0:
self.dump_tree(node['children'], depth + 1)
@ -474,7 +450,6 @@ class GNUARMEclipse(Exporter):
break
node = node['parent']
path = '/'.join(parts)
print path, nodes[k]['is_used']
self.dump_paths(nodes[k]['children'], depth + 1)
# -------------------------------------------------------------------------
@ -504,14 +479,6 @@ class GNUARMEclipse(Exporter):
# 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'] = ''
@ -944,17 +911,6 @@ class GNUARMEclipse(Exporter):
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']
@staticmethod
def find_options(lst, option):
tmp = [str for str in lst if str.startswith(option)]

View File

@ -1,3 +1,6 @@
from __future__ import print_function, absolute_import
from builtins import str
import os
from os.path import sep, join, exists
from collections import namedtuple
@ -181,7 +184,7 @@ class IAR(Exporter):
else:
out_string += "FAILURE"
print out_string
print(out_string)
if log_name:
# Write the output to the log file

View File

@ -14,6 +14,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from __future__ import print_function, absolute_import
from builtins import str
from os.path import splitext, basename, relpath, join, abspath, dirname,\
exists
from os import remove
@ -178,7 +181,7 @@ class Makefile(Exporter):
else:
out_string += "FAILURE"
print out_string
print(out_string)
if log_name:
# Write the output to the log file

View File

@ -22,6 +22,8 @@ the MCUXpresso IDE from NXP
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.utils import NotSupportedException
from tools.build_api import prepare_toolchain
# =============================================================================
POST_BINARY_WHITELIST = set([
"TEENSY3_1Code.binary_hook",
"MCU_NRF51Code.binary_hook",
@ -73,12 +72,6 @@ class MCUXpresso(GNUARMEclipse):
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
@ -115,16 +108,13 @@ class MCUXpresso(GNUARMEclipse):
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 +133,6 @@ class MCUXpresso(GNUARMEclipse):
opts['name'] = opts['id'].capitalize()
print
print 'Build configuration: {0}'.format(opts['name'])
profile = profiles[id]
@ -159,12 +148,6 @@ class MCUXpresso(GNUARMEclipse):
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']:
@ -227,8 +210,8 @@ class MCUXpresso(GNUARMEclipse):
self.gen_file_nonoverwrite('mcuxpresso/mbedignore.tmpl', jinja_ctx,
'.mbedignore')
print
print 'Done. Import the \'{0}\' project in Eclipse.'.format(self.project_name)
print('Done. Import the \'{0}\' project in MCUXpresso.'.format(
self.project_name))
@staticmethod
def clean(_):
@ -296,7 +279,7 @@ class MCUXpresso(GNUARMEclipse):
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
@ -346,14 +329,6 @@ class MCUXpresso(GNUARMEclipse):
# 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'] = ''
@ -733,15 +708,3 @@ class MCUXpresso(GNUARMEclipse):
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']

View File

@ -1,9 +1,12 @@
from __future__ import print_function, absolute_import
from builtins import str
import os
import copy
import shutil
from os.path import relpath, join, exists, dirname, basename
from os import makedirs
from os import makedirs, remove
from json import load
from tools.export.exporters import Exporter, apply_supported_whitelist
@ -49,7 +52,7 @@ class GNUARMNetbeans(Exporter):
config_header = self.toolchain.get_config_header()
flags = {key + "_flags": copy.deepcopy(value) for key, value
in toolchain.flags.iteritems()}
in toolchain.flags.items()}
if config_header:
config_header = relpath(config_header,
self.resources.file_basepath[config_header])
@ -130,13 +133,8 @@ class GNUARMNetbeans(Exporter):
# Convert all Backslashes to Forward Slashes
self.resources.win_to_unix()
print 'Include folders: {0}'.format(len(self.resources.inc_dirs))
print 'Symbols: {0}'.format(len(self.toolchain.get_symbols()))
self.ld_script = self.filter_dot(
self.resources.linker_script)
print 'Linker script: {0}'.format(self.ld_script)
# Read in all profiles, we'll extract compiler options.
profiles = self.get_all_profiles()
@ -157,9 +155,6 @@ class GNUARMNetbeans(Exporter):
opts['id'] = prof_id
opts['name'] = opts['id'].capitalize()
print
print 'Build configuration: {0}'.format(opts['name'])
profile = profiles[prof_id]
# A small hack, do not bother with src_path again,
@ -172,12 +167,6 @@ class GNUARMNetbeans(Exporter):
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'])
opts['defines'] = self.get_defines_and_remove_from_flags(flags, 'common_flags')
opts['forced_includes'] = self.get_includes_and_remove_from_flags(flags, 'common_flags')
opts['common'] = flags['common_flags']
@ -258,12 +247,6 @@ class GNUARMNetbeans(Exporter):
"""
jinja_ctx = self.create_jinja_ctx()
print
print 'Create a GNU ARM Netbeans 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)
if not exists(join(self.export_dir, 'nbproject')):
makedirs(join(self.export_dir, 'nbproject'))
@ -273,8 +256,7 @@ class GNUARMNetbeans(Exporter):
'.mbedignore')
self.gen_file('nb/Makefile.tmpl', jinja_ctx, 'Makefile')
print
print 'Done. Import the \'{0}\' project in Netbeans.'.format(self.project_name)
print('Done. Import the \'{0}\' project in Netbeans.'.format(self.project_name))
@staticmethod
def clean(_):

View File

@ -14,6 +14,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from __future__ import print_function, absolute_import
from builtins import str
from os.path import splitext, basename, join
import shutil
@ -444,7 +446,6 @@ class Sw4STM32(GNUARMEclipse):
self.c_defines = [s.replace('"', '&quot;')
for s in self.toolchain.get_symbols()]
self.cpp_defines = self.c_defines
print 'Symbols: {0}'.format(len(self.c_defines))
self.include_path = []
for s in self.resources.inc_dirs:
@ -473,9 +474,6 @@ class Sw4STM32(GNUARMEclipse):
opts['id'] = id
opts['name'] = opts['id'].capitalize()
# TODO: Add prints to log or console in verbose mode.
#print ('\nBuild configuration: {0}'.format(opts['name']))
profile = profiles[id]
# A small hack, do not bother with src_path again,
@ -489,13 +487,6 @@ class Sw4STM32(GNUARMEclipse):
flags = self.toolchain_flags(toolchain)
# TODO: Add prints to log or console in verbose mode.
# 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']:

View File

@ -1,3 +1,6 @@
from __future__ import print_function, absolute_import
from builtins import str
import os
from os.path import sep, normpath, join, exists
import ntpath
@ -12,9 +15,6 @@ from tools.targets import TARGET_MAP
from tools.export.exporters import Exporter, apply_supported_whitelist
from tools.export.cmsis import DeviceCMSIS
cache_d = False
class DeviceUvision(DeviceCMSIS):
"""Uvision Device class, inherits CMSIS Device class
@ -189,7 +189,7 @@ class Uvision(Exporter):
grouped = self.group_project_files(srcs)
for group, files in grouped.items():
grouped[group] = sorted(list(self.uv_files(files)),
key=lambda (_, __, name): name.lower())
key=lambda tuple: tuple[2].lower())
return grouped
@staticmethod
@ -205,8 +205,6 @@ class Uvision(Exporter):
def generate(self):
"""Generate the .uvproj file"""
cache = Cache(True, False)
if cache_d:
cache.cache_descriptors()
srcs = self.resources.headers + self.resources.s_sources + \
self.resources.c_sources + self.resources.cpp_sources + \
@ -216,7 +214,7 @@ class Uvision(Exporter):
# project_files => dict of generators - file group to generator of
# UVFile tuples defined above
'project_files': sorted(list(self.format_src(srcs).items()),
key=lambda (group, _): group.lower()),
key=lambda tuple: tuple[0].lower()),
'include_paths': '; '.join(self.resources.inc_dirs).encode('utf-8'),
'device': DeviceUvision(self.target),
}
@ -262,7 +260,7 @@ class Uvision(Exporter):
# Print the log file to stdout
with open(log_name, 'r') as f:
print f.read()
print(f.read())
# Cleanup the exported and built files
if cleanup:

View File

@ -12,6 +12,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function, absolute_import
from builtins import str
from os.path import join, exists, realpath, relpath, basename, isfile, splitext
from os import makedirs, listdir, remove, rmdir
@ -46,7 +49,7 @@ class VSCode(Makefile):
self.gen_file('vscode/%s.tmpl' % file, ctx,
'.vscode/%s.json' % file)
else:
print 'Keeping existing %s.json' % file
print('Keeping existing %s.json' % file)
# So.... I want all .h and .hpp files in self.resources.inc_dirs
all_directories = []

View File

@ -1,7 +1,9 @@
""" The CLI entry point for exporting projects from the mbed tools to any of the
supported IDEs or project structures.
"""
from __future__ import absolute_import, print_function
from __future__ import print_function, absolute_import
from builtins import str
import sys
from os.path import (join, abspath, dirname, exists, basename, normpath,
realpath, relpath, basename)
@ -105,7 +107,7 @@ def main():
targetnames = TARGET_NAMES
targetnames.sort()
toolchainlist = EXPORTERS.keys()
toolchainlist = list(EXPORTERS.keys())
toolchainlist.sort()
parser.add_argument("-m", "--mcu",
@ -259,7 +261,7 @@ def main():
cls.clean(basename(abspath(options.source_dir[0])))
except (NotImplementedError, IOError, OSError):
pass
for f in EXPORTERS.values()[0].CLEAN_FILES:
for f in list(EXPORTERS.values())[0].CLEAN_FILES:
try:
remove(f)
except (IOError, OSError):

View File

@ -14,6 +14,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from __future__ import print_function, absolute_import
from builtins import str
import re
from copy import copy
from os.path import join, dirname, splitext, basename, exists, relpath
@ -196,7 +199,7 @@ class ARM(mbedToolchain):
Side Effects:
This method MAY write a new scatter file to disk
"""
with open(scatter_file, "rb") as input:
with open(scatter_file, "r") as input:
lines = input.readlines()
if (lines[0].startswith(self.SHEBANG) or
not lines[0].startswith("#!")):
@ -206,7 +209,7 @@ class ARM(mbedToolchain):
self.SHEBANG += " -I %s" % relpath(dirname(scatter_file),
base_path)
if self.need_update(new_scatter, [scatter_file]):
with open(new_scatter, "wb") as out:
with open(new_scatter, "w") as out:
out.write(self.SHEBANG)
out.write("\n")
out.write("".join(lines[1:]))