1 // Copyright 2021 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 /////////////////////////////////////////////////////////////////////////////// 16 17 #include "tink/internal/test_file_util.h" 18 19 #include <iostream> 20 #include <string> 21 22 #include "absl/strings/str_cat.h" 23 #include "absl/strings/string_view.h" 24 #include "tools/cpp/runfiles/runfiles.h" 25 26 namespace crypto { 27 namespace tink { 28 namespace internal { 29 30 using ::bazel::tools::cpp::runfiles::Runfiles; 31 RunfilesPath(absl::string_view path)32std::string RunfilesPath(absl::string_view path) { 33 std::string error; 34 std::unique_ptr<Runfiles> runfiles(Runfiles::CreateForTest(&error)); 35 if (runfiles == nullptr) { 36 std::clog << "Unable to determine runfile path: " << error; 37 exit(1); 38 } 39 40 const char* workspace_dir = getenv("TEST_WORKSPACE"); 41 if (workspace_dir == nullptr || workspace_dir[0] == '\0') { 42 std::clog << "Unable to determine workspace name." << std::endl; 43 exit(1); 44 } 45 46 return runfiles->Rlocation(absl::StrCat(workspace_dir, "/", path)); 47 } 48 49 } // namespace internal 50 } // namespace tink 51 } // namespace crypto 52