From d7dcb1f938ebbc16d635b4e622f4bc78bd5db685 Mon Sep 17 00:00:00 2001 From: Jiajun Yao Date: Thu, 4 Aug 2022 21:33:51 -0700 Subject: [PATCH] Replace boost::filesystem with std::filesystem (#27522) This redos #27319 Signed-off-by: Jiajun Yao --- BUILD.bazel | 5 ----- cpp/BUILD.bazel | 1 - cpp/src/ray/config_internal.cc | 3 ++- cpp/src/ray/test/api_test.cc | 11 +++++----- cpp/src/ray/util/function_helper.cc | 22 +++++++++---------- cpp/src/ray/util/function_helper.h | 3 ++- src/ray/common/memory_monitor.h | 2 -- .../plasma/test/fallback_allocator_test.cc | 6 ++--- src/ray/raylet/node_manager.cc | 2 +- src/ray/raylet/worker_pool.cc | 2 +- src/ray/util/event.cc | 4 ++-- src/ray/util/event_test.cc | 8 +++---- 12 files changed, 32 insertions(+), 37 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index d05c87a25..9148c264f 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -676,7 +676,6 @@ cc_library( ":stats_lib", "//src/ray/protobuf:common_cc_proto", "@boost//:asio", - "@boost//:filesystem", "@boost//:system", "@com_github_jupp0r_prometheus_cpp//pull", "@com_google_absl//absl/base:core_headers", @@ -738,7 +737,6 @@ cc_library( ":worker_rpc", "//src/ray/protobuf:common_cc_proto", "@boost//:asio", - "@boost//:filesystem", "@boost//:system", "@com_github_jupp0r_prometheus_cpp//pull", "@com_google_absl//absl/base:core_headers", @@ -1275,7 +1273,6 @@ cc_test( tags = ["team:core"], deps = [ ":plasma_store_server_lib", - "@boost//:filesystem", "@com_google_absl//absl/strings:str_format", "@com_google_googletest//:gtest_main", ], @@ -1449,7 +1446,6 @@ cc_test( tags = ["team:core"], deps = [ ":ray_util", - "@boost//:filesystem", "@boost//:range", "@com_google_googletest//:gtest_main", ], @@ -2230,7 +2226,6 @@ cc_library( ":sha256", "//src/ray/protobuf:event_cc_proto", "@boost//:asio", - "@boost//:filesystem", "@com_github_spdlog//:spdlog", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/debugging:failure_signal_handler", diff --git a/cpp/BUILD.bazel b/cpp/BUILD.bazel index 58e19a5ad..5e95481c8 100644 --- a/cpp/BUILD.bazel +++ b/cpp/BUILD.bazel @@ -177,7 +177,6 @@ cc_test( tags = ["team:core"], deps = [ "ray_api", - "@boost//:filesystem", "@com_google_googletest//:gtest_main", ], ) diff --git a/cpp/src/ray/config_internal.cc b/cpp/src/ray/config_internal.cc index 8961e35c0..9b8d5b0e2 100644 --- a/cpp/src/ray/config_internal.cc +++ b/cpp/src/ray/config_internal.cc @@ -16,6 +16,7 @@ #include #include +#include #include "absl/flags/flag.h" #include "absl/flags/parse.h" @@ -195,7 +196,7 @@ void ConfigInternal::Init(RayConfig &config, int argc, char **argv) { // driver. std::vector absolute_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; } diff --git a/cpp/src/ray/test/api_test.cc b/cpp/src/ray/test/api_test.cc index 5a92ac977..3eb087b40 100644 --- a/cpp/src/ray/test/api_test.cc +++ b/cpp/src/ray/test/api_test.cc @@ -15,11 +15,12 @@ #include #include +#include +#include #include #include #include "../config_internal.h" -#include "boost/filesystem.hpp" #include "ray/util/logging.h" // using namespace ray; @@ -109,7 +110,7 @@ RAY_REMOTE(Counter::FactoryCreate, &Counter::GetList); 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); std::array str_arr{"debug test", "info test", "warning test"}; RAYLOG(DEBUG) << str_arr[0]; @@ -117,8 +118,8 @@ TEST(RayApiTest, LogTest) { RAYLOG(WARNING) << str_arr[2]; RAY_CHECK(true); - for (auto &it : boost::filesystem::directory_iterator(log_path)) { - if (!boost::filesystem::is_directory(it)) { + for (auto &it : std::filesystem::directory_iterator(log_path)) { + if (!std::filesystem::is_directory(it)) { std::ifstream in(it.path().string(), std::ios::binary); std::string line; 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) { diff --git a/cpp/src/ray/util/function_helper.cc b/cpp/src/ray/util/function_helper.cc index b0e7cb0b7..9651278c5 100644 --- a/cpp/src/ray/util/function_helper.cc +++ b/cpp/src/ray/util/function_helper.cc @@ -14,7 +14,6 @@ #include "function_helper.h" -#include #include #include @@ -23,7 +22,7 @@ namespace ray { 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 << "."; auto it = libraries_.find(lib_path.string()); @@ -31,7 +30,7 @@ void FunctionHelper::LoadDll(const boost::filesystem::path &lib_path) { return; } - RAY_CHECK(boost::filesystem::exists(lib_path)) + RAY_CHECK(std::filesystem::exists(lib_path)) << lib_path << " dynamic library not found."; std::shared_ptr lib = nullptr; @@ -119,8 +118,8 @@ std::string FunctionHelper::LoadAllRemoteFunctions(const std::string lib_path, return names_str; } -void FindDynamicLibrary(boost::filesystem::path path, - std::list &dynamic_libraries) { +void FindDynamicLibrary(std::filesystem::path path, + std::list &dynamic_libraries) { #if defined(_WIN32) static const std::unordered_set dynamic_library_extension = {".dll"}; #elif __APPLE__ @@ -129,22 +128,23 @@ void FindDynamicLibrary(boost::filesystem::path path, #else static const std::unordered_set dynamic_library_extension = {".so"}; #endif - auto extension = boost::filesystem::extension(path); - if (dynamic_library_extension.find(extension) != dynamic_library_extension.end()) { + auto extension = path.extension(); + if (dynamic_library_extension.find(extension.string()) != + dynamic_library_extension.end()) { dynamic_libraries.emplace_back(path); } } void FunctionHelper::LoadFunctionsFromPaths(const std::vector &paths) { - std::list dynamic_libraries; + std::list dynamic_libraries; // Lookup dynamic libraries from paths. for (auto path : paths) { - if (boost::filesystem::is_directory(path)) { + if (std::filesystem::is_directory(path)) { 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); } - } else if (boost::filesystem::exists(path)) { + } else if (std::filesystem::exists(path)) { FindDynamicLibrary(path, dynamic_libraries); } else { RAY_LOG(FATAL) << path << " dynamic library not found."; diff --git a/cpp/src/ray/util/function_helper.h b/cpp/src/ray/util/function_helper.h index a63c7097f..ac9ee63e8 100644 --- a/cpp/src/ray/util/function_helper.h +++ b/cpp/src/ray/util/function_helper.h @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -41,7 +42,7 @@ class FunctionHelper { return *instance; } - void LoadDll(const boost::filesystem::path &lib_path); + void LoadDll(const std::filesystem::path &lib_path); void LoadFunctionsFromPaths(const std::vector &paths); const EntryFuntion &GetExecutableFunctions(const std::string &function_name); const EntryFuntion &GetExecutableMemberFunctions(const std::string &function_name); diff --git a/src/ray/common/memory_monitor.h b/src/ray/common/memory_monitor.h index 35afa86f6..b6699e626 100644 --- a/src/ray/common/memory_monitor.h +++ b/src/ray/common/memory_monitor.h @@ -16,8 +16,6 @@ #include -#include - #include "ray/common/asio/instrumented_io_context.h" #include "ray/common/asio/periodical_runner.h" diff --git a/src/ray/object_manager/plasma/test/fallback_allocator_test.cc b/src/ray/object_manager/plasma/test/fallback_allocator_test.cc index d76a2c106..63ed0ccc9 100644 --- a/src/ray/object_manager/plasma/test/fallback_allocator_test.cc +++ b/src/ray/object_manager/plasma/test/fallback_allocator_test.cc @@ -12,18 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include "gtest/gtest.h" #include "ray/object_manager/plasma/plasma_allocator.h" -using namespace boost::filesystem; +using namespace std::filesystem; namespace plasma { namespace { const int64_t kMB = 1024 * 1024; std::string CreateTestDir() { - path directory = temp_directory_path() / unique_path(); + path directory = std::filesystem::temp_directory_path() / GenerateUUIDV4(); create_directories(directory); return directory.string(); } diff --git a/src/ray/raylet/node_manager.cc b/src/ray/raylet/node_manager.cc index 1c4950f87..698573149 100644 --- a/src/ray/raylet/node_manager.cc +++ b/src/ray/raylet/node_manager.cc @@ -16,11 +16,11 @@ #include #include +#include #include #include #include "absl/time/clock.h" -#include "boost/filesystem.hpp" #include "boost/system/error_code.hpp" #include "ray/common/asio/asio_util.h" #include "ray/common/asio/instrumented_io_context.h" diff --git a/src/ray/raylet/worker_pool.cc b/src/ray/raylet/worker_pool.cc index 9674e71d0..59c84114a 100644 --- a/src/ray/raylet/worker_pool.cc +++ b/src/ray/raylet/worker_pool.cc @@ -16,7 +16,7 @@ #include #include -#include +#include #include "ray/common/constants.h" #include "ray/common/network_util.h" diff --git a/src/ray/util/event.cc b/src/ray/util/event.cc index 7523f2957..0902b5a82 100644 --- a/src/ray/util/event.cc +++ b/src/ray/util/event.cc @@ -14,7 +14,7 @@ #include "ray/util/event.h" -#include +#include #include "absl/base/call_once.h" #include "absl/time/time.h" @@ -325,7 +325,7 @@ void RayEventInit(rpc::Event_SourceType source_type, const std::string &event_level) { absl::call_once(init_once_, [&source_type, &custom_fields, &log_dir, &event_level]() { 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( std::make_shared(source_type, event_dir.string())); SetEventLevel(event_level); diff --git a/src/ray/util/event_test.cc b/src/ray/util/event_test.cc index 031138c9e..9543f95e0 100644 --- a/src/ray/util/event_test.cc +++ b/src/ray/util/event_test.cc @@ -14,9 +14,9 @@ #include "ray/util/event.h" -#include #include #include +#include #include #include #include @@ -177,7 +177,7 @@ class EventTest : public ::testing::Test { virtual void TearDown() { TestEventReporter::event_list.clear(); - boost::filesystem::remove_all(log_dir.c_str()); + std::filesystem::remove_all(log_dir.c_str()); EventManager::Instance().ClearReporters(); ray::RayEventContext::Instance().ResetEventContext(); } @@ -424,7 +424,7 @@ TEST_F(EventTest, TestLogRotate) { int cnt = 0; 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) { cnt++; } @@ -607,7 +607,7 @@ TEST_F(EventTest, TestLogEvent) { EXPECT_THAT(vc[1], testing::HasSubstr("Event")); 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. ray::RayLog::StartRayLog("event_test", ray::RayLogLevel::INFO, log_dir);