Skip to content

Readable error when toolchain paths not set. Allow IAR and ARM toolchains to be set in user's PATH. #2418

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

Merged
merged 3 commits into from
Aug 26, 2016

Conversation

sarahmarshy
Copy link
Contributor

@sarahmarshy sarahmarshy commented Aug 10, 2016

Fixes #2360.

New error:
[ERROR] Could not find executable for IAR.
Currently set search path: /default/path/that/doesnt/exist
(System exit before any build system calls)

@theotherjimmy @0xc0170 @bridadan

Fixes ARMmbed#2360.

New error:
[Error] Toolchain path does not exist for IAR.
Current value: /default/path/that/doesnt/exist
(System exit before any build system calls)
@theotherjimmy
Copy link
Contributor

Can we exit with non-zero? It's an error after all.

@theotherjimmy
Copy link
Contributor

After exiting non-zero, LGTM.

if not exists(self.toolchain_path):
print('[ERROR] Toolchain path for %s does not exist.\n'
'Current value: %s' % (self.name, self.toolchain_path))
sys.exit(-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have any documentation about exit codes like this? would be useful in some cases if all possible exit codes are well known&documented..

Copy link
Contributor

Choose a reason for hiding this comment

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

@jupe I don't think anyone has looked at standardizing the return codes across the tools yet, that needs to be revisited in another PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, we return 2 on all argument errors after #2393 gets merged.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well that's a step in the right direction! I guess my point was we haven't specified a full list of return codes for the tools yet. I think it make sense to look at that collectively across all scripts and make that change in one PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, and we should add it to the documentation somewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we open an issue, so we don't forget?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thats good starting point 👍 . Somebody should look about existing return codes, standardize all of them and prepare proper documentation..

@bridadan
Copy link
Contributor

Copying this over from #2416 (@sarahmarshy can this PR just be updated from now on instead of moving it?)

@sarahmarshy It does exit gracefully with an error, but I think we typically try to stay away from calling exit within API functions (like toolchains or build_api). Usually I think we try to return error codes or throw exceptions in API functions and then let the top level CLI script that's calling them handle the exception and exit. Thoughts on this @theotherjimmy ?

@mazimkhan You're right I think this might cause issues with GCC_ARM because the toolchains can find it in the system PATH. I think this is only for GCC_ARM though unfortunately :/ @sarahmarshy sounds like another corner case.

@theotherjimmy
Copy link
Contributor

@sarahmarshy It does exit gracefully with an error, but I think we typically try to stay away from calling exit within API functions (like toolchains or build_api). Usually I think we try to return error codes or throw exceptions in API functions and then let the top level CLI script that's calling them handle the exception and exit. Thoughts on this @theotherjimmy ?

I agree, the toolchains should just throw an exception. This helps out with online build system compatibly.

@mazimkhan You're right I think this might cause issues with GCC_ARM because the toolchains can find it in the system PATH. I think this is only for GCC_ARM though unfortunately :/ @sarahmarshy sounds like another corner case.

I can set the ARM_PATH to '' and force it to find the armcc executable in my path (I might already do that...). This removes that use case.

@bridadan
Copy link
Contributor

I can set the ARM_PATH to '' and force it to find the armcc executable in my path (I might already do that...). This removes that use case.

Not sure exactly what you mean @theotherjimmy ?

@theotherjimmy
Copy link
Contributor

theotherjimmy commented Aug 10, 2016

Setting the path to '' would force the subprocess.Popen to search the $PATH for the executable. It's something I'll work around when this PR gets merged. It's NBD.

@bridadan
Copy link
Contributor

Does it do this for all toolchains now? Including IAR? It was my impression that this only worked for GCC_ARM

@sarahmarshy
Copy link
Contributor Author

@bridadan yes, we can just update this. I think it is at the point where I can make commits instead of new branches to implement the changes listed. Let me look into checking $PATH if the set path is empty.

@theotherjimmy
Copy link
Contributor

Instead of branches and duplicate PR's, you could force push to overwrite the old branch.

@sarahmarshy
Copy link
Contributor Author

But that would cause a lot of the conversation to look out of context for posterity,

@theotherjimmy
Copy link
Contributor

I think it would show all of the related conversation in the same thread, which might be preferred. This is off topic, if you want to continue this discussion we should do it 'offline'.

@sarahmarshy
Copy link
Contributor Author

Back to on topic: looks like https://docs.python.org/dev/library/shutil.html#shutil.which would be a good solution for executables in the path that aren't assigned an environment variable. It is only supported in python 3.3, but I will try to find a 2.7 alternative.

@bridadan
Copy link
Contributor

@sarahmarshy I did an implementation of this here: https://github.com/ARMmbed/mbed-os/pull/2057/files#diff-1832807e55f923dee42eee74919441faR69

The PR itself wasn't ready to merge but there might be some code there you can salvage!

@sarahmarshy
Copy link
Contributor Author

@bridadan
Copy link
Contributor

I remember looking at that function and kind of straying away from it due to some of the comments in this Stack Overflow post: http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python

But I never actually tried it, so it may be just fine!

@sarahmarshy
Copy link
Contributor Author

It is working alright in gcc, it is also working for arm, but there are issues with arm because we manually append the bin path like:
ARM_BIN = join(TOOLCHAIN_PATHS['ARM'], "bin")
which is used:

main_cc = join(ARM_BIN, "armcc")

so, if you leave the path blank the command becomes: bin\armcc

I could modify this to have different behavior when the path is blank.

@theotherjimmy

I can set the ARM_PATH to '' and force it to find the armcc executable in my path (I might already do that...)

Are you sure you do that? Can you check? I am not able to do this successfully.

@theotherjimmy
Copy link
Contributor

theotherjimmy commented Aug 10, 2016

I can check tomorrow. Right now I don't have armc5 installed. But, I don't consider it blocking.

@sarahmarshy sarahmarshy changed the title Readable error when toolchain paths not set. Readable error when toolchain paths not set. Allow IAR and ARM to be set in user's path. Aug 10, 2016
@sarahmarshy sarahmarshy changed the title Readable error when toolchain paths not set. Allow IAR and ARM to be set in user's path. Readable error when toolchain paths not set. Allow IAR and ARM toolchains to be set in user's PATH. Aug 10, 2016
print('[ERROR] Could not find executable for %s.\n'
'Currently set search path: %s'
% (self.name, self.toolchain_path))
sys.exit(-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we come to a decision about calling exit within toolchains? I'd still vote no on this and throw an exception instead

"""
def perform_check(self, *args, **kwargs):
if not exists(self.toolchain_path):
print('[ERROR] Could not find executable for %s.\n'
Copy link
Contributor

@bridadan bridadan Aug 10, 2016

Choose a reason for hiding this comment

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

If you move this message into the exception you raise below, it will be passed to anything that catches it, which can then print it or ignore.

raise Exception("[ERROR] Could not find executable...")

@screamerbg
Copy link
Contributor

+1 on the idea (haven't reviewed the whole implementation yet)

@bridadan
Copy link
Contributor

@sg- I'm not sure why ARM and IAR have to know the paths to the bin and the include stuff separately? Aren't they aware of these paths themselves? Or is this needed for ulib support for ARM?

@sarahmarshy
Copy link
Contributor Author

sarahmarshy commented Aug 16, 2016

@sg- This implementation uses a decorator for the compile, build, and link functions. It will check whatever would be used as the path to the command. Assuming that config makes its way to TOOLCHAIN_PATHS in settings.py (the variable used in the toolchains to get those paths), then it should be checked.

I can try to look into why we need those includes separately.

Raise exceptin instead of exit.
Corrected error for arm-none-eabi-gcc/g++ set in path.
@@ -56,6 +56,11 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
else:
cpu = target.core

if not TOOLCHAIN_PATHS['ARM']:
exe = find_executable('armcc')
if exe:
Copy link

@mazimkhan mazimkhan Aug 19, 2016

Choose a reason for hiding this comment

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

What if this condition fails. line 64 assumes ARM path in dict TOOLCHAIN_PATHS. Perhaps raise an exception. Though not sure if this class is instantiated on selection of -t ARM.

Copy link
Contributor Author

@sarahmarshy sarahmarshy Aug 19, 2016

Choose a reason for hiding this comment

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

I did not raise an exception here because I did not want the constructor to fail. The exception will be raised before compile_sources, link_program, or build_library. Nothing in this scope actually executes the command.

Copy link

@mazimkhan mazimkhan Aug 19, 2016

Choose a reason for hiding this comment

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

My question was actually local. If if exe fails then at line 64 TOOLCHAIN_PATHS['ARM'] will give KeyError exception.
If you don't care about actual path being constructed then you can do TOOLCHAIN_PATHS.get('ARM', '')

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why the constructor shouldn't fail? It looks like bailing out as soon as the error is found would be a good thing. Sorry if I'm missing something.

Copy link

@mazimkhan mazimkhan Aug 19, 2016

Choose a reason for hiding this comment

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

please ignore my comment. I can see that TOOLCHAIN_PATHS['ARM'] is already initialized tools.toolchains.__init__.py

Copy link
Contributor

Choose a reason for hiding this comment

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

Has this been checked for all the o/s's we may come across?

Copy link
Contributor Author

@sarahmarshy sarahmarshy Aug 19, 2016

Choose a reason for hiding this comment

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

@bogdanm @theotherjimmy has strong opinions here. I agree that we are delaying failure. But I think it is generally assumed that when you are constructing an object, it will succeed. Though I think __init__ is not a constructor in the same way as C++.

Copy link
Contributor

Choose a reason for hiding this comment

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

init is definitely not a constructor in the same sense as a C++ constructor. Exceptions inside constructors in C++ are bad because they might leave the object in an inconsistent state. That's hardly a concern here, when the outcome is that your program terminates with an error message. But in any case, this isn't a huge deal.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, my beef with the constructor failing has nothing to do with any of that. It's pretty simple: A constructed toolchain is required for an exporter. The online tools have only armc5. We need to be able to export to non-armc5 IDE's. So we must not fail to construct a toolchain when it's executable is not present.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I misunderstood. That makes a lot of sense.

@bogdanm
Copy link
Contributor

bogdanm commented Aug 19, 2016

PR looks good overall (with the above comments). I'd also add another change that sets all the paths in tools/settings.py to the empty string (which is the only sensible default I can think of).

@sarahmarshy
Copy link
Contributor Author

@bogdanm I think that is a good solution. Then, if mbed_settings variables are not set, the value on the PATH will be used.

@adbridge
Copy link
Contributor

I agree with Bogdan about empty strings. It forces the user to think about whether they have configured paths or not. With the non-empty defaults you can get some weird error messages that are not always quick to work out

@sarahmarshy
Copy link
Contributor Author

@adbridge Yes, the [OS ERROR] was the original motivation for this PR.

@sg-
Copy link
Contributor

sg- commented Aug 26, 2016

Tested on Mac.

>>> from distutils.spawn import find_executable
>>> print find_executable('armcc')
None
>>> print find_executable('arm-none-eabi-gcc')
/Applications/yotta.app/Contents/Resources/prerequisites/gcc-arm-none-eabi-4_9-2015q3/bin/arm-none-eabi-gcc
>>> quit()

I dont have armcc installed so that is why its not found

@sarahmarshy
Copy link
Contributor Author

@sg- great! A note on the empty string thing, @bogdanm, I think that should come as a separate PR.

@sg- sg- merged commit ea3526d into ARMmbed:master Aug 26, 2016
artokin pushed a commit to artokin/mbed-os that referenced this pull request Sep 2, 2020
…..91acece

91acece Remove test files
6568bc1 Merge branch 'release_internal' into release_external
4192cc8 Added configuration for RADIUS retry timer (ARMmbed#2438)
684b714 Added support for retries and multiple sockets to RADIUS client (ARMmbed#2426)
89e0ae0 WS: Restart auto CCA threshold after discovery (ARMmbed#2435)
dbb09b1 MAC/WS: Min possible Tack to 1ms and CCA interval to 2ms (ARMmbed#2434)
43b2ae2 Cca threshold test (ARMmbed#2436)
28108e1 Added device min sensitivity setting and stack information
7060c70 Cca threshold test (ARMmbed#2432)
640be71 WS: temporarily set default CCA threshold to -80 (ARMmbed#2431)
0a472ae WS: Calculate UFSI drift and trace (ARMmbed#2430)
61d3db8 Create APIs for DNS cache results
587add5 MAC: Validate TX time (ARMmbed#2429)
a1bfed4 Added typecast when computing max_timout from drift (ARMmbed#2428)
089fb3b Neighbour temporary entry update and Enhanced ACK tx update
70244f6 Wi-sun parameter and debug trace update
5752eae Created validate TX time handler (ARMmbed#2423)
022d61f Wi-sun Neighbour table update and DHCP new callback
857b41f Merge pull request ARMmbed#2421 from ARMmbed/update_from_mbed_os
1a9dd13 (via Mbed-OS)WS Management API missing include
4318f37 Calculate drift in critical state (ARMmbed#2419)
01a1909 FHSS WS: Do not use drift compensation with unpredictable linux timer (ARMmbed#2418)

git-subtree-dir: features/nanostack/sal-stack-nanostack
git-subtree-split: 91acece
artokin pushed a commit to artokin/mbed-os that referenced this pull request Sep 7, 2020
…..d879e6d

d879e6d Merge branch 'release_internal' into release_external
eef9246 Fixed network border router timeout recovery and EAPOL relay address fix
bac7ca6 Changed RADIUS MTU and small fixes
a9f8b75 Addeed support for DHCP vendor data
d8f0003 DHCPv6 functionality update
7fe0423 Added DHCPv6 vendor data generation for DNS queries
639f9db FHSS: Changed retry backoffs when no BC schedule or TX slots (ARMmbed#2440)
91acece Remove test files
6568bc1 Merge branch 'release_internal' into release_external
4192cc8 Added configuration for RADIUS retry timer (ARMmbed#2438)
684b714 Added support for retries and multiple sockets to RADIUS client (ARMmbed#2426)
89e0ae0 WS: Restart auto CCA threshold after discovery (ARMmbed#2435)
dbb09b1 MAC/WS: Min possible Tack to 1ms and CCA interval to 2ms (ARMmbed#2434)
43b2ae2 Cca threshold test (ARMmbed#2436)
28108e1 Added device min sensitivity setting and stack information
7060c70 Cca threshold test (ARMmbed#2432)
640be71 WS: temporarily set default CCA threshold to -80 (ARMmbed#2431)
0a472ae WS: Calculate UFSI drift and trace (ARMmbed#2430)
61d3db8 Create APIs for DNS cache results
587add5 MAC: Validate TX time (ARMmbed#2429)
a1bfed4 Added typecast when computing max_timout from drift (ARMmbed#2428)
089fb3b Neighbour temporary entry update and Enhanced ACK tx update
70244f6 Wi-sun parameter and debug trace update
5752eae Created validate TX time handler (ARMmbed#2423)
022d61f Wi-sun Neighbour table update and DHCP new callback
857b41f Merge pull request ARMmbed#2421 from ARMmbed/update_from_mbed_os
1a9dd13 (via Mbed-OS)WS Management API missing include
4318f37 Calculate drift in critical state (ARMmbed#2419)
01a1909 FHSS WS: Do not use drift compensation with unpredictable linux timer (ARMmbed#2418)

git-subtree-dir: features/nanostack/sal-stack-nanostack
git-subtree-split: d879e6d
artokin pushed a commit to artokin/mbed-os that referenced this pull request Sep 7, 2020
…8609ae..d879e6d

d879e6d Merge branch 'release_internal' into release_external
eef9246 Fixed network border router timeout recovery and EAPOL relay address fix
bac7ca6 Changed RADIUS MTU and small fixes
a9f8b75 Addeed support for DHCP vendor data
d8f0003 DHCPv6 functionality update
7fe0423 Added DHCPv6 vendor data generation for DNS queries
639f9db FHSS: Changed retry backoffs when no BC schedule or TX slots (ARMmbed#2440)
91acece Remove test files
6568bc1 Merge branch 'release_internal' into release_external
4192cc8 Added configuration for RADIUS retry timer (ARMmbed#2438)
684b714 Added support for retries and multiple sockets to RADIUS client (ARMmbed#2426)
89e0ae0 WS: Restart auto CCA threshold after discovery (ARMmbed#2435)
dbb09b1 MAC/WS: Min possible Tack to 1ms and CCA interval to 2ms (ARMmbed#2434)
43b2ae2 Cca threshold test (ARMmbed#2436)
28108e1 Added device min sensitivity setting and stack information
7060c70 Cca threshold test (ARMmbed#2432)
640be71 WS: temporarily set default CCA threshold to -80 (ARMmbed#2431)
0a472ae WS: Calculate UFSI drift and trace (ARMmbed#2430)
61d3db8 Create APIs for DNS cache results
587add5 MAC: Validate TX time (ARMmbed#2429)
a1bfed4 Added typecast when computing max_timout from drift (ARMmbed#2428)
089fb3b Neighbour temporary entry update and Enhanced ACK tx update
70244f6 Wi-sun parameter and debug trace update
5752eae Created validate TX time handler (ARMmbed#2423)
022d61f Wi-sun Neighbour table update and DHCP new callback
857b41f Merge pull request ARMmbed#2421 from ARMmbed/update_from_mbed_os
1a9dd13 (via Mbed-OS)WS Management API missing include
4318f37 Calculate drift in critical state (ARMmbed#2419)
01a1909 FHSS WS: Do not use drift compensation with unpredictable linux timer (ARMmbed#2418)

git-subtree-dir: connectivity/nanostack/sal-stack-nanostack
git-subtree-split: d879e6d
winneymj pushed a commit to winneymj/mbed-os that referenced this pull request Sep 29, 2020
…8609ae..d879e6d

d879e6d Merge branch 'release_internal' into release_external
eef9246 Fixed network border router timeout recovery and EAPOL relay address fix
bac7ca6 Changed RADIUS MTU and small fixes
a9f8b75 Addeed support for DHCP vendor data
d8f0003 DHCPv6 functionality update
7fe0423 Added DHCPv6 vendor data generation for DNS queries
639f9db FHSS: Changed retry backoffs when no BC schedule or TX slots (ARMmbed#2440)
91acece Remove test files
6568bc1 Merge branch 'release_internal' into release_external
4192cc8 Added configuration for RADIUS retry timer (ARMmbed#2438)
684b714 Added support for retries and multiple sockets to RADIUS client (ARMmbed#2426)
89e0ae0 WS: Restart auto CCA threshold after discovery (ARMmbed#2435)
dbb09b1 MAC/WS: Min possible Tack to 1ms and CCA interval to 2ms (ARMmbed#2434)
43b2ae2 Cca threshold test (ARMmbed#2436)
28108e1 Added device min sensitivity setting and stack information
7060c70 Cca threshold test (ARMmbed#2432)
640be71 WS: temporarily set default CCA threshold to -80 (ARMmbed#2431)
0a472ae WS: Calculate UFSI drift and trace (ARMmbed#2430)
61d3db8 Create APIs for DNS cache results
587add5 MAC: Validate TX time (ARMmbed#2429)
a1bfed4 Added typecast when computing max_timout from drift (ARMmbed#2428)
089fb3b Neighbour temporary entry update and Enhanced ACK tx update
70244f6 Wi-sun parameter and debug trace update
5752eae Created validate TX time handler (ARMmbed#2423)
022d61f Wi-sun Neighbour table update and DHCP new callback
857b41f Merge pull request ARMmbed#2421 from ARMmbed/update_from_mbed_os
1a9dd13 (via Mbed-OS)WS Management API missing include
4318f37 Calculate drift in critical state (ARMmbed#2419)
01a1909 FHSS WS: Do not use drift compensation with unpredictable linux timer (ARMmbed#2418)

git-subtree-dir: connectivity/nanostack/sal-stack-nanostack
git-subtree-split: d879e6d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.