Skip to content

Enable build with IAR when c_lib is set to small #12665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

hugueskamba
Copy link
Collaborator

Summary of changes

If "c_lib" is set to "small" and "targets.supported_c_libs.iar" only has "std" it means that it is not possible to build with the IAR toolchain.

This commits modifies the tools to allow building with the IAR toolchain even when "small" is specified by reverting to the standard C library and displaying a message to warn that the standard library is used instead.

Impact of changes

Migration actions required

Documentation


Pull request type

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[X] Tests / results supplied as part of this PR

Reviewers

@evedon @rajkan01


@ciarmcom
Copy link
Member

@hugueskamba, thank you for your changes.
@rajkan01 @evedon @ARMmbed/mbed-os-tools @ARMmbed/mbed-os-maintainers please review.

self.check_c_lib_supported(target, "iar")
# Build with the standard C lib if c_lib is set to small as there
# is no small lib for the IAR toolchain
if target.c_lib.lower() != "small":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If c_lib is set to "small" for IAR, we want to check that "std" is supported and if so revert to using standard.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@hugueskamba hugueskamba force-pushed the hk_iar_enable_c_lib_small_build branch from f4d874d to bc8aeb6 Compare March 21, 2020 00:14
@evedon
Copy link
Contributor

evedon commented Mar 23, 2020

We should make this a generic feature.
If c_lib is set to small :

  • if small is present in supported_c_libs for the used toolchain then use it
  • else use standard

# the value of the c_lib attribute is used to print a warning if std C lib
# ends up being used instead of a small C lib as potentially requested.
target_c_lib_check = copy.copy(target)
if hasattr(target, "c_lib") and target.c_lib == "small":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use getattr() here to simplify this.


if (
toolchain_name == "IAR"
and target.c_lib.lower() == "small"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since c_lib appears to be an optional attribute, need to use getattr() here to ensure that an exception is not thrown when it is not specified.

@hugueskamba hugueskamba force-pushed the hk_iar_enable_c_lib_small_build branch from bc8aeb6 to a9445c9 Compare March 24, 2020 14:19
@mergify mergify bot dismissed mark-edgeworth’s stale review March 24, 2020 14:19

Pull request has been modified.

@@ -205,6 +210,27 @@ def get_toolchain_name(target, toolchain_name):

return toolchain_name


def check_small_c_lib_support(target, toolchain_name):
Copy link
Contributor

@mark-edgeworth mark-edgeworth Mar 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two issues with this function: 1. The 'target' argument is potentially modified inside the function (ie the function has a side-effect that is not easily seen from outside). The name of the function 'check...' implies that it simply checks something. When the function is called, the user does not know that the target arg will be modified (without studying the internals of the function). This kind of thing is really hard to maintain in future. 2. The function mixes up the concepts of checking for some condition, and reporting on that condition. This makes it hard to test (and there are no tests for this). The reporting should be done by the caller IMO.
To fix this: return a boolean to indicate if the check passes or fails. Move the target modification and the error message formation up to the caller. Rename the function (suggest 'is_small_c_lib_supported' or something like that).
It might be that fixing these issues makes this whole function redundant (the code could be in-line since it is only called once anyway.

@@ -52,6 +52,11 @@

RELEASE_VERSIONS = ['2', '5']

SMALL_C_LIB_CHANGE_WARNING = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separating the message format from its arguments doesn't really make sense here. Since this is used only once, at the print, it makes more sense to put the text template there.

tools/build.py Outdated
@@ -177,6 +178,10 @@ def main():
except NoValidToolchainException as e:
print_end_warnings(e.end_warnings)
args_error(parser, str(e))

warning = check_small_c_lib_support(target, toolchain_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider not separating this out into a function - see below.

@hugueskamba hugueskamba force-pushed the hk_iar_enable_c_lib_small_build branch from a9445c9 to 9e2d6c7 Compare March 24, 2020 14:43
@mergify mergify bot dismissed mark-edgeworth’s stale review March 24, 2020 14:43

Pull request has been modified.

@madchutney
Copy link
Contributor

@hugueskamba Please do not force push, it makes it difficult to understand past comments without context.

@hugueskamba hugueskamba force-pushed the hk_iar_enable_c_lib_small_build branch from 9e2d6c7 to e38be3a Compare March 24, 2020 15:13
@hugueskamba hugueskamba force-pushed the hk_iar_enable_c_lib_small_build branch from e38be3a to 02bf3ca Compare March 24, 2020 15:15
Copy link
Contributor

@mark-edgeworth mark-edgeworth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are may existing review comments that have been lost due to force-push. Please look again at the comments and reimplement accordingly.
The tests that were originally here have been removed. Please reinstate.

@hugueskamba
Copy link
Collaborator Author

Closing this as the scope has changed.

@mergify mergify bot removed the needs: work label Mar 24, 2020
@hugueskamba
Copy link
Collaborator Author

hugueskamba commented Mar 24, 2020

The following PR replaces the present PR:
#12691

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants