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

Fixing issue 21741: Modifying reference documentation #23238

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions src/main/starlark/builtins_bzl/common/cc/attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,37 @@ most build rules</a>.
and that rule's <code>outs</code> are automatically added to
this <code>cc_library</code>'s data files.
</p>
<p>Your C++ code can access these data files like so:</p>
<p>Using the functionality defined by the <code>runfiles.h</code> located under
<code>tools/cpp/runfiles/runfiles.h</code>. This header is provided by the following target
<code>@bazel_tools//cpp/runfiles:runfiles</code> Your C++ code can access these data files,
like so:
</p>
<pre><code class="lang-starlark">
const std::string path = devtools_build::GetDataDependencyFilepath(
Copy link
Member

Choose a reason for hiding this comment

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

This might be internal specific doc. /cc @comius

Copy link
Member

Choose a reason for hiding this comment

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

@pzembrod Can you help address this?

"my/test/data/file");

#include "tools/cpp/runfiles/runfiles.h"

int main(int argc, char** argv) {

try {

using bazel::tools::cpp::runfiles::Runfiles;

std::string error;
std::unique_ptr<Runfiles> runfiles(Runfiles::Create(argv[0], BAZEL_CURRENT_REPOSITORY, &error));

// "cpp_example" is the module name attribute
// "data/example.json" is the path relative from the project root

std::string path = runfiles->Rlocation("cpp_example/data/example.json");

//...

} catch (const std::exception& e) {
// ...
}

return 0;
}
</code></pre>
""",
),
Expand Down