Skip to content

Commit 17833e8

Browse files
committed
Abstractify the mbedToolchain base class
The mbedToolchain class calls many members of it's subclasses, expecting them to implement a particular API. This change adds a requirement to each subclass that requires them to implement this expected API. The API consists of these methods: - parse_dependencies - parse_ouptut - get_config_option - compile_c - compile_cpp - link - archive - binary
1 parent d0d023a commit 17833e8

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

tools/toolchains/__init__.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from inspect import getmro
2727
from copy import deepcopy
2828
from tools.config import Config
29+
from abc import ABCMeta, abstractmethod
2930

3031
from multiprocessing import Pool, cpu_count
3132
from tools.utils import run_cmd, mkdir, rel_path, ToolException, NotSupportedException, split_path
@@ -230,6 +231,8 @@ class mbedToolchain:
230231

231232
MBED_CONFIG_FILE_NAME="mbed_config.h"
232233

234+
__metaclass__ = ABCMeta
235+
233236
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
234237
self.target = target
235238
self.name = self.__class__.__name__
@@ -784,9 +787,22 @@ def compile_command(self, source, object, includes):
784787

785788
return None
786789

790+
@abstractmethod
791+
def parse_dependencies(self, dep_path):
792+
"""Take in a dependency file generated by the compiler and build a list of
793+
all files that the dep_path depends on.
794+
"""
795+
pass
796+
787797
def is_not_supported_error(self, output):
788798
return "#error directive: [NOT_SUPPORTED]" in output
789799

800+
@abstractmethod
801+
def parse_output(self, output):
802+
"""Take in compiler output and extract sinlge line warnings and errors from it
803+
"""
804+
pass
805+
790806
def compile_output(self, output=[]):
791807
_rc = output[0]
792808
_stderr = output[1]
@@ -958,6 +974,63 @@ def get_config_header(self):
958974
f.write(Config.config_to_header(self.config_data))
959975
return config_file
960976

977+
@abstractmethod
978+
def get_config_option(self, config_header):
979+
"""Generate the compiler option that forces the inclusion of the configuration
980+
header file.
981+
"""
982+
pass
983+
984+
@abstractmethod
985+
def assemble(self, source, object, includes):
986+
"""Generate the command line that:
987+
- Assembles the given assembly *source* file.
988+
- Puts the results into the file named *object*.
989+
- Has an include search path that includes everything in *includes*
990+
"""
991+
pass
992+
993+
@abstractmethod
994+
def compile_c(self, source, object, includes):
995+
"""Generate the command line that:
996+
- Compiles the given C *source* file.
997+
- Puts the results into the file named *object*.
998+
- Has an include search path that includes everything in *includes*
999+
"""
1000+
pass
1001+
1002+
@abstractmethod
1003+
def compile_cpp(self, source, object, includes):
1004+
"""Generate the command line that:
1005+
- Compiles the given C++ *source* file.
1006+
- Puts the results into the file named *object*.
1007+
- Has an include search path that includes everything in *includes*
1008+
"""
1009+
pass
1010+
1011+
@abstractmethod
1012+
def link(self, output, objects, libraries, lib_dirs, mem_map):
1013+
"""Run the link command that will:
1014+
- Emit a file named *output*
1015+
- Includes all *objects* and *libraries*
1016+
- Searches for libraries in *lib_dirs*
1017+
- Generates a memory map file in the file *mem_map*
1018+
"""
1019+
pass
1020+
1021+
@abstractmethod
1022+
def archive(self, objects, lib_path):
1023+
"""Run the command line that creates an archive containing *objects*, and named *lib_path*
1024+
"""
1025+
pass
1026+
1027+
@abstractmethod
1028+
def binary(self, resources, elf, bin):
1029+
"""Run the command line that will Extract a binary named *bin* from an
1030+
elf file named *elf*.
1031+
"""
1032+
pass
1033+
9611034
# Return the list of macros geenrated by the build system
9621035
def get_config_macros(self):
9631036
return Config.config_to_macros(self.config_data) if self.config_data else []

0 commit comments

Comments
 (0)