Skip to content

Commit

Permalink
Reduce Boost dependencies ECFLOW-1922
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosbento authored Dec 1, 2023
2 parents d3a0556 + 46dbf05 commit 6689ac7
Show file tree
Hide file tree
Showing 154 changed files with 420 additions and 648 deletions.
2 changes: 2 additions & 0 deletions ACore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ set(srcs
src/ecflow/core/Extract.hpp
src/ecflow/core/File.hpp
src/ecflow/core/File_r.hpp
src/ecflow/core/Filesystem.hpp
src/ecflow/core/Host.hpp
src/ecflow/core/Indentor.hpp
src/ecflow/core/Log.hpp
Expand Down Expand Up @@ -74,6 +75,7 @@ set(srcs
src/ecflow/core/Extract.cpp
src/ecflow/core/File.cpp
src/ecflow/core/File_r.cpp
src/ecflow/core/Filesystem.cpp
src/ecflow/core/Host.cpp
src/ecflow/core/Indentor.cpp
src/ecflow/core/Log.cpp
Expand Down
7 changes: 2 additions & 5 deletions ACore/src/ecflow/core/EcfPortLock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#include <iostream>
#include <sstream>

#include <boost/filesystem.hpp>
#include <boost/filesystem/operations.hpp>

#include "ecflow/core/Converter.hpp"
#include "ecflow/core/File.hpp"

Expand All @@ -33,7 +30,7 @@ class EcfPortLock {
public:
static bool is_free(int port, bool debug = false) {
std::string the_port = ecf::convert_to<std::string>(port);
if (boost::filesystem::exists(port_file(the_port))) {
if (fs::exists(port_file(the_port))) {
if (debug)
std::cout << " EcfPortLock::is_free(" << port << ") returning FALSE\n ";
return false;
Expand All @@ -59,7 +56,7 @@ class EcfPortLock {
std::string the_file = port_file(the_port);
// std::cout << "EcfPortLock::remove " << the_file << "
// --------------------------------------------------\n";
boost::filesystem::remove(the_file);
fs::remove(the_file);
}

private:
Expand Down
39 changes: 19 additions & 20 deletions ACore/src/ecflow/core/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

using namespace std;
using namespace boost;
namespace fs = boost::filesystem;

// #define DEBUG_SERVER_PATH 1
// #define DEBUG_CLIENT_PATH 1
Expand Down Expand Up @@ -348,9 +347,9 @@ std::string File::stream_error_condition(const std::ios& stream) {
return msg;
}

bool File::find(const boost::filesystem::path& dir_path, // from this directory downwards,
const std::string& file_name, // search for this name,
boost::filesystem::path& path_found // placing path here if found
bool File::find(const fs::path& dir_path, // from this directory downwards,
const std::string& file_name, // search for this name,
fs::path& path_found // placing path here if found
) {
// std::cout << "Searching '" << dir_path << "' for " << file_name << "\n";
if (!fs::exists(dir_path))
Expand All @@ -373,9 +372,9 @@ bool File::find(const boost::filesystem::path& dir_path, // from this directory
return false;
}

void File::findAll(const boost::filesystem::path& dir_path, // from this directory downwards
const std::string& file_name, // search for this name,
std::vector<boost::filesystem::path>& paths_found // placing path here if found
void File::findAll(const fs::path& dir_path, // from this directory downwards
const std::string& file_name, // search for this name,
std::vector<fs::path>& paths_found // placing path here if found
) {
if (!fs::exists(dir_path))
return;
Expand All @@ -394,9 +393,9 @@ void File::findAll(const boost::filesystem::path& dir_path, // from thi
}
}

void File::find_files_with_extn(const boost::filesystem::path& dir_path, // In this directory
const std::string& extn, // find files matching this extension
std::vector<boost::filesystem::path>& paths_found // placing path here if found
void File::find_files_with_extn(const fs::path& dir_path, // In this directory
const std::string& extn, // find files matching this extension
std::vector<fs::path>& paths_found // placing path here if found
) {
if (!fs::exists(dir_path)) {
return;
Expand All @@ -412,9 +411,9 @@ void File::find_files_with_extn(const boost::filesystem::path& dir_path,
}
}

std::string File::findPath(const boost::filesystem::path& dir_path, // from this directory downwards
const std::string& file_name, // search for this name,
const std::string& leafDir // path must contain this string
std::string File::findPath(const fs::path& dir_path, // from this directory downwards
const std::string& file_name, // search for this name,
const std::string& leafDir // path must contain this string
) {
std::vector<fs::path> paths;
File::findAll(dir_path, file_name, paths);
Expand All @@ -430,9 +429,9 @@ std::string File::findPath(const boost::filesystem::path& dir_path, // from this
return std::string();
}

std::string File::findPath(const boost::filesystem::path& dir_path, // from this directory downwards
const std::string& file_name, // search for this name,
const std::vector<std::string>& tokens // path must contain all these tokens
std::string File::findPath(const fs::path& dir_path, // from this directory downwards
const std::string& file_name, // search for this name,
const std::vector<std::string>& tokens // path must contain all these tokens
) {
std::vector<fs::path> paths;
File::findAll(dir_path, file_name, paths);
Expand Down Expand Up @@ -801,7 +800,7 @@ std::string File::forwardSearch(const std::string& rootPath, const std::string&
}

// Remove a directory recursively ****
bool File::removeDir(const boost::filesystem::path& p) {
bool File::removeDir(const fs::path& p) {
try {
fs::directory_iterator end;
for (fs::directory_iterator it(p); it != end; ++it) {
Expand Down Expand Up @@ -832,9 +831,9 @@ bool File::removeDir(const boost::filesystem::path& p) {

static std::string bjam_workspace_dir() {
// We need the *SAME* location so that different process find the same file. Get to the workspace directory
boost::filesystem::path current_path = boost::filesystem::current_path();
std::string stem = current_path.stem().string();
int count = 0;
auto current_path = fs::current_path();
std::string stem = current_path.stem().string();
int count = 0;
while (stem.find("ecflow") == std::string::npos) {
current_path = current_path.parent_path();
stem = current_path.stem().string();
Expand Down
42 changes: 23 additions & 19 deletions ACore/src/ecflow/core/File.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
#include <string>
#include <vector>

#include <boost/core/noncopyable.hpp>
#include <boost/filesystem/path.hpp>
#include "ecflow/core/Filesystem.hpp"

namespace ecf {

class File : private boost::noncopyable {
class File {
public:
File() = default;
File(const File&) = delete;

File& operator=(const File&) = delete;

static size_t MAX_LINES(); // max number of lines, default to 10000
static const std::string& JOB_EXTN(); // ".job"
static const std::string& MAN_EXTN(); // ".man"
Expand Down Expand Up @@ -74,34 +78,34 @@ class File : private boost::noncopyable {
/// recursively look for a file, given a starting directory
/// Return the first file that matches
/// return true if file found false otherwise
static bool find(const boost::filesystem::path& dir_path, // from this directory downwards
const std::string& file_name, // search for this name,
boost::filesystem::path& path_found // placing path here if found
static bool find(const fs::path& dir_path, // from this directory downwards
const std::string& file_name, // search for this name,
fs::path& path_found // placing path here if found
);

/// recursively look for a file, given a starting directory
/// Returns _ALL_ files that match
static void findAll(const boost::filesystem::path& dir_path, // from this directory downwards
const std::string& file_name, // search for this name,
std::vector<boost::filesystem::path>& paths_found // placing path here if found
static void findAll(const fs::path& dir_path, // from this directory downwards
const std::string& file_name, // search for this name,
std::vector<fs::path>& paths_found // placing path here if found
);

/// Find all files with given extension must include leading .
static void find_files_with_extn(const boost::filesystem::path& dir_path, // In this directory
const std::string& extn, // find files matching this extension
std::vector<boost::filesystem::path>& paths_found // placing path here if found
static void find_files_with_extn(const fs::path& dir_path, // In this directory
const std::string& extn, // find files matching this extension
std::vector<fs::path>& paths_found // placing path here if found
);

/// recursively look for a file, given a starting directory and path token
/// Returns the first match found
static std::string findPath(const boost::filesystem::path& dir_path, // from this directory downwards
const std::string& file_name, // search for this name,
const std::string& leafDir // path must contain this string
static std::string findPath(const fs::path& dir_path, // from this directory downwards
const std::string& file_name, // search for this name,
const std::string& leafDir // path must contain this string
);

static std::string findPath(const boost::filesystem::path& dir_path, // from this directory downwards
const std::string& file_name, // search for this name,
const std::vector<std::string>& tokens // path must contain all these tokens
static std::string findPath(const fs::path& dir_path, // from this directory downwards
const std::string& file_name, // search for this name,
const std::vector<std::string>& tokens // path must contain all these tokens
);

/// Create missing directories. This is *NOT* the same as boost::create_directories
Expand Down Expand Up @@ -148,7 +152,7 @@ class File : private boost::noncopyable {
forwardSearch(const std::string& rootPath, const std::string& nodePath, const std::string& fileExtn);

// Remove a directory recursively ****
static bool removeDir(const boost::filesystem::path& p);
static bool removeDir(const fs::path& p);

// Locate the path to the server exe
static std::string find_ecf_server_path();
Expand Down
11 changes: 11 additions & 0 deletions ACore/src/ecflow/core/Filesystem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright 2023- ECMWF.
*
* This software is licensed under the terms of the Apache Licence version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation
* nor does it submit to any jurisdiction.
*/

#include "Filesystem.hpp"
20 changes: 20 additions & 0 deletions ACore/src/ecflow/core/Filesystem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2023- ECMWF.
*
* This software is licensed under the terms of the Apache Licence version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation
* nor does it submit to any jurisdiction.
*/

#ifndef ECFLOW_CORE_FILESYSTEM_HPP
#define ECFLOW_CORE_FILESYSTEM_HPP

#include <cassert>

#include <boost/filesystem.hpp>

namespace fs = boost::filesystem;

#endif
5 changes: 1 addition & 4 deletions ACore/src/ecflow/core/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
#include <stdexcept>
#include <vector>

#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>

#include "ecflow/core/File.hpp"
#include "ecflow/core/Filesystem.hpp"
#include "ecflow/core/Indentor.hpp"
#include "ecflow/core/Str.hpp"
#include "ecflow/core/TimeStamp.hpp"

using namespace std;
namespace fs = boost::filesystem;

namespace ecf {

Expand Down
8 changes: 4 additions & 4 deletions ACore/src/ecflow/core/PrintStyle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ class PrintStyle {
NET = 4
};

PrintStyle() = delete;
PrintStyle(const PrintStyle&) = delete;
explicit PrintStyle(Type_t t) : old_style_(getStyle()) { setStyle(t); }
~PrintStyle() { setStyle(old_style_); } // reset to old style on destruction

PrintStyle& operator=(const PrintStyle&) = delete;

/// We want to control the output, so that we can dump in old style defs format
/// or choose to dump for debug.
static Type_t getStyle();
Expand All @@ -52,10 +56,6 @@ class PrintStyle {
static std::string to_string();
static std::string to_string(PrintStyle::Type_t);

private:
PrintStyle(const PrintStyle&) = delete;
const PrintStyle& operator=(const PrintStyle&) = delete;

private:
Type_t old_style_;
};
Expand Down
3 changes: 1 addition & 2 deletions ACore/test/TestCereal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@

#include <iostream>

#include <boost/filesystem/operations.hpp>
#include <boost/test/unit_test.hpp>

#include "ecflow/core/Filesystem.hpp"
#include "ecflow/core/SerializationTest.hpp"

using namespace ecf;
using namespace boost;
using namespace std;
namespace fs = boost::filesystem;

class MyClass {
public:
Expand Down
3 changes: 1 addition & 2 deletions ACore/test/TestCerealOptionalNVP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@

#include <iostream>

#include <boost/filesystem/operations.hpp>
#include <boost/test/unit_test.hpp>

#include "ecflow/core/Filesystem.hpp"
#include "ecflow/core/SerializationTest.hpp"

using namespace ecf;
using namespace boost;
using namespace std;
namespace fs = boost::filesystem;

class Base {
public:
Expand Down
3 changes: 1 addition & 2 deletions ACore/test/TestCerealWithHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
* nor does it submit to any jurisdiction.
*/

#include <boost/filesystem/operations.hpp>
#include <boost/test/unit_test.hpp>

#include "ecflow/core/Filesystem.hpp"
#include "ecflow/core/Serialization.hpp"

using namespace ecf;
using namespace boost;
using namespace std;
namespace fs = boost::filesystem;

// ======================================================================================

Expand Down
6 changes: 2 additions & 4 deletions ACore/test/TestFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <iostream>
#include <string>

#include <boost/filesystem/operations.hpp>
#include <boost/test/unit_test.hpp>

#include "ecflow/core/Converter.hpp"
Expand All @@ -32,7 +31,6 @@
using namespace boost;
using namespace std;
using namespace ecf;
namespace fs = boost::filesystem;

BOOST_AUTO_TEST_SUITE(CoreTestSuite)

Expand Down Expand Up @@ -537,14 +535,14 @@ BOOST_AUTO_TEST_CASE(test_get_all_files_by_extension) {
cout << "ACore:: ...test_get_all_files_by_extension\n";
{
std::string rootPath = File::test_data("ACore/test/data/badPasswdFiles", "ACore");
std::vector<boost::filesystem::path> vec;
std::vector<fs::path> vec;
File::find_files_with_extn(rootPath, ".passwd", vec);
// for(auto& file: vec) std::cout << file << "\n";
BOOST_REQUIRE_MESSAGE(vec.size() == 6, "Expected 6 files in directory " << rootPath);
}
{
std::string rootPath = File::test_data("ACore/test/data/badWhiteListFiles", "ACore");
std::vector<boost::filesystem::path> vec;
std::vector<fs::path> vec;
File::find_files_with_extn(rootPath, ".lists", vec);
// for(auto& file: vec) std::cout << file << "\n";
BOOST_REQUIRE_MESSAGE(vec.size() == 7, "Expected 7 files in directory " << rootPath);
Expand Down
3 changes: 0 additions & 3 deletions ACore/test/TestLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include <stdexcept>
#include <string>

#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/test/unit_test.hpp>

#include "ecflow/core/DurationTimer.hpp"
Expand All @@ -24,7 +22,6 @@
using namespace ecf;
using namespace std;
using namespace boost;
namespace fs = boost::filesystem;

BOOST_AUTO_TEST_SUITE(CoreTestSuite)

Expand Down
Loading

0 comments on commit 6689ac7

Please sign in to comment.