Open lgalfaso opened 3 months ago
Which Bazel version are you using? I tested on Bazel 7.1.2 and I could see that ${TEST_SRCDIR}/foo/man
does indeed contain the files I expected.
@Wyverald the path depends on whether you are importing the dependency from WORKSPACE
or from MODULE.bazel
. If you are using the former, then you are correct that it will be available at ${TEST_SRCDIR}/foo/man
. If you are using the later following the patter from https://github.com/bazelbuild/bazel/issues/17141#issuecomment-1622343142, then it will be available at ${TEST_SRCDIR}/_main~_foo/man
.
This is using Basel 7.1.2.
That is true. @fmeum do you know if the runfiles library works with ${TEST_SRCDIR}
? And/or what's the best practice here? We should fix the docs.
Yes, runfiles libraries generally also support tests via TEST_SRCDIR
. If you want consistent behavior between WORKSPACE and Bzlmod, try using @bazel_tools//tools/cpp/runfiles
.
+1 to fixing up the docs.
@fmeum is there a way for @bazel_tools//tools/cpp/runfiles
to make a reference to a directory?
You can reference a file in it and then walk up from there. Directory lookups could be added, but that would require a filesystem abstraction that I'm not sure is feasible to implement on C++ (std::filesystem
may support this, but I don't know it well enough).
Having to reference a file, the fact that at the moment there is a (maybe bad) alternative for which this is not needed, makes the option of just using ${TEST_SRCDIR}/_main~_foo/man
much better. This shows the abstraction that Bazel adds, but the alternative feels much hackier.
Page link:
https://bazel.build/concepts/dependencies#data-dependencies
Problem description (include actual vs expected text, if applicable):
The page in the link reads
The reference to
workspace
in this link would make you believe that you can make a reference to any workspace, including the workspace for any dependency.Eg. Say you have a dependency
foo
. This dependency has aBUILD
file at the root that readsSay that
@foo//:bar
contains 1000s of files.Then you have a
cc_test
that you would like to use the files from@foo//:bar
.then following the doc, I would expect for
${TEST_SRCDIR}/foo/man
to be reference to the man directory in@foo//:bar
(for completeness, say that the workspace name of@foo
is"foo"
).This is not the case (and my understanding is that this is not the expected behaviour).
Where do you see this issue? (include link to specific section of the page, if applicable)
No response
Any other information you'd like to share?
No response