Skip to content

Commit 3bf7517

Browse files
committed
Apply review comments
1 parent 9b92105 commit 3bf7517

File tree

5 files changed

+35
-29
lines changed

5 files changed

+35
-29
lines changed

tools/build_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
from .libraries import Library
4949
from .toolchains import TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS
5050
from .toolchains.arm import UARM_TOOLCHAIN_WARNING
51-
from .toolchains.mbed_toolchain import is_std_c_lib_supported_instead_small_c_lib
51+
from .toolchains.mbed_toolchain import replace_small_c_lib
5252
from .config import Config
5353

5454
RELEASE_VERSIONS = ['2', '5']
@@ -253,9 +253,9 @@ def find_valid_toolchain(target, toolchain):
253253
):
254254
end_warnings.append(UARM_TOOLCHAIN_WARNING)
255255

256-
if is_std_c_lib_supported_instead_small_c_lib(target, toolchain):
256+
if replace_small_c_lib(target, toolchain, True):
257257
warning = (
258-
"Warning: We noticed that you are using target.c_lib set to small.\n"
258+
"Warning: We noticed that target.c_lib is set to small.\n"
259259
"As the {} target does not support a small C library for the {} toolchain,\n"
260260
"we are using the standard C library instead. "
261261
).format(target.name, toolchain)

tools/toolchains/arm.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from distutils.version import LooseVersion
2828

2929
from tools.toolchains.mbed_toolchain import (
30-
mbedToolchain, TOOLCHAIN_PATHS, is_std_c_lib_supported_instead_small_c_lib
30+
mbedToolchain, TOOLCHAIN_PATHS, replace_small_c_lib
3131
)
3232
from tools.utils import mkdir, NotSupportedException, run_cmd
3333
from tools.resources import FileRef
@@ -74,9 +74,7 @@ def __init__(self, target, notify=None, macros=None,
7474

7575
toolchain = "arm"
7676

77-
if is_std_c_lib_supported_instead_small_c_lib(target, toolchain):
78-
# Replace small C lib with std if there is no small C lib support
79-
target.c_lib = "std"
77+
replace_small_c_lib(target, toolchain)
8078

8179
self.check_c_lib_supported(target, toolchain)
8280

@@ -572,9 +570,7 @@ def __init__(self, target, *args, **kwargs):
572570

573571
toolchain = "arm"
574572

575-
if is_std_c_lib_supported_instead_small_c_lib(target, toolchain):
576-
# Replace small C lib with std if there is no small C lib support
577-
target.c_lib = "std"
573+
replace_small_c_lib(target, toolchain)
578574

579575
self.check_c_lib_supported(target, toolchain)
580576

tools/toolchains/gcc.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from distutils.version import LooseVersion
2424

2525
from tools.toolchains.mbed_toolchain import (
26-
mbedToolchain, TOOLCHAIN_PATHS, is_std_c_lib_supported_instead_small_c_lib
26+
mbedToolchain, TOOLCHAIN_PATHS, replace_small_c_lib
2727
)
2828
from tools.utils import run_cmd
2929

@@ -58,9 +58,7 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
5858
if hasattr(target, "c_lib"):
5959
toolchain = "gcc_arm"
6060

61-
if is_std_c_lib_supported_instead_small_c_lib(target, toolchain):
62-
# Replace small C lib with std if there is no small C lib support
63-
target.c_lib = "std"
61+
replace_small_c_lib(target, toolchain)
6462

6563
self.check_c_lib_supported(target, toolchain)
6664
c_lib = target.c_lib

tools/toolchains/iar.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from distutils.version import LooseVersion
2222

2323
from tools.toolchains.mbed_toolchain import (
24-
mbedToolchain, TOOLCHAIN_PATHS, is_std_c_lib_supported_instead_small_c_lib
24+
mbedToolchain, TOOLCHAIN_PATHS, replace_small_c_lib
2525
)
2626
from tools.utils import run_cmd
2727

@@ -58,9 +58,7 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
5858

5959
toolchain = "iar"
6060

61-
if is_std_c_lib_supported_instead_small_c_lib(target, toolchain):
62-
# Replace small C lib with std if there is no small C lib support
63-
target.c_lib = "std"
61+
replace_small_c_lib(target, toolchain)
6462

6563
self.check_c_lib_supported(target, "iar")
6664

tools/toolchains/mbed_toolchain.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,19 +1394,33 @@ def report(self):
13941394
to_ret.update(self.config.report)
13951395
return to_ret
13961396

1397-
def is_std_c_lib_supported_instead_small_c_lib(target, toolchain):
1397+
def replace_small_c_lib(target, toolchain, check_only=False):
13981398
"""
1399-
Check if the standard C lib should be used instead of the small C lib.
1400-
Return True if the target does not support a small C lib for a given
1401-
toolchain but supports the standard C library instead.
1399+
Replace the small C lib for the standard C lib.
1400+
1401+
The replacement occurs only if the small C lib is not supported but the
1402+
standard C lib is.
1403+
Return True if the replacement occurs otherwise return None.
1404+
"""
1405+
if (
1406+
not is_library_supported("small", target, toolchain)
1407+
and is_library_supported("std", target, toolchain)
1408+
and target.c_lib == "small"
1409+
):
1410+
if not check_only:
1411+
target.c_lib = "std"
1412+
return True
1413+
1414+
1415+
def is_library_supported(lib_type, target, toolchain):
1416+
"""
1417+
Check if a library type is supported by a toolchain for a given target.
1418+
1419+
Return True if the library type is supported, False if not supported, and
1420+
None if the target does not have support the given toolchain.
14021421
"""
14031422
if (
1404-
hasattr(target, "c_lib")
1405-
and target.c_lib.lower() == "small"
1406-
and hasattr(target, "supported_c_libs")
1423+
hasattr(target, "supported_c_libs")
14071424
and toolchain.lower() in target.supported_c_libs
14081425
):
1409-
return (
1410-
"small" not in target.supported_c_libs[toolchain.lower()]
1411-
and "std" in target.supported_c_libs[toolchain.lower()]
1412-
)
1426+
return lib_type in target.supported_c_libs[toolchain.lower()]

0 commit comments

Comments
 (0)