blob: d47bc0840e1b6f5e555a0fefdc593eb0a5ae610c [file] [log] [blame] [edit]
#include <fstream>
#include <iostream>
#include <string>
#include "rules_cc/cc/runfiles/runfiles.h"
using rules_cc::cc::runfiles::Runfiles;
inline constexpr std::string_view someFile = "examples/runfile.txt";
int main(int argc, char** argv) {
std::string error;
const auto runfiles =
Runfiles::Create(argv[0], BAZEL_CURRENT_REPOSITORY, &error);
if (runfiles == nullptr) {
std::cerr << "Failed to create Runfiles object" << error << "\n";
return 1;
}
std::string root = BAZEL_CURRENT_REPOSITORY;
if (root == "") {
root = "_main";
}
const std::string realPathToSomeFile =
runfiles->Rlocation(root + "/" + std::string{someFile});
std::cout << "The content of the runfile is:" << std::endl
<< std::ifstream(realPathToSomeFile).rdbuf();
return 0;
}