diff --git a/tools/export/__init__.py b/tools/export/__init__.py index 4f7ba95dc8..d419077451 100644 --- a/tools/export/__init__.py +++ b/tools/export/__init__.py @@ -18,7 +18,6 @@ from tools.export import codered, ds5_5, iar, makefile from tools.export import emblocks, coide, kds, simplicityv3, atmelstudio from tools.export import sw4stm32, e2studio, zip, cmsis, uvision, cdt -from tools.export.exporters import OldLibrariesException, FailedBuildException from tools.targets import TARGET_NAMES EXPORTERS = { diff --git a/tools/export/cmsis/__init__.py b/tools/export/cmsis/__init__.py index 48d526ca9e..b953227f5a 100644 --- a/tools/export/cmsis/__init__.py +++ b/tools/export/cmsis/__init__.py @@ -30,7 +30,8 @@ class DeviceCMSIS(): """CMSIS Device class Encapsulates target information retrieved by arm-pack-manager""" - cache = Cache(True, False) + + CACHE = Cache(True, False) def __init__(self, target): target_info = self.check_supported(target) if not target_info: @@ -52,7 +53,7 @@ class DeviceCMSIS(): t = TARGET_MAP[target] try: cpu_name = t.device_name - target_info = DeviceCMSIS.cache.index[cpu_name] + target_info = DeviceCMSIS.CACHE.index[cpu_name] # Target does not have device name or pdsc file except: try: diff --git a/tools/export/exporters.py b/tools/export/exporters.py index ae7ad692eb..439d4697f6 100644 --- a/tools/export/exporters.py +++ b/tools/export/exporters.py @@ -11,16 +11,6 @@ import copy from tools.targets import TARGET_MAP -class OldLibrariesException(Exception): - """Exception that indicates an export can not complete due to an out of date - library version. - """ - pass - -class FailedBuildException(Exception): - """Exception that indicates that a build failed""" - pass - class TargetNotSupportedException(Exception): """Indicates that an IDE does not support a particular MCU""" pass @@ -146,9 +136,31 @@ class Exporter(object): def group_project_files(self, sources): """Group the source files by their encompassing directory Positional Arguments: - sources - array of sourc locations + sources - array of source locations Returns a dictionary of {group name: list of source locations} """ data = sorted(sources, key=self.make_key) return {k: list(g) for k,g in groupby(data, self.make_key)} + + @staticmethod + def build(project_name, log_name='build_log.txt', cleanup=True): + """Invoke exporters build command within a subprocess. + This method is assumed to be executed at the same level as exporter + project files and project source code. + See uvision/__init__.py, iar/__init__.py, and makefile/__init__.py for + example implemenation. + + Positional Arguments: + project_name - the name of the project to build; often required by + exporter's build command. + + Keyword Args: + log_name - name of the build log to create. Written and printed out, + deleted if cleanup = True + cleanup - a boolean dictating whether exported project files and + build log are removed after build + + Returns -1 on failure and 0 on success + """ + raise NotImplemented("Implement in derived Exporter class.") diff --git a/tools/export/iar/__init__.py b/tools/export/iar/__init__.py index 6e63016d30..d9b92db4f3 100644 --- a/tools/export/iar/__init__.py +++ b/tools/export/iar/__init__.py @@ -7,7 +7,7 @@ import re import sys from tools.targets import TARGET_MAP -from tools.export.exporters import Exporter, FailedBuildException +from tools.export.exporters import Exporter import json from tools.export.cmsis import DeviceCMSIS from multiprocessing import cpu_count diff --git a/tools/export/makefile/__init__.py b/tools/export/makefile/__init__.py index 8c342a7b84..cf67940bae 100644 --- a/tools/export/makefile/__init__.py +++ b/tools/export/makefile/__init__.py @@ -108,7 +108,7 @@ class Makefile(Exporter): @staticmethod def build(project_name, log_name="build_log.txt", cleanup=True): """ Build Make project """ - # > Make -C [project directory] -j + # > Make -j cmd = ["make", "-j"] p = Popen(cmd, stdout=PIPE, stderr=PIPE) ret = p.communicate() diff --git a/tools/export/uvision/__init__.py b/tools/export/uvision/__init__.py index ab0cb33b5f..14eedbc637 100644 --- a/tools/export/uvision/__init__.py +++ b/tools/export/uvision/__init__.py @@ -9,7 +9,7 @@ import re from tools.arm_pack_manager import Cache from tools.targets import TARGET_MAP -from tools.export.exporters import Exporter, FailedBuildException +from tools.export.exporters import Exporter from tools.export.cmsis import DeviceCMSIS cache_d = False @@ -207,6 +207,8 @@ class Uvision(Exporter): @staticmethod def build(project_name, log_name='build_log.txt', cleanup=True): + """ Build Uvision project """ + # > UV4.exe -r -j0 -o [log_name] [project_name].uvprojx success = 0 warn = 1 cmd = ["UV4.exe", '-r', '-j0', '-o', log_name, project_name+".uvprojx"]