Skip to content

Commit c7bc655

Browse files
theotherjimmy0xc0170
authored andcommitted
Format and document libraries.py
1 parent d25230f commit c7bc655

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

tools/libraries.py

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17-
from tools.paths import *
18-
from tools.data.support import *
17+
from tools.paths import MBED_RTX, RTOS_LIBRARIES, MBED_LIBRARIES, MBED_RPC,\
18+
RTOS_ABSTRACTION, RPC_LIBRARY, USB, USB_LIBRARIES, USB_HOST,\
19+
USB_HOST_LIBRARIES, FAT_FS, DSP_ABSTRACTION, DSP_CMSIS, DSP_LIBRARIES,\
20+
SD_FS, FS_LIBRARY, ETH_SOURCES, LWIP_SOURCES, ETH_LIBRARY, UBLOX_SOURCES,\
21+
UBLOX_LIBRARY, CELLULAR_SOURCES, CELLULAR_USB_SOURCES, CPPUTEST_SRC,\
22+
CPPUTEST_PLATFORM_SRC, CPPUTEST_TESTRUNNER_SCR, CPPUTEST_LIBRARY,\
23+
CPPUTEST_INC, CPPUTEST_PLATFORM_INC, CPPUTEST_TESTRUNNER_INC,\
24+
CPPUTEST_INC_EXT
25+
from tools.data.support import DEFAULT_SUPPORT
1926
from tools.tests import TEST_MBED_LIB
2027

2128

@@ -84,40 +91,55 @@
8491

8592
{
8693
"id": "ublox",
87-
"source_dir": [UBLOX_SOURCES, CELLULAR_SOURCES, CELLULAR_USB_SOURCES, LWIP_SOURCES],
94+
"source_dir": [UBLOX_SOURCES, CELLULAR_SOURCES, CELLULAR_USB_SOURCES,
95+
LWIP_SOURCES],
8896
"build_dir": UBLOX_LIBRARY,
8997
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, USB_HOST_LIBRARIES],
9098
},
9199

92100
# Unit Testing library
93101
{
94102
"id": "cpputest",
95-
"source_dir": [CPPUTEST_SRC, CPPUTEST_PLATFORM_SRC, CPPUTEST_TESTRUNNER_SCR],
103+
"source_dir": [CPPUTEST_SRC, CPPUTEST_PLATFORM_SRC,
104+
CPPUTEST_TESTRUNNER_SCR],
96105
"build_dir": CPPUTEST_LIBRARY,
97106
"dependencies": [MBED_LIBRARIES],
98-
'inc_dirs': [CPPUTEST_INC, CPPUTEST_PLATFORM_INC, CPPUTEST_TESTRUNNER_INC, TEST_MBED_LIB],
107+
'inc_dirs': [CPPUTEST_INC, CPPUTEST_PLATFORM_INC,
108+
CPPUTEST_TESTRUNNER_INC, TEST_MBED_LIB],
99109
'inc_dirs_ext': [CPPUTEST_INC_EXT],
100-
'macros': ["CPPUTEST_USE_MEM_LEAK_DETECTION=0", "CPPUTEST_USE_STD_CPP_LIB=0", "CPPUTEST=1"],
110+
'macros': ["CPPUTEST_USE_MEM_LEAK_DETECTION=0",
111+
"CPPUTEST_USE_STD_CPP_LIB=0", "CPPUTEST=1"],
101112
},
102113
]
103114

104115

105116
LIBRARY_MAP = dict([(library['id'], library) for library in LIBRARIES])
106117

107118

108-
class Library:
109-
DEFAULTS = {
110-
"supported": DEFAULT_SUPPORT,
111-
'dependencies': None,
112-
'inc_dirs': None, # Include dirs required by library build
113-
'inc_dirs_ext': None, # Include dirs required by others to use with this library
114-
'macros': None, # Additional macros you want to define when building library
115-
}
119+
class Library(object):
120+
"""A library representation that allows for querying of support"""
116121
def __init__(self, lib_id):
117-
self.__dict__.update(Library.DEFAULTS)
118-
self.__dict__.update(LIBRARY_MAP[lib_id])
122+
lib = LIBRARY_MAP[lib_id]
123+
self.supported = lib.get("supported", DEFAULT_SUPPORT)
124+
self.dependencies = lib.get("dependencies", None)
125+
# Include dirs required by library build
126+
self.inc_dirs = lib.get("inc_dirs", None)
127+
# Include dirs required by others to use with this library
128+
self.inc_dirs_ext = lib.get("inc_dirs_ext", None)
129+
# Additional macros you want to define when building library
130+
self.macros = lib.get("macros", None)
131+
132+
self.source_dir = lib["source_dir"]
133+
self.build_dir = lib["build_dir"]
119134

120135
def is_supported(self, target, toolchain):
136+
"""Check if a target toolchain combination is supported
137+
138+
Positional arguments:
139+
target - the MCU or board
140+
toolchain - the compiler
141+
"""
121142
if not hasattr(self, 'supported'):
122143
return True
123-
return (target.name in self.supported) and (toolchain in self.supported[target.name])
144+
return (target.name in self.supported) and \
145+
(toolchain in self.supported[target.name])

0 commit comments

Comments
 (0)