Merge pull request #2173 from theotherjimmy/abstract-base-class

[toolchains]Abstractify the mbedToolchain base class.
pull/2196/merge
Sam Grove 2016-07-21 22:10:49 -05:00 committed by GitHub
commit b10276cbef
3 changed files with 191 additions and 0 deletions

View File

@ -3,6 +3,7 @@ python:
script:
- PYTHONPATH=. python tools/test/config_test/config_test.py
- py.test tools/test/toolchains/api.py
- python tools/build_travis.py
before_install:
- sudo add-apt-repository -y ppa:terry.guo/gcc-arm-embedded
@ -15,3 +16,4 @@ install:
- sudo pip install colorama
- sudo pip install prettytable
- sudo pip install jinja2
- sudo pip install pytest

View File

@ -0,0 +1,13 @@
import sys
import os
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
sys.path.insert(0, ROOT)
from tools.toolchains import TOOLCHAIN_CLASSES, LEGACY_TOOLCHAIN_NAMES
from tools.targets import TARGET_MAP
def test_instantiation():
for name, Class in TOOLCHAIN_CLASSES.items():
CLS = Class(TARGET_MAP["K64F"])
assert name == CLS.name or name == LEGACY_TOOLCHAIN_NAMES[CLS.name]

View File

@ -26,6 +26,7 @@ from os.path import join, splitext, exists, relpath, dirname, basename, split, a
from inspect import getmro
from copy import deepcopy
from tools.config import Config
from abc import ABCMeta, abstractmethod
from multiprocessing import Pool, cpu_count
from tools.utils import run_cmd, mkdir, rel_path, ToolException, NotSupportedException, split_path, compile_worker
@ -213,6 +214,8 @@ class mbedToolchain:
MBED_CONFIG_FILE_NAME="mbed_config.h"
__metaclass__ = ABCMeta
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
self.target = target
self.name = self.__class__.__name__
@ -825,9 +828,39 @@ class mbedToolchain:
return None
@abstractmethod
def parse_dependencies(self, dep_path):
"""Parse the dependency information generated by the compiler.
Positional arguments:
dep_path -- the path to a file generated by a previous run of the compiler
Return value:
A list of all source files that the dependency file indicated were dependencies
Side effects:
None
"""
raise NotImplemented
def is_not_supported_error(self, output):
return "#error directive: [NOT_SUPPORTED]" in output
@abstractmethod
def parse_output(self, output):
"""Take in compiler output and extract sinlge line warnings and errors from it.
Positional arguments:
output -- a string of all the messages emitted by a run of the compiler
Return value:
None
Side effects:
call self.cc_info or self.notify with a description of the event generated by the compiler
"""
raise NotImplemented
def compile_output(self, output=[]):
_rc = output[0]
_stderr = output[1]
@ -1035,6 +1068,149 @@ class mbedToolchain:
self.config_processed = True
return self.config_file
@abstractmethod
def get_config_option(self, config_header):
"""Generate the compiler option that forces the inclusion of the configuration
header file.
Positional arguments:
config_header -- The configuration header that will be included within all source files
Return value:
A list of the command line arguments that will force the inclusion the specified header
Side effects:
None
"""
raise NotImplemented
@abstractmethod
def assemble(self, source, object, includes):
"""Generate the command line that assembles.
Positional arguments:
source -- a file path that is the file to assemble
object -- a file path that is the destination object
includes -- a list of all directories where header files may be found
Return value:
The complete command line, as a list, that would invoke the assembler
on the source file, include all the include paths, and generate
the specified object file.
Side effects:
None
Note:
This method should be decorated with @hook_tool.
"""
raise NotImplemented
@abstractmethod
def compile_c(self, source, object, includes):
"""Generate the command line that compiles a C source file.
Positional arguments:
source -- the C source file to compile
object -- the destination object file
includes -- a list of all the directories where header files may be found
Return value:
The complete command line, as a list, that would invoke the C compiler
on the source file, include all the include paths, and generate the
specified object file.
Side effects:
None
Note:
This method should be decorated with @hook_tool.
"""
raise NotImplemented
@abstractmethod
def compile_cpp(self, source, object, includes):
"""Generate the command line that compiles a C++ source file.
Positional arguments:
source -- the C++ source file to compile
object -- the destination object file
includes -- a list of all the directories where header files may be found
Return value:
The complete command line, as a list, that would invoke the C++ compiler
on the source file, include all the include paths, and generate the
specified object file.
Side effects:
None
Note:
This method should be decorated with @hook_tool.
"""
raise NotImplemented
@abstractmethod
def link(self, output, objects, libraries, lib_dirs, mem_map):
"""Run the linker to create an executable and memory map.
Positional arguments:
output -- the file name to place the executable in
objects -- all of the object files to link
libraries -- all of the required libraries
lib_dirs -- where the required libraries are located
mem_map -- the location where the memory map file should be stored
Return value:
None
Side effect:
Runs the linker to produce the executable.
Note:
This method should be decorated with @hook_tool.
"""
raise NotImplemented
@abstractmethod
def archive(self, objects, lib_path):
"""Run the command line that creates an archive.
Positional arguhments:
objects -- a list of all the object files that should be archived
lib_path -- the file name of the resulting library file
Return value:
None
Side effect:
Runs the archiving tool to produce the library file.
Note:
This method should be decorated with @hook_tool.
"""
raise NotImplemented
@abstractmethod
def binary(self, resources, elf, bin):
"""Run the command line that will Extract a simplified binary file.
Positional arguments:
resources -- A resources object (Is not used in any of the toolchains)
elf -- the executable file that is to be converted
bin -- the file name of the to be created simplified binary file
Return value:
None
Side effect:
Runs the elf2bin tool to produce the simplified binary file.
Note:
This method should be decorated with @hook_tool.
"""
raise NotImplemented
# Return the list of macros geenrated by the build system
def get_config_macros(self):
return Config.config_to_macros(self.config_data) if self.config_data else []