Skip to content

Commit

Permalink
refactor: replace boost filesystem with std (#1569)
Browse files Browse the repository at this point in the history
since `std::filesystem` is fairly established by now, this PR switches out `boost::filesystem` completely.

there is no `unique_path` in `std` because of security concerns and I replaced it by a known path in the systems temporary.

this also adds `cmake/FindFilesystem.cmake` because gcc8 will not link to `stdc++fs` or `c++fs` automatically. as soon as gcc8 is not relevant for us or downstream we can remove it.
  • Loading branch information
andiwand committed Oct 5, 2022
1 parent c27fa44 commit f7c5dce
Show file tree
Hide file tree
Showing 20 changed files with 288 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ jobs:
- name: ccache stats
run: ccache -s
- name: Unit tests
run: ${SETUP} && ${PRELOAD} && cmake --build build --target test
run: ${SETUP} && cmake --build build --target test
- name: Integration tests
run: ${SETUP} && cmake --build build --target integrationtests
- name: Install
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,8 @@ set(_acts_tbb_version 2020.1)
# required packages
if (ACTS_SETUP_BOOST)
if (ACTS_USE_SYSTEM_BOOST)
# NOTE we use boost::filesystem instead of std::filesystem since the later
# is not uniformly supported even on compilers that nominally support C++17
# NOTE FindBoost.cmake looks for BoostConfig.cmake first, before running it's own logic.
find_package(Boost ${_acts_boost_version} REQUIRED COMPONENTS filesystem program_options unit_test_framework)
find_package(Boost ${_acts_boost_version} REQUIRED COMPONENTS program_options unit_test_framework)
else()
add_subdirectory(thirdparty/boost)
endif()
Expand All @@ -203,6 +201,8 @@ if (ACTS_SETUP_VECMEM)
endif()
endif()

find_package(Filesystem REQUIRED)

# the `<project_name>_VERSION` variables set by `setup(... VERSION ...)` have
# only local scope, i.e. they are not accessible her for dependencies added
# via `add_subdirectory`. this overrides the `project(...)` funcion for
Expand Down
2 changes: 1 addition & 1 deletion Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ add_subdirectory(Framework)
add_subdirectory(Io)
add_subdirectory(Run)
add_subdirectory_if(Python ACTS_BUILD_EXAMPLES_PYTHON_BINDINGS)
add_subdirectory_if(Scripts ACTS_BUILD_ANALYSIS_APPS)
add_subdirectory_if(Scripts ACTS_BUILD_ANALYSIS_APPS)
2 changes: 1 addition & 1 deletion Examples/Detectors/MagneticField/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ target_link_libraries(
# the ROOT libraries should be private, but if we do that then the linker
# fails with some missing ROOT symbols.
PUBLIC ActsCore ActsExamplesFramework ROOT::Core ROOT::Tree
PRIVATE Boost::filesystem Boost::program_options)
PRIVATE Boost::program_options std::filesystem)

