Skip to content
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

Simplify data embedding #270

Merged
merged 1 commit into from
May 7, 2020
Merged

Simplify data embedding #270

merged 1 commit into from
May 7, 2020

Conversation

jwnimmer-tri
Copy link
Contributor

@jwnimmer-tri jwnimmer-tri commented May 7, 2020

This is an internal-only refactoring that changes the mechanics of how the sdf/** file data is embedded into the library.

For one, it solves the https://isocpp.org/wiki/faq/ctors#static-init-order fiasco for the embedded data. The data is only loaded into memory upon first use, instead of as the library is being loaded. This is the magic of function-local statics.

It also simplifies the ruby embedding code, making it more concise. I hope this is easier to maintain, but it also helps me when sharing Drake with consumers that always build from source, but will not install ruby as a compile-time prerequisite (RobotLocomotion/drake#13231).

I am happy to take feedback. Is this the correct branch to PR into? Should I be adding a changelog entry? You are welcome to push fixes to my branch -- it looks like by convention I should not be rebasing nor squashing it?

Copy link
Collaborator

@azeey azeey left a comment

Choose a reason for hiding this comment

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

Looks good to me! Now that you've simplified the codgen, I wonder how hard it would be to generate the file using CMake.

Copy link
Collaborator

@azeey azeey left a comment

Choose a reason for hiding this comment

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

I remembered that I saw some minor style issues after I approved.

src/Converter.cc Outdated Show resolved Hide resolved
src/Converter.cc Outdated Show resolved Hide resolved
This is an internal-only refactoring that changes the mechanics of how
the sdf/** file data is embedded into the library.

For one, it solves the "static initialization order fiasco" for the
embedded data. The data is only loaded into memory upon first use,
instead of as the library is being loaded.

It also simplifies the ruby embedding code, making it more concise.
I hope this is easier to maintain, but it also helps me when sharing
Drake with consumers that always build from source, but will not
install ruby as a compile-time prerequisite

The EmbeddedSdf codegen now emits the cc file with the data; the header
is stored in git. This provides an easier way to use a function to
retrieve the embedded strings as static locals.

The embedded SDF data is now combined into a single map.  Embedding
files should be boring, ala the WIP std::embed specification.  It
should not include application-layer logic encoding upgrade paths.

This will also make it easier to avoid the "static destruction fiasco"
in future commits, due to fewer functions to repair.

Signed-off-by: Jeremy Nimmer <jeremy.nimmer@tri.global>
@jwnimmer-tri
Copy link
Contributor Author

FYI I've locally squashed and force-pushed as part of placating the DCO bot

I wonder how hard it would be to generate the file using CMake.

Probably possible, but there's a more complicated use of ruby still in tools/, so we wouldn't be able to drop the ruby dependency yet. That could be future work. For now, this is enough to make my users happier.

@codecov-io
Copy link

codecov-io commented May 7, 2020

Codecov Report

Merging #270 into master will increase coverage by 0.00%.
The diff coverage is 95.45%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #270   +/-   ##
=======================================
  Coverage   86.45%   86.46%           
=======================================
  Files          59       59           
  Lines        9051     9065   +14     
=======================================
+ Hits         7825     7838   +13     
- Misses       1226     1227    +1     
Impacted Files Coverage Δ
src/Converter.cc 91.46% <94.73%> (+<0.01%) ⬆️
src/SDF.cc 92.35% <100.00%> (+0.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9eb6b99...360394d. Read the comment docs.

/// directory such as "1.8/root.sdf", and the values are the contents of
/// that source file.
const std::map<std::string, std::string> &GetEmbeddedSdf();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit Mismatched indentation?

Copy link
Member

Choose a reason for hiding this comment

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

it looks like we usually close the internal namespace on the same line that it was created (Converter.hh) but not always (SDFImplPrivate.hh), so I'm not worried about it

@scpeters scpeters merged commit 3bbd303 into gazebosim:master May 7, 2020
@jwnimmer-tri jwnimmer-tri deleted the simplify-data-embedding branch May 8, 2020 00:45
scpeters pushed a commit that referenced this pull request Jun 2, 2020
This is an internal-only refactoring that changes the mechanics of how
the sdf/** file data is embedded into the library.

For one, it solves the "static initialization order fiasco" for the
embedded data. The data is only loaded into memory upon first use,
instead of as the library is being loaded.

It also simplifies the ruby embedding code, making it more concise.
I hope this is easier to maintain, but it also helps me when sharing
Drake with consumers that always build from source, but will not
install ruby as a compile-time prerequisite

The EmbeddedSdf codegen now emits the cc file with the data; the header
is stored in git. This provides an easier way to use a function to
retrieve the embedded strings as static locals.

The embedded SDF data is now combined into a single map.  Embedding
files should be boring, ala the WIP std::embed specification.  It
should not include application-layer logic encoding upgrade paths.

This will also make it easier to avoid the "static destruction fiasco"
in future commits, due to fewer functions to repair.

Signed-off-by: Jeremy Nimmer <jeremy.nimmer@tri.global>
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