-
Notifications
You must be signed in to change notification settings - Fork 3k
Fixed sw4stm32 exporter #4779
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
Fixed sw4stm32 exporter #4779
Conversation
Can you please sign https://developer.mbed.org/contributor_agreement/ ? |
Signed already, is there somekind of a problem? |
I could not locate JarnoEtt on mbed developer page, whats your nick name? |
Oh, my mbed developer nickname is Jarno. |
tools/export/sw4stm32/__init__.py
Outdated
from os.path import splitext, basename, join | ||
import os | ||
|
||
from os.path import splitext, basename, join, dirname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason to import os; from os.path import XX
instead of doing directly from os.path import XX
as it was before ?
tools/export/sw4stm32/__init__.py
Outdated
This function removes ./ from str. | ||
str must be converted with win_to_unix() before using this function. | ||
""" | ||
if str == None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be a tabulation here. Python conventions (PEP8) prefer 4 spaces for indentation, and dislike mixed tabs and spaces. Moreover, str
is a builtin class and should not be used as a variable name: prefer a name like path
which is also more descriptive of what the variable holds. Also the prefered method to test for None
is if path is None
because None is a singleton (also PEP8).
tools/export/sw4stm32/__init__.py
Outdated
src) for src in self.resources.c_sources + self.resources.cpp_sources + self.resources.s_sources)] | ||
if '.' in self.source_folders: | ||
self.source_folders.remove('.') | ||
#print source_folders |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug comment should be removed. (Not the only occurence of this, but I will report only this one)
tools/export/sw4stm32/__init__.py
Outdated
libraries = [] | ||
for lib in self.resources.libraries: | ||
l, _ = splitext(basename(lib)) | ||
libraries.append(l[3:]) | ||
|
||
self.include_path = [self.filter_dot(s) for s in self.resources.inc_dirs] | ||
print 'Include folders: {0}'.format(len(self.include_path)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python 3's print is not a keyword anymore and require parenthesis.
Mbed uses Python 2, but if some day Python 3 is supported (and it should be asap), best is to ease this work as much as possible.
@Nodraak changed. |
As a Python lover, I made a few comments about the Python code. I think mbed's Python code could be greatly enhanced and therefore I think that each PR should try to improve the quality and not introduce new code style issues. @JarnoEtt, first of all, thank you for your contribution. I don't know if your are an experienced Python dev, but if you don't already, I suggest you use tools such as Pylint (others exists, such as Flake8 or others but I like Pylint), in order to check the quality of your code. This will improve the readability of your code and even sometimes highlight potential issues that could lead to bugs. |
Thx for your feedback, going to check those. |
My hero. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great start. I'm going to remove the deprecation notice for SW4STM32. But, This looks like it does nothing with the passed in compiler flags. It could be supported better if it did.
tools/export/sw4stm32/__init__.py
Outdated
This function removes ./ from str. | ||
str must be converted with win_to_unix() before using this function. | ||
""" | ||
if path is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be:
if not path:
return path
That way you avoid empty string issues too.
tools/export/sw4stm32/__init__.py
Outdated
""" | ||
if path is None: | ||
return None | ||
if path[:2] == './': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check should be:
if path.startswith('./'):
That's more in line with what you're trying to check.
tools/export/sw4stm32/__init__.py
Outdated
if not found: | ||
for directory in self.exclude_dirs: | ||
# Do not exclude subfolders from excluded folder | ||
if path.find(directory+'/') != -1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably don't care where the substring is, so:
if (directory + '/') in path:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively,
if join(directory, '') in path:
tools/export/sw4stm32/__init__.py
Outdated
found = False | ||
for used in self.include_path: | ||
if path == used: | ||
found = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole for loop is the same as:
found = path in self.include_path
tools/export/sw4stm32/__init__.py
Outdated
|
||
ld_script = self.filter_dot(self.resources.linker_script) | ||
|
||
# self.lib_dirs = [self.filter_dot(s) for s in self.resources.lib_dirs] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove commented out code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes made. Can't promise anything about build method or other things, there was pretty tight timeline for this and sw4stm32 exporter was more broken and bare boned than we thought.
@JarnoEtt Would it be possible to write a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python bits look great! Still needs to pass compiler flags into the template though.
@JarnoEtt You mentioned that your timeline for this fix was short. Would you be able to support SW4STM32 after that time? How long do you have to fix this? I might be able to help out with the fix, if your need it in really soon. |
@JarnoEtt Any news? @bcostm @adustm @LMESTM @jeromecoutant Could you review? Would you like to help make this exporter better? |
Oh, sorry for the silence. I have been out of office/out of reach for a while. @ajaakko-arm and @Veli-PekkaPorrassalmi took this task and going to continue with flags + linker script problem #4269. They are also informed about headless build method request. I added them to forked repository, is there anything else to do so they can do changes to this case? |
@ajaakko-arm It's great to see progress. Let me re-review and give you the checklist of things I would like to see before merge and how well this PR is doing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're getting there. I'm really excited to see that the SW4STM32 exporter is being maintained, and that it heeds the scan resources rules.
I have left a few suggestions that may help reduce code duplication among the exporters. Please either follow them, or explain why you must duplicate the code.
Further, for the best user experience, , an exporter:
- Takes input from the resource scan.
- Uses the flags in the build profiles. (I'm pretty sure that the template just ignores them)
- Has a single template file for each file type they produce. For example, an eclipse CDT project would have one template for
.project
files and one for.cproject
files. - Does not call Mbed CLI. It is possible to export from the website, which will not include Mbed CLI in the resulting zip.
tools/export/sw4stm32/__init__.py
Outdated
# Paths returned by os.walk() must be split with os.dep | ||
# to accomodate Windows weirdness. | ||
parts = root.split(sep) | ||
self.remove_unused('/'.join(parts)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, You should be able to avoid walking here. self.resources
has an ignored_dirs
member on export that should be very useful to you. Moreover, you could just inherit from the GnuArmEclipse class and get most of this for free.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I looked at the code first time, my thought was, that there should be some common or base package every exporter (or more likely every exporter for IDE's based on Eclipse) could use. There were so much same or similar functionality.
To inherit GnuArmEclipse is of course another option, and maybe simpler. I could give it a try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI.
Flags were next on my todo-list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! I wanted to record what should happen before we get this in. Thanks for taking this over!
print ('\nCreate a System Workbench for STM32 managed project') | ||
print ('Project name: {0}'.format(self.project_name)) | ||
print ('Target: {0}'.format(self.toolchain.target.name)) | ||
print ('Toolchain: {0}'.format(self.TOOLCHAIN) + '\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate the attention to making this printing python 3 compatible, but I have to ask: Why do you need to tell the user exactly what they specified? They really should know all of this stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I borrowed this from gnuarmeclipse exporter. But I personally like the idea, that program is printing something, so that I know what's going on.
Better option would be to print some deeper information when exporter is called with verbose flag on. Like path to linker script, flags etc. But i suppose there's no way to know if 'mbed export' was called with -v flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But i suppose there's no way to know if 'mbed export' was called with -v flag?
That's correct.
Alright then. I will switch to using logging or something like it for the exporters soon. I'll change your prints to logs at a good level then. now you can leave it in.
Can I ask: "Added -O2 to GCC compiler because e.g. mbed-os/rtos/rtx5/TARGET_CORTEX_M/rtx_delay.c needs it" May I ask why this is the case? So if someone changes the optimisation settings, it breaks? |
@noutram You might want to ask that at https://github.com/ARM-software/CMSIS_5 as that file comes from https://github.com/ARM-software/CMSIS_5/blob/develop/CMSIS/RTOS2/RTX/Source/rtx_delay.c |
…ader() instead of hardcoding it to project file.
Added makefile.target, and rule for linker script pre-compilation.
SW4STM32 linker script name now contains target name. Print formatting is using new Python style.
Sw4STM32 is using methods from GNUARMEclipse class to handle flags. Flags are also passed to cproject file.
Removed unused methods and methods with dublicate functionality. Removed unused imports. Generating list of defines for assembler.
Fixed invalid linker script path in project file. Using 'defines' instead of 'symbols' in compiler options.
Quotation marks in defines had to be replaced with html codes.
Sometimes Sw4STM32 exporter receives wrong linker script file. Because build directories cannot be excluded from scanned resources, ld files are removed.
Quoting linker preprocessor command, if path contains parentheses. Using relative path to shorten list of included directories. Using Eclipse variables to get path to preprocessor.
Directories Debug and Release must not be excluded. Otherwise, Eclipse is not able to find binaries, which are stored to build directories.
Add double quotes to linker command unconditionally.
Some of the optimization and warning flags, which were supported by the gnuarmeclipse exporter, were missing from the sw4stm32.
f3cfda5
to
6b6187a
Compare
Did rebase from https://github.com/ARMmbed/mbed-os master to test NUCLEO_F767ZI. |
I have rechecked the exporter on NUCLEO_F767ZI and it is OK with me. |
@theotherjimmy There were some IAR build machines that were configured slightly wrong which caused this to fail. All green now. |
/morph export-build |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
Outputmbed Build Number: 149 All exports and builds passed! |
This is good news! I will test today. |
Notes:
Fixes issues with sw4stm32 exporter
Description
Added mbed_config.h as -included, fixes #4084.
Added exclude directory generation, fixes #4091 (see theotherjimmy post).
Added -O2 to GCC compiler because e.g. mbed-os/rtos/rtx5/TARGET_CORTEX_M/rtx_delay.c needs it.
Exporter generated broken project file if there was quotes in toolchain symbols, fixed that also.
Status
READY
Todos
Deploy notes
Steps to test or reproduce