Skip to content

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

Merged
merged 17 commits into from
Sep 22, 2017
Merged

Fixed sw4stm32 exporter #4779

merged 17 commits into from
Sep 22, 2017

Conversation

JarnoEtt
Copy link
Contributor

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

  • Tests
  • Documentation

Deploy notes

Steps to test or reproduce

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 19, 2017

@JarnoEtt
Copy link
Contributor Author

Signed already, is there somekind of a problem?

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 19, 2017

I could not locate JarnoEtt on mbed developer page, whats your nick name?

@JarnoEtt
Copy link
Contributor Author

Oh, my mbed developer nickname is Jarno.

from os.path import splitext, basename, join
import os

from os.path import splitext, basename, join, dirname
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 specific reason to import os; from os.path import XX instead of doing directly from os.path import XX as it was before ?

This function removes ./ from str.
str must be converted with win_to_unix() before using this function.
"""
if str == None:
Copy link
Contributor

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).

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
Copy link
Contributor

@Nodraak Nodraak Jul 19, 2017

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)

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))
Copy link
Contributor

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.

@JarnoEtt
Copy link
Contributor Author

@Nodraak changed.

@Nodraak
Copy link
Contributor

Nodraak commented Jul 19, 2017

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.

@JarnoEtt
Copy link
Contributor Author

Thx for your feedback, going to check those.

@theotherjimmy
Copy link
Contributor

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.

My hero.

Copy link
Contributor

@theotherjimmy theotherjimmy left a 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.

This function removes ./ from str.
str must be converted with win_to_unix() before using this function.
"""
if path is None:
Copy link
Contributor

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.

"""
if path is None:
return None
if path[:2] == './':
Copy link
Contributor

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.

if not found:
for directory in self.exclude_dirs:
# Do not exclude subfolders from excluded folder
if path.find(directory+'/') != -1:
Copy link
Contributor

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:

Copy link
Contributor

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:

found = False
for used in self.include_path:
if path == used:
found = True
Copy link
Contributor

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


ld_script = self.filter_dot(self.resources.linker_script)

# self.lib_dirs = [self.filter_dot(s) for s in self.resources.lib_dirs]
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@theotherjimmy
Copy link
Contributor

theotherjimmy commented Jul 19, 2017

@JarnoEtt Would it be possible to write a build method for this class? If you do, it will be added to CI and will significantly more stable.

Copy link
Contributor

@theotherjimmy theotherjimmy left a 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.

@theotherjimmy
Copy link
Contributor

theotherjimmy commented Jul 26, 2017

@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.

@theotherjimmy
Copy link
Contributor

@JarnoEtt Any news?

@bcostm @adustm @LMESTM @jeromecoutant Could you review? Would you like to help make this exporter better?

@JarnoEtt
Copy link
Contributor Author

JarnoEtt commented Aug 7, 2017

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?

@theotherjimmy
Copy link
Contributor

@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.

Copy link
Contributor

@theotherjimmy theotherjimmy left a 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.

# Paths returned by os.walk() must be split with os.dep
# to accomodate Windows weirdness.
parts = root.split(sep)
self.remove_unused('/'.join(parts))
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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')
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

@noutram-old-uopaccount
Copy link

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?

@theotherjimmy
Copy link
Contributor

JarnoEtt and others added 14 commits September 13, 2017 12:05
…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.
@ajaakkoh
Copy link
Contributor

Did rebase from https://github.com/ARMmbed/mbed-os master to test NUCLEO_F767ZI.

@bcostm
Copy link
Contributor

bcostm commented Sep 15, 2017

I have rechecked the exporter on NUCLEO_F767ZI and it is OK with me.

@theotherjimmy
Copy link
Contributor

Thanks @bcostm for testing!

@tommikas It looks like something is going wrong with the Oulu CI, but no C files were harmed in the making of this pull request. Further, this only touches an untested (in CI) exporter. Could you take a look?

@tommikas
Copy link
Contributor

@theotherjimmy There were some IAR build machines that were configured slightly wrong which caused this to fail. All green now.

@theotherjimmy
Copy link
Contributor

/morph export-build

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph export-build

Output

mbed Build Number: 149

All exports and builds passed!

@noutram-old-uopaccount
Copy link

This is good news! I will test today.

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.

Exported mbed-os project build fails in SW4STM32 Exported project build fails in SW4STM32
9 participants