Replace boost::filesystem with std::filesystem (#27522)

This redos #27319

Signed-off-by: Jiajun Yao <jeromeyjj@gmail.com>
This commit is contained in:
Jiajun Yao 2022-08-04 21:33:51 -07:00 committed by GitHub
parent 1714d0266b
commit d7dcb1f938
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 32 additions and 37 deletions

View file

@ -676,7 +676,6 @@ cc_library(
":stats_lib", ":stats_lib",
"//src/ray/protobuf:common_cc_proto", "//src/ray/protobuf:common_cc_proto",
"@boost//:asio", "@boost//:asio",
"@boost//:filesystem",
"@boost//:system", "@boost//:system",
"@com_github_jupp0r_prometheus_cpp//pull", "@com_github_jupp0r_prometheus_cpp//pull",
"@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/base:core_headers",
@ -738,7 +737,6 @@ cc_library(
":worker_rpc", ":worker_rpc",
"//src/ray/protobuf:common_cc_proto", "//src/ray/protobuf:common_cc_proto",
"@boost//:asio", "@boost//:asio",
"@boost//:filesystem",
"@boost//:system", "@boost//:system",
"@com_github_jupp0r_prometheus_cpp//pull", "@com_github_jupp0r_prometheus_cpp//pull",
"@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/base:core_headers",
@ -1275,7 +1273,6 @@ cc_test(
tags = ["team:core"], tags = ["team:core"],
deps = [ deps = [
":plasma_store_server_lib", ":plasma_store_server_lib",
"@boost//:filesystem",
"@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/strings:str_format",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
@ -1449,7 +1446,6 @@ cc_test(
tags = ["team:core"], tags = ["team:core"],
deps = [ deps = [
":ray_util", ":ray_util",
"@boost//:filesystem",
"@boost//:range", "@boost//:range",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
@ -2230,7 +2226,6 @@ cc_library(
":sha256", ":sha256",
"//src/ray/protobuf:event_cc_proto", "//src/ray/protobuf:event_cc_proto",
"@boost//:asio", "@boost//:asio",
"@boost//:filesystem",
"@com_github_spdlog//:spdlog", "@com_github_spdlog//:spdlog",
"@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/debugging:failure_signal_handler", "@com_google_absl//absl/debugging:failure_signal_handler",

View file

@ -177,7 +177,6 @@ cc_test(
tags = ["team:core"], tags = ["team:core"],
deps = [ deps = [
"ray_api", "ray_api",
"@boost//:filesystem",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
], ],
) )

View file

@ -16,6 +16,7 @@
#include <boost/dll/runtime_symbol_info.hpp> #include <boost/dll/runtime_symbol_info.hpp>
#include <charconv> #include <charconv>
#include <filesystem>
#include "absl/flags/flag.h" #include "absl/flags/flag.h"
#include "absl/flags/parse.h" #include "absl/flags/parse.h"
@ -195,7 +196,7 @@ void ConfigInternal::Init(RayConfig &config, int argc, char **argv) {
// driver. // driver.
std::vector<std::string> absolute_path; std::vector<std::string> absolute_path;
for (const auto &path : code_search_path) { for (const auto &path : code_search_path) {
absolute_path.emplace_back(boost::filesystem::absolute(path).string()); absolute_path.emplace_back(std::filesystem::absolute(path).string());
} }
code_search_path = absolute_path; code_search_path = absolute_path;
} }

View file

@ -15,11 +15,12 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <ray/api.h> #include <ray/api.h>
#include <filesystem>
#include <fstream>
#include <future> #include <future>
#include <thread> #include <thread>
#include "../config_internal.h" #include "../config_internal.h"
#include "boost/filesystem.hpp"
#include "ray/util/logging.h" #include "ray/util/logging.h"
// using namespace ray; // using namespace ray;
@ -109,7 +110,7 @@ RAY_REMOTE(Counter::FactoryCreate,
&Counter::GetList); &Counter::GetList);
TEST(RayApiTest, LogTest) { TEST(RayApiTest, LogTest) {
auto log_path = boost::filesystem::current_path().string() + "/tmp/"; auto log_path = std::filesystem::current_path().string() + "/tmp/";
ray::RayLog::StartRayLog("cpp_worker", ray::RayLogLevel::DEBUG, log_path); ray::RayLog::StartRayLog("cpp_worker", ray::RayLogLevel::DEBUG, log_path);
std::array<std::string, 3> str_arr{"debug test", "info test", "warning test"}; std::array<std::string, 3> str_arr{"debug test", "info test", "warning test"};
RAYLOG(DEBUG) << str_arr[0]; RAYLOG(DEBUG) << str_arr[0];
@ -117,8 +118,8 @@ TEST(RayApiTest, LogTest) {
RAYLOG(WARNING) << str_arr[2]; RAYLOG(WARNING) << str_arr[2];
RAY_CHECK(true); RAY_CHECK(true);
for (auto &it : boost::filesystem::directory_iterator(log_path)) { for (auto &it : std::filesystem::directory_iterator(log_path)) {
if (!boost::filesystem::is_directory(it)) { if (!std::filesystem::is_directory(it)) {
std::ifstream in(it.path().string(), std::ios::binary); std::ifstream in(it.path().string(), std::ios::binary);
std::string line; std::string line;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
@ -128,7 +129,7 @@ TEST(RayApiTest, LogTest) {
} }
} }
boost::filesystem::remove_all(log_path); std::filesystem::remove_all(log_path);
} }
TEST(RayApiTest, TaskOptionsCheckTest) { TEST(RayApiTest, TaskOptionsCheckTest) {

View file

@ -14,7 +14,6 @@
#include "function_helper.h" #include "function_helper.h"
#include <boost/filesystem.hpp>
#include <boost/range/iterator_range.hpp> #include <boost/range/iterator_range.hpp>
#include <memory> #include <memory>
@ -23,7 +22,7 @@
namespace ray { namespace ray {
namespace internal { namespace internal {
void FunctionHelper::LoadDll(const boost::filesystem::path &lib_path) { void FunctionHelper::LoadDll(const std::filesystem::path &lib_path) {
RAY_LOG(INFO) << "Start loading the library " << lib_path << "."; RAY_LOG(INFO) << "Start loading the library " << lib_path << ".";
auto it = libraries_.find(lib_path.string()); auto it = libraries_.find(lib_path.string());
@ -31,7 +30,7 @@ void FunctionHelper::LoadDll(const boost::filesystem::path &lib_path) {
return; return;
} }
RAY_CHECK(boost::filesystem::exists(lib_path)) RAY_CHECK(std::filesystem::exists(lib_path))
<< lib_path << " dynamic library not found."; << lib_path << " dynamic library not found.";
std::shared_ptr<boost::dll::shared_library> lib = nullptr; std::shared_ptr<boost::dll::shared_library> lib = nullptr;
@ -119,8 +118,8 @@ std::string FunctionHelper::LoadAllRemoteFunctions(const std::string lib_path,
return names_str; return names_str;
} }
void FindDynamicLibrary(boost::filesystem::path path, void FindDynamicLibrary(std::filesystem::path path,
std::list<boost::filesystem::path> &dynamic_libraries) { std::list<std::filesystem::path> &dynamic_libraries) {
#if defined(_WIN32) #if defined(_WIN32)
static const std::unordered_set<std::string> dynamic_library_extension = {".dll"}; static const std::unordered_set<std::string> dynamic_library_extension = {".dll"};
#elif __APPLE__ #elif __APPLE__
@ -129,22 +128,23 @@ void FindDynamicLibrary(boost::filesystem::path path,
#else #else
static const std::unordered_set<std::string> dynamic_library_extension = {".so"}; static const std::unordered_set<std::string> dynamic_library_extension = {".so"};
#endif #endif
auto extension = boost::filesystem::extension(path); auto extension = path.extension();
if (dynamic_library_extension.find(extension) != dynamic_library_extension.end()) { if (dynamic_library_extension.find(extension.string()) !=
dynamic_library_extension.end()) {
dynamic_libraries.emplace_back(path); dynamic_libraries.emplace_back(path);
} }
} }
void FunctionHelper::LoadFunctionsFromPaths(const std::vector<std::string> &paths) { void FunctionHelper::LoadFunctionsFromPaths(const std::vector<std::string> &paths) {
std::list<boost::filesystem::path> dynamic_libraries; std::list<std::filesystem::path> dynamic_libraries;
// Lookup dynamic libraries from paths. // Lookup dynamic libraries from paths.
for (auto path : paths) { for (auto path : paths) {
if (boost::filesystem::is_directory(path)) { if (std::filesystem::is_directory(path)) {
for (auto &entry : for (auto &entry :
boost::make_iterator_range(boost::filesystem::directory_iterator(path), {})) { boost::make_iterator_range(std::filesystem::directory_iterator(path), {})) {
FindDynamicLibrary(entry, dynamic_libraries); FindDynamicLibrary(entry, dynamic_libraries);
} }
} else if (boost::filesystem::exists(path)) { } else if (std::filesystem::exists(path)) {
FindDynamicLibrary(path, dynamic_libraries); FindDynamicLibrary(path, dynamic_libraries);
} else { } else {
RAY_LOG(FATAL) << path << " dynamic library not found."; RAY_LOG(FATAL) << path << " dynamic library not found.";

View file

@ -18,6 +18,7 @@
#include <ray/api/ray_runtime_holder.h> #include <ray/api/ray_runtime_holder.h>
#include <boost/dll.hpp> #include <boost/dll.hpp>
#include <filesystem>
#include <memory> #include <memory>
#include <msgpack.hpp> #include <msgpack.hpp>
#include <string> #include <string>
@ -41,7 +42,7 @@ class FunctionHelper {
return *instance; return *instance;
} }
void LoadDll(const boost::filesystem::path &lib_path); void LoadDll(const std::filesystem::path &lib_path);
void LoadFunctionsFromPaths(const std::vector<std::string> &paths); void LoadFunctionsFromPaths(const std::vector<std::string> &paths);
const EntryFuntion &GetExecutableFunctions(const std::string &function_name); const EntryFuntion &GetExecutableFunctions(const std::string &function_name);
const EntryFuntion &GetExecutableMemberFunctions(const std::string &function_name); const EntryFuntion &GetExecutableMemberFunctions(const std::string &function_name);

View file

@ -16,8 +16,6 @@
#include <gtest/gtest_prod.h> #include <gtest/gtest_prod.h>
#include <boost/filesystem.hpp>
#include "ray/common/asio/instrumented_io_context.h" #include "ray/common/asio/instrumented_io_context.h"
#include "ray/common/asio/periodical_runner.h" #include "ray/common/asio/periodical_runner.h"

View file

@ -12,18 +12,18 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <boost/filesystem.hpp> #include <filesystem>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "ray/object_manager/plasma/plasma_allocator.h" #include "ray/object_manager/plasma/plasma_allocator.h"
using namespace boost::filesystem; using namespace std::filesystem;
namespace plasma { namespace plasma {
namespace { namespace {
const int64_t kMB = 1024 * 1024; const int64_t kMB = 1024 * 1024;
std::string CreateTestDir() { std::string CreateTestDir() {
path directory = temp_directory_path() / unique_path(); path directory = std::filesystem::temp_directory_path() / GenerateUUIDV4();
create_directories(directory); create_directories(directory);
return directory.string(); return directory.string();
} }

View file

@ -16,11 +16,11 @@
#include <cctype> #include <cctype>
#include <csignal> #include <csignal>
#include <filesystem>
#include <fstream> #include <fstream>
#include <memory> #include <memory>
#include "absl/time/clock.h" #include "absl/time/clock.h"
#include "boost/filesystem.hpp"
#include "boost/system/error_code.hpp" #include "boost/system/error_code.hpp"
#include "ray/common/asio/asio_util.h" #include "ray/common/asio/asio_util.h"
#include "ray/common/asio/instrumented_io_context.h" #include "ray/common/asio/instrumented_io_context.h"

View file

@ -16,7 +16,7 @@
#include <algorithm> #include <algorithm>
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/filesystem.hpp> #include <fstream>
#include "ray/common/constants.h" #include "ray/common/constants.h"
#include "ray/common/network_util.h" #include "ray/common/network_util.h"

View file

@ -14,7 +14,7 @@
#include "ray/util/event.h" #include "ray/util/event.h"
#include <boost/filesystem.hpp> #include <filesystem>
#include "absl/base/call_once.h" #include "absl/base/call_once.h"
#include "absl/time/time.h" #include "absl/time/time.h"
@ -325,7 +325,7 @@ void RayEventInit(rpc::Event_SourceType source_type,
const std::string &event_level) { const std::string &event_level) {
absl::call_once(init_once_, [&source_type, &custom_fields, &log_dir, &event_level]() { absl::call_once(init_once_, [&source_type, &custom_fields, &log_dir, &event_level]() {
RayEventContext::Instance().SetEventContext(source_type, custom_fields); RayEventContext::Instance().SetEventContext(source_type, custom_fields);
auto event_dir = boost::filesystem::path(log_dir) / boost::filesystem::path("events"); auto event_dir = std::filesystem::path(log_dir) / std::filesystem::path("events");
ray::EventManager::Instance().AddReporter( ray::EventManager::Instance().AddReporter(
std::make_shared<ray::LogEventReporter>(source_type, event_dir.string())); std::make_shared<ray::LogEventReporter>(source_type, event_dir.string()));
SetEventLevel(event_level); SetEventLevel(event_level);

View file

@ -14,9 +14,9 @@
#include "ray/util/event.h" #include "ray/util/event.h"
#include <boost/filesystem.hpp>
#include <boost/range.hpp> #include <boost/range.hpp>
#include <csignal> #include <csignal>
#include <filesystem>
#include <fstream> #include <fstream>
#include <set> #include <set>
#include <thread> #include <thread>
@ -177,7 +177,7 @@ class EventTest : public ::testing::Test {
virtual void TearDown() { virtual void TearDown() {
TestEventReporter::event_list.clear(); TestEventReporter::event_list.clear();
boost::filesystem::remove_all(log_dir.c_str()); std::filesystem::remove_all(log_dir.c_str());
EventManager::Instance().ClearReporters(); EventManager::Instance().ClearReporters();
ray::RayEventContext::Instance().ResetEventContext(); ray::RayEventContext::Instance().ResetEventContext();
} }
@ -424,7 +424,7 @@ TEST_F(EventTest, TestLogRotate) {
int cnt = 0; int cnt = 0;
for (auto &entry : for (auto &entry :
boost::make_iterator_range(boost::filesystem::directory_iterator(log_dir), {})) { boost::make_iterator_range(std::filesystem::directory_iterator(log_dir), {})) {
if (entry.path().string().find("event_RAYLET") != std::string::npos) { if (entry.path().string().find("event_RAYLET") != std::string::npos) {
cnt++; cnt++;
} }
@ -607,7 +607,7 @@ TEST_F(EventTest, TestLogEvent) {
EXPECT_THAT(vc[1], testing::HasSubstr("Event")); EXPECT_THAT(vc[1], testing::HasSubstr("Event"));
EXPECT_THAT(vc[1], testing::HasSubstr("test fatal")); EXPECT_THAT(vc[1], testing::HasSubstr("test fatal"));
boost::filesystem::remove_all(log_dir.c_str()); std::filesystem::remove_all(log_dir.c_str());
// Set log level smaller than event level. // Set log level smaller than event level.
ray::RayLog::StartRayLog("event_test", ray::RayLogLevel::INFO, log_dir); ray::RayLog::StartRayLog("event_test", ray::RayLogLevel::INFO, log_dir);