Skip to content

Commit bc8aeb6

Browse files
committed
Enable build with IAR when c_lib is set to small
1 parent 03dab7f commit bc8aeb6

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

tools/build_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +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.iar import IAR_SMALL_LIB_WARNING
5152
from .config import Config
5253

5354
RELEASE_VERSIONS = ['2', '5']
@@ -250,6 +251,13 @@ def find_valid_toolchain(target, toolchain):
250251
and "uARM" in {toolchain_name, target.default_toolchain}
251252
):
252253
end_warnings.append(UARM_TOOLCHAIN_WARNING)
254+
255+
if (
256+
toolchain_name == "IAR"
257+
and target.c_lib.lower() == "small"
258+
):
259+
end_warnings.append(IAR_SMALL_LIB_WARNING)
260+
253261
return toolchain_name, internal_tc_name, end_warnings
254262
else:
255263
if last_error:

tools/test/toolchains/test_toolchains.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,16 @@ def test_iar_c_lib_std_exception(self):
209209
with self.assertRaisesRegexp(NotSupportedException, UNSUPPORTED_C_LIB_EXCEPTION_STRING.format(mock_target.c_lib)):
210210
IAR(mock_target)
211211

212-
def test_iar_c_lib_small_exception(self):
213-
"""Test that an exception is raised if the small C library is not supported for a target on the IAR toolchain."""
212+
def test_iar_c_lib_small(self):
213+
"""Test that no exception is raised if the small C library is used with the IAR toolchain."""
214214
mock_target = mock.MagicMock()
215215
mock_target.core = "Cortex-M4"
216216
mock_target.c_lib = "small"
217217
del mock_target.default_lib
218218
mock_target.supported_c_libs = {"iar": ["std"]}
219219
mock_target.supported_toolchains = ["IAR"]
220-
with self.assertRaisesRegexp(NotSupportedException, UNSUPPORTED_C_LIB_EXCEPTION_STRING.format(mock_target.c_lib)):
220+
mock_target.is_TrustZone_secure_target = False
221+
try:
221222
IAR(mock_target)
223+
except NotSupportedException:
224+
self.fail(UNSUPPORTED_C_LIB_EXCEPTION_STRING.format(mock_target.c_lib))

tools/toolchains/iar.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
See the License for the specific language governing permissions and
1616
limitations under the License.
1717
"""
18+
import copy
1819
import re
1920
from os import remove
2021
from os.path import join, splitext, exists
@@ -23,6 +24,12 @@
2324
from tools.toolchains.mbed_toolchain import mbedToolchain, TOOLCHAIN_PATHS
2425
from tools.utils import run_cmd
2526

27+
28+
IAR_SMALL_LIB_WARNING = (
29+
"Warning: We noticed that you are using IAR toolchain with target.c_lib set to small. "
30+
"As there is no small C library for the IAR toolchain, we are using the standard C library instead. "
31+
)
32+
2633
class IAR(mbedToolchain):
2734
OFFICIALLY_SUPPORTED = True
2835
LIBRARY_EXT = '.a'
@@ -54,7 +61,16 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
5461
build_profile=build_profile
5562
)
5663

57-
self.check_c_lib_supported(target, "iar")
64+
# Copy the object as we do not want to modify the object received since
65+
# the value of the c_lib attribute is used to print a warning if std C lib
66+
# ends up being used instead of a small C lib as potentially requested.
67+
target_c_lib_check = copy.copy(target)
68+
if hasattr(target, "c_lib") and target.c_lib == "small":
69+
# Build with the std C lib (if supported) as there
70+
# is no small C lib for the IAR toolchain
71+
target_c_lib_check.c_lib = "std"
72+
73+
self.check_c_lib_supported(target_c_lib_check, "iar")
5874

5975
if target.is_TrustZone_secure_target:
6076
# Enable compiler security extensions

0 commit comments

Comments
 (0)