install(
TARGETS ActsExamplesMagneticField
Expand Down
4 changes: 2 additions & 2 deletions Examples/Detectors/MagneticField/src/MagneticFieldOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
#include "ActsExamples/MagneticField/ScalableBFieldService.hpp"
#include "ActsExamples/Utilities/Options.hpp"

#include <filesystem>
#include <memory>
#include <stdexcept>
#include <string>

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

void ActsExamples::Options::addMagneticFieldOptions(Description& desc) {
Expand Down Expand Up @@ -103,7 +103,7 @@ void ActsExamples::Options::setupMagneticFieldServices(const Variables& vars,
std::shared_ptr<Acts::MagneticFieldProvider>
ActsExamples::Options::readMagneticField(const Variables& vars) {
using namespace ActsExamples::detail;
using boost::filesystem::path;
using std::filesystem::path;

ACTS_LOCAL_LOGGER(
Acts::getDefaultLogger("MagneticField", Acts::Logging::INFO));
Expand Down
2 changes: 1 addition & 1 deletion Examples/Framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ target_include_directories(
target_link_libraries(
ActsExamplesFramework
PUBLIC ActsCore ActsFatras Boost::boost ROOT::Core ROOT::Hist
PRIVATE Boost::filesystem dfelibs)
PRIVATE dfelibs std::filesystem)
target_compile_definitions(
ActsExamplesFramework
PRIVATE BOOST_FILESYSTEM_NO_DEPRECATED)
Expand Down
13 changes: 6 additions & 7 deletions Examples/Framework/src/Utilities/Paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@

#include <charconv>
#include <cstdio>
#include <filesystem>
#include <regex>
#include <sstream>
#include <stdexcept>

#include <boost/filesystem.hpp>

std::string ActsExamples::ensureWritableDirectory(const std::string& dir) {
using boost::filesystem::current_path;
using boost::filesystem::path;
using std::filesystem::current_path;
using std::filesystem::path;

auto dir_path = dir.empty() ? current_path() : path(dir);
if (exists(dir_path) and not is_directory(dir_path)) {
Expand Down Expand Up @@ -56,9 +55,9 @@ std::string ActsExamples::perEventFilepath(const std::string& dir,

std::pair<size_t, size_t> ActsExamples::determineEventFilesRange(
const std::string& dir, const std::string& name) {
using boost::filesystem::current_path;
using boost::filesystem::directory_iterator;
using boost::filesystem::path;
using std::filesystem::current_path;
using std::filesystem::directory_iterator;
using std::filesystem::path;

ACTS_LOCAL_LOGGER(
Acts::getDefaultLogger("EventFilesRange", Acts::Logging::INFO));
Expand Down
6 changes: 3 additions & 3 deletions Examples/Python/src/MagneticField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#include "ActsExamples/MagneticField/FieldMapRootIo.hpp"
#include "ActsExamples/MagneticField/FieldMapTextIo.hpp"

#include <filesystem>
#include <memory>

#include <boost/filesystem.hpp>
#include <pybind11/pybind11.h>

namespace py = pybind11;
Expand Down Expand Up @@ -86,7 +86,7 @@ void addMagneticField(Context& ctx) {
"MagneticFieldMapXyz",
[](std::string filename, std::string tree, double lengthUnit,
double BFieldUnit, bool firstOctant) {
const boost::filesystem::path file = filename;
const std::filesystem::path file = filename;

auto mapBins = [](std::array<size_t, 3> bins,
std::array<size_t, 3> sizes) {
Expand Down Expand Up @@ -119,7 +119,7 @@ void addMagneticField(Context& ctx) {
"MagneticFieldMapRz",
[](std::string filename, std::string tree, double lengthUnit,
double BFieldUnit, bool firstQuadrant) {
const boost::filesystem::path file = filename;
const std::filesystem::path file = filename;

auto mapBins = [](std::array<size_t, 2> bins,
std::array<size_t, 2> sizes) {
Expand Down
3 changes: 2 additions & 1 deletion Examples/Run/Alignment/Common/DetectorAlignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
#include "ActsExamples/Utilities/Options.hpp"
#include "ActsExamples/Utilities/Paths.hpp"

#include <filesystem>
#include <memory>

using namespace Acts::UnitLiterals;
using namespace ActsExamples;
using namespace boost::filesystem;
using namespace std::filesystem;

void addAlignmentOptions(ActsExamples::Options::Description& desc) {
using boost::program_options::value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
#include "ActsExamples/TruthTracking/ParticleSmearingOptions.hpp"
#include "ActsExamples/Utilities/Options.hpp"

#include <filesystem>
#include <memory>
#include <string>

#include <boost/filesystem.hpp>

/// Setup sim hit csv reader
///
/// @param vars The configuration variables
Expand Down
5 changes: 2 additions & 3 deletions Examples/Run/Reconstruction/Common/RecCKFTracks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@
#include "ActsExamples/Utilities/Paths.hpp"
#include <Acts/Definitions/Units.hpp>

#include <filesystem>
#include <memory>

#include <boost/filesystem.hpp>

using namespace Acts::UnitLiterals;
using namespace ActsExamples;
using namespace boost::filesystem;
using namespace std::filesystem;
using namespace std::placeholders;

void addRecCKFOptions(ActsExamples::Options::Description& desc) {
Expand Down
1 change: 1 addition & 0 deletions Plugins/ExaTrkX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ target_link_libraries(
PRIVATE
${TORCH_LIBRARIES}
frnn
std::filesystem
)

if(ACTS_EXATRKX_ENABLE_ONNX)
Expand Down
5 changes: 3 additions & 2 deletions Plugins/ExaTrkX/src/ExaTrkXTrackFindingOnnx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

#include "Acts/Plugins/ExaTrkX/ExaTrkXTrackFindingOnnx.hpp"

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

#include <core/session/onnxruntime_cxx_api.h>
#include <cuda.h>
#include <cuda_runtime_api.h>
Expand All @@ -31,7 +32,7 @@ Acts::ExaTrkXTrackFindingOnnx::ExaTrkXTrackFindingOnnx(const Config& config)

m_env = std::make_unique<Ort::Env>(ORT_LOGGING_LEVEL_WARNING, "ExaTrkX");

using Path = boost::filesystem::path;
using Path = std::filesystem::path;
const Path embedModelPath = Path(m_cfg.modelDir) / "embedding.onnx";
const Path filterModelPath = Path(m_cfg.modelDir) / "filtering.onnx";
const Path gnnModelPath = Path(m_cfg.modelDir) / "gnn.onnx";
Expand Down
5 changes: 3 additions & 2 deletions Plugins/ExaTrkX/src/ExaTrkXTrackFindingTorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

#include "Acts/Plugins/ExaTrkX/ExaTrkXTrackFindingTorch.hpp"

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

#include <cuda.h>
#include <cuda_runtime.h>
#include <cuda_runtime_api.h>
Expand Down Expand Up @@ -46,7 +47,7 @@ namespace Acts {
ExaTrkXTrackFindingTorch::ExaTrkXTrackFindingTorch(
const ExaTrkXTrackFindingTorch::Config& config)
: ExaTrkXTrackFindingBase("ExaTrkXTorch"), m_cfg(config) {
using Path = boost::filesystem::path;
using Path = std::filesystem::path;

const Path embedModelPath = Path(m_cfg.modelDir) / "embed.pt";
const Path filterModelPath = Path(m_cfg.modelDir) / "filter.pt";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

#include "Acts/Tests/CommonHelpers/DataDirectory.hpp"

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

std::string Acts::Test::getDataPath(const std::string& relativePath) {
using boost::filesystem::path;
using std::filesystem::path;

path dataDir(ACTS_TEST_DATA_DIR);
path absPath = dataDir / path(relativePath);
Expand Down
2 changes: 1 addition & 1 deletion Tests/CommonHelpers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ target_include_directories(
target_link_libraries(
ActsTestsCommonHelpers
PUBLIC ActsCore
PRIVATE Boost::filesystem)
PRIVATE std::filesystem)
11 changes: 5 additions & 6 deletions Tests/UnitTests/Core/Utilities/BoundingBoxTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
#include "Acts/Utilities/Ray.hpp"
#include "Acts/Visualization/PlyVisualization3D.hpp"

#include <cstdio>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <map>
#include <memory>
#include <random>
#include <set>

#include <boost/filesystem.hpp>

namespace Acts {
namespace Test {

Expand All @@ -39,10 +39,9 @@ using Vector2F = Eigen::Matrix<BoundingBoxScalar, 2, 1>;
using Vector3F = Eigen::Matrix<BoundingBoxScalar, 3, 1>;
using AngleAxis3F = Eigen::AngleAxis<BoundingBoxScalar>;

boost::filesystem::path tmp_path = []() {
auto p = boost::filesystem::temp_directory_path() /
boost::filesystem::unique_path();
boost::filesystem::create_directory(p);
std::filesystem::path tmp_path = []() {
auto p = std::filesystem::temp_directory_path() / "acts_unit_tests";
std::filesystem::create_directory(p);
std::cout << "Writing test output to: " << p << std::endl;
return p;
}();
Expand Down
2 changes: 1 addition & 1 deletion Tests/UnitTests/Core/Utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_unittest(BinningData BinningDataTests.cpp)
add_unittest(BinUtility BinUtilityTests.cpp)

add_unittest(BoundingBox BoundingBoxTest.cpp)
target_link_libraries(ActsUnitTestBoundingBox PRIVATE Boost::filesystem)
target_link_libraries(ActsUnitTestBoundingBox PRIVATE std::filesystem)

add_unittest(Extendable ExtendableTests.cpp)
add_unittest(FiniteStateMachine FiniteStateMachineTests.cpp)
Expand Down

0 comments on commit f7c5dce

Please sign in to comment.