2013-08-06 13:38:00 +00:00
|
|
|
"""
|
|
|
|
mbed SDK
|
2016-07-26 20:30:59 +00:00
|
|
|
Copyright (c) 2011-2016 ARM Limited
|
2013-08-06 13:38:00 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
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.
|
|
|
|
"""
|
2015-03-05 14:58:24 +00:00
|
|
|
import re
|
2015-03-25 12:03:50 +00:00
|
|
|
import os
|
2016-02-22 20:43:35 +00:00
|
|
|
from project_generator_definitions.definitions import ProGenDef
|
|
|
|
|
2016-07-18 14:09:07 +00:00
|
|
|
from tools.export.exporters import Exporter, ExporterTargetsProperty
|
2016-06-09 20:34:53 +00:00
|
|
|
from tools.targets import TARGET_MAP, TARGET_NAMES
|
2016-02-20 21:56:27 +00:00
|
|
|
|
2016-02-22 21:04:53 +00:00
|
|
|
# If you wish to add a new target, add it to project_generator_definitions, and then
|
|
|
|
# define progen_target name in the target class (`` self.progen_target = 'my_target_name' ``)
|
2013-02-18 15:32:11 +00:00
|
|
|
class IAREmbeddedWorkbench(Exporter):
|
2015-03-25 13:43:06 +00:00
|
|
|
"""
|
2016-02-22 21:04:53 +00:00
|
|
|
Exporter class for IAR Systems. This class uses project generator.
|
2015-03-25 13:43:06 +00:00
|
|
|
"""
|
2016-02-22 21:04:53 +00:00
|
|
|
# These 2 are currently for exporters backward compatiblity
|
2016-07-20 19:43:09 +00:00
|
|
|
NAME = 'iar_arm'
|
2013-02-18 15:32:11 +00:00
|
|
|
TOOLCHAIN = 'IAR'
|
2016-02-22 21:04:53 +00:00
|
|
|
# PROGEN_ACTIVE contains information for exporter scripts that this is using progen
|
2016-02-20 21:56:27 +00:00
|
|
|
PROGEN_ACTIVE = True
|
2014-05-29 13:42:03 +00:00
|
|
|
|
2016-06-27 15:40:32 +00:00
|
|
|
MBED_CONFIG_HEADER_SUPPORTED = True
|
2016-06-20 19:28:55 +00:00
|
|
|
|
2016-07-18 14:09:07 +00:00
|
|
|
@ExporterTargetsProperty
|
|
|
|
def TARGETS(cls):
|
|
|
|
if not hasattr(cls, "_targets_supported"):
|
|
|
|
cls._targets_supported = []
|
2016-07-21 08:41:38 +00:00
|
|
|
progendef = ProGenDef('iar')
|
2016-07-15 12:37:50 +00:00
|
|
|
for target in TARGET_NAMES:
|
|
|
|
try:
|
2016-07-21 08:41:38 +00:00
|
|
|
if (progendef.is_supported(str(TARGET_MAP[target])) or
|
|
|
|
progendef.is_supported(TARGET_MAP[target].progen['target'])):
|
2016-07-18 14:09:07 +00:00
|
|
|
cls._targets_supported.append(target)
|
2016-07-15 12:37:50 +00:00
|
|
|
except AttributeError:
|
|
|
|
# target is not supported yet
|
|
|
|
continue
|
2016-07-18 14:09:07 +00:00
|
|
|
return cls._targets_supported
|
2016-02-22 20:43:35 +00:00
|
|
|
|
2016-07-20 19:43:09 +00:00
|
|
|
def generate(self):
|
2016-02-20 21:56:27 +00:00
|
|
|
""" Generates the project files """
|
|
|
|
project_data = self.progen_get_project_data()
|
2016-02-25 14:02:08 +00:00
|
|
|
try:
|
|
|
|
if TARGET_MAP[self.target].progen['iar']['template']:
|
2016-07-20 19:43:09 +00:00
|
|
|
project_data['template']=TARGET_MAP[self.target].progen['iar']['template']
|
2016-02-25 14:02:08 +00:00
|
|
|
except KeyError:
|
|
|
|
# use default template
|
|
|
|
# by the mbed projects
|
2016-07-20 19:43:09 +00:00
|
|
|
project_data['template']=[os.path.join(os.path.dirname(__file__), 'iar_template.ewp.tmpl')]
|
2016-02-25 14:02:08 +00:00
|
|
|
|
2016-07-20 19:43:09 +00:00
|
|
|
project_data['misc'] = self.flags
|
2016-06-28 15:15:48 +00:00
|
|
|
# VLA is enabled via template IccAllowVLA
|
2016-07-20 19:43:09 +00:00
|
|
|
project_data['misc']['c_flags'].remove("--vla")
|
|
|
|
project_data['misc']['asm_flags'] = list(set(project_data['misc']['asm_flags']))
|
|
|
|
project_data['build_dir'] = os.path.join(project_data['build_dir'], 'iar_arm')
|
|
|
|
self.progen_gen_file(project_data)
|
2015-03-05 14:58:24 +00:00
|
|
|
|
2016-02-20 21:56:27 +00:00
|
|
|
# Currently not used, we should reuse folder_name to create virtual folders
|
2015-03-25 13:43:06 +00:00
|
|
|
class IarFolder():
|
|
|
|
"""
|
|
|
|
This is a recursive folder object.
|
|
|
|
To present the folder structure in the IDE as it is presented on the disk.
|
|
|
|
This can be used for uvision as well if you replace the __str__ method.
|
|
|
|
Example:
|
|
|
|
files: ./main.cpp, ./apis/I2C.h, ./mbed/common/I2C.cpp
|
|
|
|
in the project this would look like:
|
|
|
|
main.cpp
|
|
|
|
common/I2C.cpp
|
|
|
|
input:
|
|
|
|
folder_level : folder path to current folder
|
|
|
|
folder_name : name of current folder
|
|
|
|
source_files : list of source_files (all must be in same directory)
|
|
|
|
"""
|
2015-03-05 14:58:24 +00:00
|
|
|
def __init__(self, folder_level, folder_name, source_files):
|
|
|
|
self.folder_level = folder_level
|
|
|
|
self.folder_name = folder_name
|
|
|
|
self.source_files = source_files
|
2015-03-25 13:43:06 +00:00
|
|
|
self.sub_folders = {}
|
|
|
|
|
2015-03-05 14:58:24 +00:00
|
|
|
def __str__(self):
|
2015-03-25 13:43:06 +00:00
|
|
|
"""
|
|
|
|
converts the folder structue to IAR project format.
|
|
|
|
"""
|
2015-03-05 14:58:24 +00:00
|
|
|
group_start = ""
|
|
|
|
group_end = ""
|
|
|
|
if self.folder_name != "":
|
|
|
|
group_start = "<group>\n<name>%s</name>\n" %(self.folder_name)
|
|
|
|
group_end = "</group>\n"
|
|
|
|
|
|
|
|
str_content = group_start
|
|
|
|
#Add files in current folder
|
|
|
|
if self.source_files:
|
|
|
|
for src in self.source_files:
|
2015-03-25 12:03:50 +00:00
|
|
|
str_content += "<file>\n<name>$PROJ_DIR$/%s</name>\n</file>\n" % src
|
2015-03-25 13:43:06 +00:00
|
|
|
#Add sub folders
|
2015-03-05 14:58:24 +00:00
|
|
|
if self.sub_folders:
|
|
|
|
for folder_name in self.sub_folders.iterkeys():
|
|
|
|
str_content += self.sub_folders[folder_name].__str__()
|
2015-03-25 13:43:06 +00:00
|
|
|
|
2015-03-05 14:58:24 +00:00
|
|
|
str_content += group_end
|
|
|
|
return str_content
|
2015-03-25 13:43:06 +00:00
|
|
|
|
2015-03-05 14:58:24 +00:00
|
|
|
def insert_file(self, source_input):
|
2015-03-25 13:43:06 +00:00
|
|
|
"""
|
|
|
|
Inserts a source file into the folder tree
|
|
|
|
"""
|
|
|
|
if self.source_files:
|
|
|
|
#All source_files in a IarFolder must be in same directory.
|
|
|
|
dir_sources = IarFolder.get_directory(self.source_files[0])
|
|
|
|
#Check if sources are already at their deepest level.
|
|
|
|
if not self.folder_level == dir_sources:
|
2015-03-05 14:58:24 +00:00
|
|
|
_reg_exp = r"^" + re.escape(self.folder_level) + r"[/\\]?([^/\\]+)"
|
2015-03-25 13:43:06 +00:00
|
|
|
folder_name = re.match(_reg_exp, dir_sources).group(1)
|
|
|
|
self.sub_folders[folder_name] = IarFolder(os.path.join(self.folder_level, folder_name), folder_name, self.source_files)
|
2015-03-05 14:58:24 +00:00
|
|
|
self.source_files = []
|
2015-03-25 13:43:06 +00:00
|
|
|
|
|
|
|
dir_input = IarFolder.get_directory(source_input)
|
2015-03-05 14:58:24 +00:00
|
|
|
if dir_input == self.folder_level:
|
|
|
|
self.source_files.append(source_input)
|
|
|
|
else:
|
|
|
|
_reg_exp = r"^" + re.escape(self.folder_level) + r"[/\\]?([^/\\]+)"
|
2015-03-25 13:43:06 +00:00
|
|
|
folder_name = re.match(_reg_exp, dir_input).group(1)
|
2015-03-05 14:58:24 +00:00
|
|
|
if self.sub_folders.has_key(folder_name):
|
|
|
|
self.sub_folders[folder_name].insert_file(source_input)
|
|
|
|
else:
|
2015-03-25 13:43:06 +00:00
|
|
|
if self.folder_level == "":
|
|
|
|
#Top level exception
|
|
|
|
self.sub_folders[folder_name] = IarFolder(folder_name, folder_name, [source_input])
|
2015-03-05 14:58:24 +00:00
|
|
|
else:
|
2015-03-25 13:43:06 +00:00
|
|
|
self.sub_folders[folder_name] = IarFolder(os.path.join(self.folder_level, folder_name), folder_name, [source_input])
|
2015-03-05 14:58:24 +00:00
|
|
|
|
2015-03-25 13:43:06 +00:00
|
|
|
@staticmethod
|
2015-03-05 14:58:24 +00:00
|
|
|
def get_directory(file_path):
|
2015-03-25 13:43:06 +00:00
|
|
|
"""
|
|
|
|
Returns the directory of the file
|
|
|
|
"""
|
2015-03-25 12:03:50 +00:00
|
|
|
return os.path.dirname(file_path)
|