Skip to content

Commit 02bf3ca

Browse files
committed
Replace small C lib with std C lib if not supported for a given target
1 parent 03dab7f commit 02bf3ca

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

tools/build.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from tools.build_api import print_build_results
4040
from tools.build_api import target_supports_toolchain
4141
from tools.build_api import find_valid_toolchain
42+
from tools.build_api import check_small_c_lib_support
4243
from tools.notifier.term import TerminalNotifier
4344
from tools.utils import argparse_filestring_type, args_error, argparse_many
4445
from tools.utils import argparse_dir_not_parent
@@ -177,6 +178,10 @@ def main():
177178
except NoValidToolchainException as e:
178179
print_end_warnings(e.end_warnings)
179180
args_error(parser, str(e))
181+
182+
warning = check_small_c_lib_swap(target, toolchain_name)
183+
end_warnings += [warning] if warning is not None else []
184+
180185
tt_id = "%s::%s" % (internal_tc_name, target_name)
181186
if not target_supports_toolchain(target, toolchain_name):
182187
# Log this later

tools/build_api.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252

5353
RELEASE_VERSIONS = ['2', '5']
5454

55+
SMALL_C_LIB_CHANGE_WARNING = (
56+
"Warning: We noticed that you are using target.c_lib set to small. "
57+
"As the {} target does not support a small C library for the {} toolchain, we are using the standard C library instead. "
58+
)
59+
5560
def prep_report(report, target_name, toolchain_name, id_name):
5661
"""Setup report keys
5762
@@ -205,6 +210,27 @@ def get_toolchain_name(target, toolchain_name):
205210

206211
return toolchain_name
207212

213+
214+
def check_small_c_lib_support(target, toolchain_name):
215+
"""
216+
Check if the small C lib is supported.
217+
If it is not supported and the standard C library is supported, the later will be used instead.
218+
Return a warning if the standard C lib will be used instead of the small C lib.
219+
"""
220+
if (
221+
hasattr(target, "c_lib")
222+
and target.c_lib.lower() == "small"
223+
and hasattr(target, "supported_c_libs")
224+
and toolchain_name not in target.supported_c_libs
225+
):
226+
if (
227+
"small" not in target.supported_c_libs[toolchain_name]
228+
and "std" in target.supported_c_libs[toolchain_name]
229+
):
230+
return SMALL_C_LIB_CHANGE_WARNING.format(target.name, toolchain_name)
231+
232+
233+
208234
def find_valid_toolchain(target, toolchain):
209235
"""Given a target and toolchain, get the names for the appropriate
210236
toolchain to use. The environment is also checked to see if the corresponding
@@ -250,6 +276,7 @@ def find_valid_toolchain(target, toolchain):
250276
and "uARM" in {toolchain_name, target.default_toolchain}
251277
):
252278
end_warnings.append(UARM_TOOLCHAIN_WARNING)
279+
253280
return toolchain_name, internal_tc_name, end_warnings
254281
else:
255282
if last_error:

tools/toolchains/mbed_toolchain.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,17 @@ def check_c_lib_supported(self, target, toolchain):
11111111
"target.default_lib is no longer supported, please use target.c_lib for C library selection."
11121112
)
11131113
if hasattr(target, "c_lib"):
1114+
11141115
target.c_lib = target.c_lib.lower()
1116+
1117+
if (
1118+
target.c_lib == "small"
1119+
and hasattr(target, "supported_c_libs")
1120+
and "small" not in target.supported_c_libs[toolchain]
1121+
and "std" in target.supported_c_libs[toolchain]
1122+
):
1123+
target.c_lib = "std"
1124+
11151125
if (
11161126
hasattr(target, "supported_c_libs") == False
11171127
or toolchain not in target.supported_c_libs

0 commit comments

Comments
 (0)