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

Local data path #231

Closed
vahidk opened this issue Jun 5, 2015 · 1 comment
Closed

Local data path #231

vahidk opened this issue Jun 5, 2015 · 1 comment
Assignees

Comments

@vahidk
Copy link

vahidk commented Jun 5, 2015

I have a binary with some local data:

cc_binary(
name = "sample",
srcs = ["sample.cpp"],
data = glob(["data/test.png"]),
)

I'm wondering how can I get the path to the data directory in C++ code?

Is this a reliable solution: argv[0] + ".run_files/"?

@lberki
Copy link
Contributor

lberki commented Jun 9, 2015

You are off by one slash: argv[0] + ".runfiles". You may also want to do a readlink -f on argv[0], so the most reliable thing is: $(readlink -f $0).runfiles

This gets a bit more complicated if you put a binary in the data attribute of another binary (the same method should work, but alas, it doesn't always), but as long as you are looking at calling binaries on the output of Bazel, you are fine with this mechanism.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants