1 // Copyright 2023 The gRPC Authors. 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 #ifndef GRPC_TEST_CPP_UTIL_WINDOWS_MANIFEST_FILE_H 16 #define GRPC_TEST_CPP_UTIL_WINDOWS_MANIFEST_FILE_H 17 18 #include <grpc/support/port_platform.h> 19 20 #ifdef GPR_WINDOWS 21 22 #include <fstream> 23 #include <string> 24 #include <unordered_map> 25 26 namespace grpc { 27 namespace testing { 28 29 std::string NormalizeFilePath(const std::string& filepath); 30 31 // This class is used for handling Runfiles for a Bazel target on Windows (e.g. 32 // the output of targets specified in the data attribute of the target). On 33 // Linux/macOS, Bazel creates a runfiles tree which contains symlinks to the 34 // actual runfiles. But on Windows, it only creates a MANIFEST file which 35 // contains a list of <symlink relative path, absolute symlink target path>. 36 // Thus one initializes a ManifestFile object with the filepath to a MANIFEST 37 // file and uses it as a key-value datastore by querying the absolute symlink 38 // target path with the imaginative symlink relative path. See 39 // https://github.com/bazelbuild/bazel/issues/4261#issuecomment-350723457 for 40 // more details. 41 class ManifestFile { 42 public: 43 explicit ManifestFile(const std::string& filepath); 44 45 std::string Get(const std::string& key); 46 47 private: 48 std::fstream filestream_; 49 std::unordered_map<std::string, std::string> cache_; 50 }; 51 52 } // namespace testing 53 } // namespace grpc 54 55 #endif // GPR_WINDOWS 56 57 #endif // GRPC_TEST_CPP_UTIL_WINDOWS_MANIFEST_FILE_H 58