Remove boost::filesystem dependency (#245)

This commit is contained in:
mehrdadn
2016-07-10 19:48:56 +03:00
committed by Robert Nishihara
parent 5db31cd8a2
commit cd92a8d787
2 changed files with 44 additions and 22 deletions
+6 -3
View File
@@ -41,6 +41,9 @@ find_package(NumPy REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(Boost)
include_directories(${Boost_INCLUDE_DIRS}) # This was required to find boost for macports
include_directories("${CMAKE_SOURCE_DIR}/include")
include_directories("/usr/local/include")
include_directories("${CMAKE_SOURCE_DIR}/thirdparty/grpc/include/")
@@ -139,11 +142,11 @@ add_library(pynumbuf STATIC ${CMAKE_SOURCE_DIR}/thirdparty/numbuf/cpp/src/numbuf
target_link_libraries(pynumbuf ${ARROW_LIB} ${PYTHON_LIBRARIES})
add_executable(objstore src/objstore.cc src/ipc.cc src/utils.cc ${GENERATED_PROTOBUF_FILES})
target_link_libraries(objstore ${ARROW_LIB} pynumbuf boost_system boost_filesystem)
target_link_libraries(objstore ${ARROW_LIB} pynumbuf)
add_executable(scheduler src/scheduler.cc src/computation_graph.cc src/utils.cc ${GENERATED_PROTOBUF_FILES})
target_link_libraries(scheduler boost_system boost_filesystem)
target_link_libraries(scheduler)
add_library(raylib SHARED src/raylib.cc src/worker.cc src/ipc.cc src/utils.cc ${GENERATED_PROTOBUF_FILES})
target_link_libraries(raylib ${ARROW_LIB} pynumbuf boost_system boost_filesystem)
target_link_libraries(raylib ${ARROW_LIB} pynumbuf)
get_filename_component(PYTHON_SHARED_LIBRARY ${PYTHON_LIBRARIES} NAME)
if(APPLE)
+38 -19
View File
@@ -1,13 +1,18 @@
#include "utils.h"
#if defined(_CPPLIB_VER) && _CPPLIB_VER >= 650
#include <experimental/filesystem>
#else
#include <boost/filesystem.hpp>
#endif
#include "ray/ray.h"
#include <sys/stat.h>
#ifdef _S_IREAD // Visual C++ runtime?
#include <direct.h> // _mkdir
#else
namespace {
int _mkdir(char const* path) {
return mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO);
}
}
#endif
std::string::iterator split_ip_address(std::string& ip_address) {
if (ip_address[0] == '[') { // IPv6
auto split_end = std::find(ip_address.begin() + 1, ip_address.end(), ']');
@@ -33,18 +38,32 @@ const char* get_cmd_option(char** begin, char** end, const std::string& option)
return 0;
}
void create_log_dir_or_die(const char* log_file_name) {
#ifdef BOOST_FILESYSTEM_FILESYSTEM_HPP
namespace filesystem = boost::filesystem;
typedef boost::system::error_code error_code;
#else
namespace filesystem = std::experimental::filesystem;
typedef std::error_code error_code;
#endif
filesystem::path log_file_path(log_file_name);
error_code returned_error;
filesystem::create_directories(log_file_path.parent_path(), returned_error);
if (returned_error) {
RAY_CHECK(false, "Failed to create directory for " << log_file_name);
void create_directories(const char* log_file_name) {
bool success = _mkdir(log_file_name) != -1 || errno == EEXIST;
if (!success) {
// If we couldn't create it directly and it didn't already exist, then try to create it from the root...
// Note that we keep going until the end even if creating the root fails, because we don't necessarily have access to the root
bool stop = false;
size_t i = 0;
do {
stop = log_file_name[i] == '\0';
bool delimiter = stop || log_file_name[i] == '/' || log_file_name[i] == '\\';
if (!stop) {
++i;
}
if (delimiter) {
std::string ancestor(log_file_name, i);
success = _mkdir(ancestor.c_str()) != -1 || errno == EEXIST;
}
} while (!stop);
}
RAY_CHECK(success, "Failed to create directory for " << log_file_name);
}
void create_log_dir_or_die(const char* log_file_name) {
std::string dirname = log_file_name;
while (!dirname.empty() && dirname.back() != '/' && dirname.back() != '\\') {
dirname.pop_back();
}
return create_directories(dirname.c_str());
}