Skip to content

Copying JSON files to pick up config for built libraries #2471

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 1 commit into from
Aug 26, 2016

Conversation

bridadan
Copy link
Contributor

This came up when building tests, but affects any library using config that's first built, then included as "source" with the mbed tools. JSON files are not copied by default when building a library, so when this is built it loses the config data associated with the library. This commit copies all JSON files into the build directory when building libraries.

There is a strange side effect now which is there are now multiple mbed_config.h files created during the build process: one when building the library and one when building the actual application. This isn't currently a problem since none of our code explicitly includes mbed_config, but it does look strange. Is anyone aware of potential issues with this? If so, having the ability to prevent an mbed_config.h from being created in the API may be a solution.

cc @bogdanm @AlessandroA @screamerbg

@bridadan
Copy link
Contributor Author

This should hopefully address one of the issues raised in #2397

@bridadan
Copy link
Contributor Author

/morph test

@mbed-bot
Copy link

Result: SUCCESS

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

/morph test

Output

mbed Build Number: 659

All builds and test passed!

@bogdanm
Copy link
Contributor

bogdanm commented Aug 17, 2016

There is a strange side effect now which is there are now multiple mbed_config.h files created during the build process: one when building the library and one when building the actual application.

The mbed_config.h file that is created when building the library needs to be deleted. The configuration system will generate a new mbed_config.h when building the application (and this mbed_config.h will take into account all the mbed_lib.json files that it finds in the source directories).

@@ -457,6 +457,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
toolchain.copy_files(resources.headers, build_path, resources=resources)
toolchain.copy_files(resources.objects, build_path, resources=resources)
toolchain.copy_files(resources.libraries, build_path, resources=resources)
toolchain.copy_files(resources.json_files, build_path, resources=resources)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the scanner finds more than one mbed_lib.json file? For example, the one for core and the one forrtos. Are those copied in separate directories? It's important to keep all thembed_lib.json` files found by the scanner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the paths for mbed_lib.json files should be preserved, though I will double check this!

@bridadan
Copy link
Contributor Author

@bogdanm Thanks for the feedback. Perhaps the way we should do this then is provide an option to the build_library api that allows you to disable creating the mbed_config.h files? So when building tests, we would disable the creating of the file altogether.

@bogdanm
Copy link
Contributor

bogdanm commented Aug 18, 2016

So when building tests, we would disable the creating of the file altogether.

The thing is that when building you need mbed_config.h, since that's how the libraries know about their compile-time configuration. But that file is only needed when building the library; later, when the application is built, the config system will re-create mbed_config.h from the various mbed_lib.json files it finds, plus the mbed_app.json file. So either:

  • when building the library, create the mbed_config.h file somewhere outside the library build tree.
  • build the library, then remove the mbed_config.h file.

The second option above is probably a bit easier to implement.

@theotherjimmy
Copy link
Contributor

We could always create mbed_config.h as a temp file. That would accomplish both of those points at the same time. OTOH, I think it's reasonable to insist that library builds always delete the mbed_config.h

This came up when building tests, but affects any library that's built
that uses config and included as "source" with the mbed tools.
JSON files are not copied by default when building a library, so when this
is built it loses the config data associated with the library. This commit
copies all JSON files into the build directory when building libraries.

This leads to two mbed_config.h files existing if the build directories
are different between the library and application build. This is the case
when building tests, so an option build_library was added to remove the
mbed_config.h file when compilation is done. This disabled by default when
building libraries, but it is enabled when building tests.
@bridadan bridadan force-pushed the copy-config-library branch from 06a24b5 to 33672b4 Compare August 23, 2016 21:44
@bridadan
Copy link
Contributor Author

I've added an option to build_library that allows you to remove the config header file after compilation completes. This is by default disabled, but I enable this when building tests.

@bridadan
Copy link
Contributor Author

/morph test

@theotherjimmy
Copy link
Contributor

theotherjimmy commented Aug 23, 2016

Instead, could you possibly delete the mbed_config.h after you call build_library? I'm hesitant to increase the number of arguments to build library, it's already ~20.

OTOH, 👍 on the docstring update.

@bridadan
Copy link
Contributor Author

@theotherjimmy I did think about doing that. Although in test.py I don't have access to the toolchain instance and I was using that to get the location of the mbed_config.h header. I could probably search through the build directory to find it (or just assume its at the root of the build directory), but that seemed a bit presumptive. What do you think?

@theotherjimmy
Copy link
Contributor

I don't like it, but you're right it would be hacky either way.

@mbed-bot
Copy link

Result: FAILURE

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

/morph test

Output

mbed Build Number: 689

Test failed!

@AlessandroA
Copy link
Contributor

@theotherjimmy @bridadan What's the status of this?

@bridadan
Copy link
Contributor Author

@bogdanm Are you happy with this?

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 26, 2016

@bogdanm Are you happy with this?

He's away for the next days. We shall together review and do +1 if it looks good and addresses comments within this patch. @theotherjimmy happy with this?

@sg- sg- merged commit f147f6f into ARMmbed:master Aug 26, 2016
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.

7 participants