-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
kuka_plan_runner can find resources when installed #7439
kuka_plan_runner can find resources when installed #7439
Conversation
I'm unclear on the motivation for this PR. I see that Is the problem of kuka_plan_runner needing an env var to work right now acutely painful, such that we want a band-aid PR merged quickly? If so, this PR would be fine with an appropriate TODO disclaimer near the changed lines, and an issue opened to track undoing it. If its not an immediate pain point, then it seems like an infrastructural fixup would be less overall hassle, since we have to do that anyway. Review status: 0 of 1 files reviewed at latest revision, all discussions resolved, some commit checks failed. Comments from Reviewable |
The motivation of this PR is to get other Right now, if one runs The environment variable is ok, but it is always easier to have software that just works. The same idea was applied to the libraries: If dependent libraries are not found at runtime, one can change The general solution suggested in the PR message is a better solution, but I didn't want to implement it before getting other people's opinion. Is this what you called 'infrastructural fixup` or did you have something else in mind? Review status: 0 of 1 files reviewed at latest revision, all discussions resolved, some commit checks failed. Comments from Reviewable |
That helps a lot, thank you. By infrastructure, I just mean fixing it in one place. Probably that is some change to Comments from Reviewable |
Good point. The runtime_error string provided in |
For making binaries Just Work, I see two possible options. (1) Use the binary's pathname (via our implementation of (2) Use the binary's |
I tested 2) and on linux it is fairly easy to list the libraries that are loaded. However, that made me realize that the examples do not link against |
53dc685
to
6c1d6ce
Compare
I updated the bazel build such that the examples that we are installing depend in |
I marked a few suggested spots for cleanup. I would like to get @jamiesnape's feedback on the general approach. I wonder if using a smaller shared library would make more sense. So like in Reviewed 1 of 6 files at r2. drake/bindings/python/pydrake/init.py, line 13 at r2 (raw file):
This hunk (here on down) seems like it should also be removed, since the AddRes... call that uses it is gone now. drake/common/find_resource.cc, line 294 at r2 (raw file):
Maybe the "where is libdrake.so" code could move into a second file, to help declutter this one, and to isolate platform-specific code into a single exclusive location from platform-independent code? (The "../share/drake" addition could still live within this file.) drake/examples/kuka_iiwa_arm/BUILD.bazel, line 90 at r2 (raw file):
The "create an example that links to libdrake.so" mechanics will have to be abstracted into a helper macro. Repeating it several times is too brittle. drake/examples/kuka_iiwa_arm/BUILD.bazel, line 111 at r2 (raw file):
Probably this (within the helper macro) should just depend on all LCM headers, so either drake/examples/kuka_iiwa_arm/kuka_plan_runner.cc, line 187 at r2 (raw file):
BTW This change (adding two unused arguments) can probably be reverted now? Comments from Reviewable |
I think this is fine and I probably would keep Review status: 1 of 6 files reviewed at latest revision, 5 unresolved discussions, some commit checks failed. Comments from Reviewable |
OK Review status: 1 of 6 files reviewed at latest revision, 5 unresolved discussions, some commit checks failed. Comments from Reviewable |
6c1d6ce
to
58e2e92
Compare
Review status: 0 of 10 files reviewed at latest revision, 5 unresolved discussions, some commit checks failed. drake/common/find_resource.cc, line 294 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. drake/examples/kuka_iiwa_arm/BUILD.bazel, line 90 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. drake/examples/kuka_iiwa_arm/BUILD.bazel, line 111 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. drake/bindings/python/pydrake/init.py, line 13 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. drake/examples/kuka_iiwa_arm/kuka_plan_runner.cc, line 187 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. Comments from Reviewable |
FYI I'm okay anytime you want to rebase this, even if it resets reviewable's discussions. Reviewed 8 of 12 files at r3. drake/common/find_resource.cc, line 17 at r3 (raw file):
Are these includes needed here anymore? drake/examples/kuka_iiwa_arm/BUILD.bazel, line 133 at r3 (raw file):
Unclear why this doesn't use tools/skylark/drake_cc.bzl, line 515 at r3 (raw file):
Needs more documentation - both about what this does, and advice on why or where it should be used. Comments from Reviewable |
58e2e92
to
36b1bc1
Compare
Review status: 1 of 8 files reviewed at latest revision, 3 unresolved discussions. tools/skylark/drake_cc.bzl, line 515 at r3 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. drake/common/find_resource.cc, line 17 at r3 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. drake/examples/kuka_iiwa_arm/BUILD.bazel, line 133 at r3 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. Comments from Reviewable |
Reviewed 11 of 15 files at r4. common/find_loaded_library.cc, line 87 at r4 (raw file):
FYI The names and mnemonics in https://stackoverflow.com/a/27522149 were more useful for me (and a bit more C++-ish) to follow along with. common/find_loaded_library.cc, line 89 at r4 (raw file):
Private structure declarations should appear in the anonymous namespace. Ditto below common/find_loaded_library.cc, line 90 at r4 (raw file):
BTW Extra horizontal whitespace common/find_loaded_library.cc, line 93 at r4 (raw file):
Inconsistent capitalization common/find_loaded_library.cc, line 98 at r4 (raw file):
BTW Extra horizontal whitespace common/find_loaded_library.h, line 4 at r4 (raw file):
BTW unused? common/find_loaded_library.h, line 11 at r4 (raw file):
Should be CamelCase http://drake.mit.edu/styleguide/cppguide.html#Function_Names Also the common/find_loaded_library.h, line 11 at r4 (raw file):
Missing API documentation on public method. common/find_resource.cc, line 231 at r4 (raw file):
http://drake.mit.edu/styleguide/cppguide.html#Static_and_Global_Variables The easy fix is: static const never_destroyed<optional<string>> from_libdrake =
resource_path_from_libdrake(); common/find_resource.cc, line 232 at r4 (raw file):
Case (3) probably needs a regression test of some kind? (Or did I overlook it?) common/find_resource.cc, line 233 at r4 (raw file):
Missing blank line between numbered list items (for consistency with other paragraphs above). tools/skylark/drake_cc.bzl, line 530 at r4 (raw file):
BTW Is there a reason to repeat args that are passed through unchanged to drake_cc_binary? The tools/skylark/drake_cc.bzl, line 540 at r4 (raw file):
It seems to me like this macro should fail-fast if deps contains a label Probably should also fail-fast if Comments from Reviewable |
+@soonho-tri for feature review of the APPLE portion (first half) of +@sammy-tri for feature review of the proposal to use Review status: all files reviewed at latest revision, 13 unresolved discussions. Comments from Reviewable |
Done. PTAL. Reviewed 4 of 15 files at r4. common/find_loaded_library.cc, line 15 at r4 (raw file):
It seems that we need common/find_loaded_library.cc, line 28 at r4 (raw file):
It's not clear why we need common/find_loaded_library.cc, line 33 at r4 (raw file):
BTW, better to be verbose here by having common/find_loaded_library.cc, line 36 at r4 (raw file):
BTW, unnecessary space between common/find_loaded_library.cc, line 43 at r4 (raw file):
BTW, common/find_loaded_library.cc, line 45 at r4 (raw file):
I think the use of common/find_loaded_library.cc, line 63 at r4 (raw file):
BTW, is it better to have common/find_loaded_library.cc, line 74 at r4 (raw file):
Can we use common/find_loaded_library.cc, line 76 at r4 (raw file):
How about we have explicit return statement, Comments from Reviewable |
Review status: all files reviewed at latest revision, 22 unresolved discussions. common/find_loaded_library.cc, line 15 at r4 (raw file):
Never mind. I found it in Comments from Reviewable |
Reviewed 1 of 14 files at r3, 9 of 15 files at r4. common/find_loaded_library.cc, line 88 at r4 (raw file):
Is there a compelling reason to define common/find_loaded_library.cc, line 109 at r4 (raw file):
Could we avoid defining examples/kuka_iiwa_arm/BUILD.bazel, line 95 at r4 (raw file):
These are all real dependencies of this code. I'm not sure it's a good policy to remove deps because they happen to be captured by a transitive dependency (which could be brittle if the something downstream changes its dependencies)? (and META throughout this file). Comments from Reviewable |
Review status: all files reviewed at latest revision, 24 unresolved discussions. examples/kuka_iiwa_arm/BUILD.bazel, line 95 at r4 (raw file): Previously, sammy-tri (Sam Creasey) wrote…
This is actually the point of this PR, and what I wanted your eyes on. The upshot is when using One consequence of that is that building these examples now unconditionally depends on all of libdrake, rather than just the fraction that is used at runtime. Another consequence is that we can't list things twice here; doing that would violate ODR. The premise of this PR is that examples link to In writing this out now, I realize that Another alternative might be to have an used-by-install-rules-only target, that links the example dynamically; it could programmatically strip out the deps, so that the list here would remain unchanged (and used to narrow the dependencies at development-time). Comments from Reviewable |
Review status: all files reviewed at latest revision, 24 unresolved discussions. examples/kuka_iiwa_arm/BUILD.bazel, line 95 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Ok, thanks, hopefully I understand a bit better now. Building these examples (and the .so for that matter!) every time anything anywhere in drake changes might get annoying, but for someone actively developing another part of drake the answer is probably to use a more specific target for For the Comments from Reviewable |
examples/kuka_iiwa_arm/BUILD.bazel, line 95 at r4 (raw file): Previously, sammy-tri (Sam Creasey) wrote…
For context: the thought process is also that (1) approximately all examples should be installed, and (2) all installed examples will switch to use drake_example_cc_binary and thus have the "libdrake.so dependency" consequences. Comments from Reviewable |
Review status: all files reviewed at latest revision, 24 unresolved discussions. tools/skylark/drake_cc.bzl, line 540 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Caveat: code in a Comments from Reviewable |
36b1bc1
to
919355f
Compare
Review status: 2 of 10 files reviewed at latest revision, 26 unresolved discussions. common/find_loaded_library.cc, line 15 at r4 (raw file): Previously, soonho-tri (Soonho Kong) wrote…
common/find_loaded_library.cc, line 28 at r4 (raw file):
common/find_loaded_library.cc, line 28 at r4 (raw file): Previously, soonho-tri (Soonho Kong) wrote…
Done. common/find_loaded_library.cc, line 36 at r4 (raw file): Previously, soonho-tri (Soonho Kong) wrote…
Done. common/find_loaded_library.cc, line 43 at r4 (raw file): Previously, soonho-tri (Soonho Kong) wrote…
Done. common/find_loaded_library.cc, line 45 at r4 (raw file): Previously, soonho-tri (Soonho Kong) wrote…
Done. common/find_loaded_library.cc, line 63 at r4 (raw file): Previously, soonho-tri (Soonho Kong) wrote…
Done. common/find_loaded_library.cc, line 74 at r4 (raw file): Previously, soonho-tri (Soonho Kong) wrote…
I don't see the benefits of using common/find_loaded_library.cc, line 76 at r4 (raw file): Previously, soonho-tri (Soonho Kong) wrote…
Done. common/find_loaded_library.cc, line 87 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
I removed most of it. common/find_loaded_library.cc, line 88 at r4 (raw file): Previously, sammy-tri (Sam Creasey) wrote…
I removed it. common/find_loaded_library.cc, line 89 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
I removed it. common/find_loaded_library.cc, line 90 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. common/find_loaded_library.cc, line 93 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Removed. common/find_loaded_library.cc, line 98 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. common/find_loaded_library.cc, line 109 at r4 (raw file): Previously, sammy-tri (Sam Creasey) wrote…
Done. common/find_loaded_library.h, line 4 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. common/find_loaded_library.h, line 11 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. common/find_loaded_library.h, line 11 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. common/find_resource.cc, line 231 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
It seems easier to simply remove the common/find_resource.cc, line 232 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
The Python test common/find_resource.cc, line 233 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. examples/kuka_iiwa_arm/BUILD.bazel, line 95 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
What is the conclusion of this discussion? For now I haven't updated this PR to take into account what is said here. tools/skylark/drake_cc.bzl, line 530 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. tools/skylark/drake_cc.bzl, line 540 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
I added a fail-fast if this macro is not used in Comments from Reviewable |
Review status: 2 of 10 files reviewed at latest revision, 18 unresolved discussions. common/find_loaded_library.cc, line 33 at r4 (raw file): Previously, soonho-tri (Soonho Kong) wrote…
Done. Comments from Reviewable |
Reviewed 2 of 15 files at r4, 8 of 8 files at r5. examples/kuka_iiwa_arm/BUILD.bazel, line 95 at r4 (raw file): Previously, fbudin69500 (Francois Budin) wrote…
Given Jeremy's comment that "almost all examples will be installed" I think that we'll eventually need the used-by-install-rules-only target to avoid constantly rebuilding examples which don't care about the actual change. For now, I'm OK landing this as is (and seeing how much, if any, significant pain results in terms of compile times). Comments from Reviewable |
Review status: all files reviewed at latest revision, 11 unresolved discussions, some commit checks failed. examples/kuka_iiwa_arm/BUILD.bazel, line 95 at r4 (raw file): Previously, sammy-tri (Sam Creasey) wrote…
Since the examples are linked against a shared library Comments from Reviewable |
Reviewed 1 of 15 files at r4, 7 of 8 files at r5. tools/skylark/drake_cc.bzl, line 540 at r4 (raw file): Previously, fbudin69500 (Francois Budin) wrote…
To clarify: the following would be a bug in code that uses this macro:
This would re-link the Comments from Reviewable |
When an executable depends on `libdrake.so`, it can find the resources in the install tree based on the location of `libdrake.so`. The implementation to find `libdrake.so` is platform specific (MacOS and Linux). In both cases, it finds the location of the library loaded in the process. It extracts its directory and appends its with the relative path to the resource files. This should limit the necessity of programmatically add path to the candidate directory in which the sentinel file is searched.
919355f
to
a422f25
Compare
Review status: 9 of 10 files reviewed at latest revision, 2 unresolved discussions. tools/skylark/drake_cc.bzl, line 540 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
I added some fail-fast checks and some comments. Comments from Reviewable |
Reviewed 1 of 15 files at r4, 1 of 8 files at r5, 1 of 1 files at r6. tools/skylark/drake_cc.bzl, line 550 at r6 (raw file):
BTW The libdrake.so guard is unnecessary -- Bazel will already de-duplicate it for us; though I guess its harmless to keep it here. Comments from Reviewable |
Reviewed 2 of 15 files at r4, 2 of 8 files at r5. Comments from Reviewable |
Review status: all files reviewed at latest revision, 1 unresolved discussion. tools/skylark/drake_cc.bzl, line 550 at r6 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Better have extra guards than not enough :) Comments from Reviewable |
Can this be merged now? I think it is ready. Review status: all files reviewed at latest revision, 1 unresolved discussion. Comments from Reviewable |
Blocked on a sentiment from @jamiesnape, but then yeah LGTM to merge. Review status: all files reviewed at latest revision, all discussions resolved. Comments from Reviewable |
Reviewed 1 of 14 files at r3, 3 of 15 files at r4, 7 of 8 files at r5, 1 of 1 files at r6. Comments from Reviewable |
kuka_plan_runner adds its own path to AddResourceSearchPath. Before this patch,
FindResource()
was only using the environment variable or the current workingdirectory to find resources. No additional resource search path was set.
This is the easy solution and would have to be implemented in each executable. Another solution would be to add the current executable path in the resource search path as part of the process to find resources (in
find_resource.cc
). There is no cross-platform way of doing so without usingargv[0]
but one could use this solution which implements a solution for Linux and MacOS. If Windows support was added todrake
, one could useGetModuleFileName
.This change is