From 0c755460b1cd971a1e138099147cdd7877a95f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Thu, 4 Apr 2019 17:01:37 +0200 Subject: [PATCH] Use std::filesystem instead of boost::filesystem Note that there is no equivalent of boost::filesystem::unique_path(), so I implemented ModFile::unique_path() which does something similar. --- configure.ac | 2 - m4/ax_boost_filesystem.m4 | 118 ------------------------------------- m4/ax_boost_system.m4 | 121 -------------------------------------- src/DataTree.cc | 7 +-- src/DynamicModel.cc | 12 ++-- src/DynamicModel.hh | 4 +- src/DynareMain.cc | 16 ++--- src/DynareMain2.cc | 12 ++-- src/Makefile.am | 2 +- src/ModFile.cc | 49 ++++++++++----- src/ModFile.hh | 8 ++- src/ModelEquationBlock.cc | 2 +- src/ModelTree.cc | 16 ++--- src/ModelTree.hh | 8 +-- src/StaticModel.cc | 8 +-- src/StaticModel.hh | 8 +-- 16 files changed, 78 insertions(+), 315 deletions(-) delete mode 100644 m4/ax_boost_filesystem.m4 delete mode 100644 m4/ax_boost_system.m4 diff --git a/configure.ac b/configure.ac index e34e1ecd..415beb53 100644 --- a/configure.ac +++ b/configure.ac @@ -66,8 +66,6 @@ fi # We need 1.36 because of unordered_{set,hash} used by Dynare++ AX_BOOST_BASE([1.36], [], [AC_MSG_ERROR([Can't find Boost >= 1.36])]) -AX_BOOST_SYSTEM -AX_BOOST_FILESYSTEM CPPFLAGS_SAVED="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" diff --git a/m4/ax_boost_filesystem.m4 b/m4/ax_boost_filesystem.m4 deleted file mode 100644 index c392f9d6..00000000 --- a/m4/ax_boost_filesystem.m4 +++ /dev/null @@ -1,118 +0,0 @@ -# =========================================================================== -# https://www.gnu.org/software/autoconf-archive/ax_boost_filesystem.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_BOOST_FILESYSTEM -# -# DESCRIPTION -# -# Test for Filesystem library from the Boost C++ libraries. The macro -# requires a preceding call to AX_BOOST_BASE. Further documentation is -# available at <http://randspringer.de/boost/index.html>. -# -# This macro calls: -# -# AC_SUBST(BOOST_FILESYSTEM_LIB) -# -# And sets: -# -# HAVE_BOOST_FILESYSTEM -# -# LICENSE -# -# Copyright (c) 2009 Thomas Porschberg <thomas@randspringer.de> -# Copyright (c) 2009 Michael Tindal -# Copyright (c) 2009 Roman Rybalko <libtorrent@romanr.info> -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 27 - -AC_DEFUN([AX_BOOST_FILESYSTEM], -[ - AC_ARG_WITH([boost-filesystem], - AS_HELP_STRING([--with-boost-filesystem@<:@=special-lib@:>@], - [use the Filesystem library from boost - it is possible to specify a certain library for the linker - e.g. --with-boost-filesystem=boost_filesystem-gcc-mt ]), - [ - if test "$withval" = "no"; then - want_boost="no" - elif test "$withval" = "yes"; then - want_boost="yes" - ax_boost_user_filesystem_lib="" - else - want_boost="yes" - ax_boost_user_filesystem_lib="$withval" - fi - ], - [want_boost="yes"] - ) - - if test "x$want_boost" = "xyes"; then - AC_REQUIRE([AC_PROG_CC]) - CPPFLAGS_SAVED="$CPPFLAGS" - CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" - export CPPFLAGS - - LDFLAGS_SAVED="$LDFLAGS" - LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" - export LDFLAGS - - LIBS_SAVED=$LIBS - LIBS="$LIBS $BOOST_SYSTEM_LIB" - export LIBS - - AC_CACHE_CHECK(whether the Boost::Filesystem library is available, - ax_cv_boost_filesystem, - [AC_LANG_PUSH([C++]) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <boost/filesystem/path.hpp>]], - [[using namespace boost::filesystem; - path my_path( "foo/bar/data.txt" ); - return 0;]])], - ax_cv_boost_filesystem=yes, ax_cv_boost_filesystem=no) - AC_LANG_POP([C++]) - ]) - if test "x$ax_cv_boost_filesystem" = "xyes"; then - AC_DEFINE(HAVE_BOOST_FILESYSTEM,,[define if the Boost::Filesystem library is available]) - BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` - if test "x$ax_boost_user_filesystem_lib" = "x"; then - for libextension in `ls -r $BOOSTLIBDIR/libboost_filesystem* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'` ; do - ax_lib=${libextension} - AC_CHECK_LIB($ax_lib, exit, - [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break], - [link_filesystem="no"]) - done - if test "x$link_filesystem" != "xyes"; then - for libextension in `ls -r $BOOSTLIBDIR/boost_filesystem* 2>/dev/null | sed 's,.*/,,' | sed -e 's,\..*,,'` ; do - ax_lib=${libextension} - AC_CHECK_LIB($ax_lib, exit, - [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break], - [link_filesystem="no"]) - done - fi - else - for ax_lib in $ax_boost_user_filesystem_lib boost_filesystem-$ax_boost_user_filesystem_lib; do - AC_CHECK_LIB($ax_lib, exit, - [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break], - [link_filesystem="no"]) - done - - fi - if test "x$ax_lib" = "x"; then - AC_MSG_ERROR(Could not find a version of the library!) - fi - if test "x$link_filesystem" != "xyes"; then - AC_MSG_ERROR(Could not link against $ax_lib !) - fi - fi - - CPPFLAGS="$CPPFLAGS_SAVED" - LDFLAGS="$LDFLAGS_SAVED" - LIBS="$LIBS_SAVED" - fi -]) diff --git a/m4/ax_boost_system.m4 b/m4/ax_boost_system.m4 deleted file mode 100644 index 207d7be8..00000000 --- a/m4/ax_boost_system.m4 +++ /dev/null @@ -1,121 +0,0 @@ -# =========================================================================== -# https://www.gnu.org/software/autoconf-archive/ax_boost_system.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_BOOST_SYSTEM -# -# DESCRIPTION -# -# Test for System library from the Boost C++ libraries. The macro requires -# a preceding call to AX_BOOST_BASE. Further documentation is available at -# <http://randspringer.de/boost/index.html>. -# -# This macro calls: -# -# AC_SUBST(BOOST_SYSTEM_LIB) -# -# And sets: -# -# HAVE_BOOST_SYSTEM -# -# LICENSE -# -# Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de> -# Copyright (c) 2008 Michael Tindal -# Copyright (c) 2008 Daniel Casimiro <dan.casimiro@gmail.com> -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 19 - -AC_DEFUN([AX_BOOST_SYSTEM], -[ - AC_ARG_WITH([boost-system], - AS_HELP_STRING([--with-boost-system@<:@=special-lib@:>@], - [use the System library from boost - it is possible to specify a certain library for the linker - e.g. --with-boost-system=boost_system-gcc-mt ]), - [ - if test "$withval" = "no"; then - want_boost="no" - elif test "$withval" = "yes"; then - want_boost="yes" - ax_boost_user_system_lib="" - else - want_boost="yes" - ax_boost_user_system_lib="$withval" - fi - ], - [want_boost="yes"] - ) - - if test "x$want_boost" = "xyes"; then - AC_REQUIRE([AC_PROG_CC]) - AC_REQUIRE([AC_CANONICAL_BUILD]) - CPPFLAGS_SAVED="$CPPFLAGS" - CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" - export CPPFLAGS - - LDFLAGS_SAVED="$LDFLAGS" - LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" - export LDFLAGS - - AC_CACHE_CHECK(whether the Boost::System library is available, - ax_cv_boost_system, - [AC_LANG_PUSH([C++]) - CXXFLAGS_SAVE=$CXXFLAGS - CXXFLAGS= - - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <boost/system/error_code.hpp>]], - [[boost::system::error_category *a = 0;]])], - ax_cv_boost_system=yes, ax_cv_boost_system=no) - CXXFLAGS=$CXXFLAGS_SAVE - AC_LANG_POP([C++]) - ]) - if test "x$ax_cv_boost_system" = "xyes"; then - AC_SUBST(BOOST_CPPFLAGS) - - AC_DEFINE(HAVE_BOOST_SYSTEM,,[define if the Boost::System library is available]) - BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` - - LDFLAGS_SAVE=$LDFLAGS - if test "x$ax_boost_user_system_lib" = "x"; then - for libextension in `ls -r $BOOSTLIBDIR/libboost_system* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'` ; do - ax_lib=${libextension} - AC_CHECK_LIB($ax_lib, exit, - [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break], - [link_system="no"]) - done - if test "x$link_system" != "xyes"; then - for libextension in `ls -r $BOOSTLIBDIR/boost_system* 2>/dev/null | sed 's,.*/,,' | sed -e 's,\..*,,'` ; do - ax_lib=${libextension} - AC_CHECK_LIB($ax_lib, exit, - [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break], - [link_system="no"]) - done - fi - - else - for ax_lib in $ax_boost_user_system_lib boost_system-$ax_boost_user_system_lib; do - AC_CHECK_LIB($ax_lib, exit, - [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break], - [link_system="no"]) - done - - fi - if test "x$ax_lib" = "x"; then - AC_MSG_ERROR(Could not find a version of the library!) - fi - if test "x$link_system" = "xno"; then - AC_MSG_ERROR(Could not link against $ax_lib !) - fi - fi - - CPPFLAGS="$CPPFLAGS_SAVED" - LDFLAGS="$LDFLAGS_SAVED" - fi -]) diff --git a/src/DataTree.cc b/src/DataTree.cc index 28dbbc6d..ff7712dc 100644 --- a/src/DataTree.cc +++ b/src/DataTree.cc @@ -22,10 +22,7 @@ #include <iostream> #include <regex> -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#include <boost/filesystem.hpp> -#pragma GCC diagnostic pop +#include <filesystem> #include "DataTree.hh" @@ -890,6 +887,6 @@ DataTree::packageDir(const string &package) { regex pat{R"(\.)"}; string dirname = "+" + regex_replace(package, pat, "/+"); - boost::filesystem::create_directories(dirname); + filesystem::create_directories(dirname); return dirname; } diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index c046b914..6ac66420 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -965,7 +965,7 @@ DynamicModel::writeModelEquationsCode(const string &basename, const map_idx_t &m unsigned int instruction_number = 0; bool file_open = false; - boost::filesystem::create_directories(basename + "/model/bytecode"); + filesystem::create_directories(basename + "/model/bytecode"); string main_name = basename + "/model/bytecode/dynamic.cod"; code_file.open(main_name, ios::out | ios::binary | ios::ate); @@ -1233,7 +1233,7 @@ DynamicModel::writeModelEquationsCode_Block(const string &basename, const map_id vector<int> feedback_variables; bool file_open = false; string main_name; - boost::filesystem::create_directories(basename + "/model/bytecode"); + filesystem::create_directories(basename + "/model/bytecode"); if (linear_decomposition) main_name = basename + "/model/bytecode/non_linear.cod"; else @@ -1692,7 +1692,7 @@ DynamicModel::writeDynamicJuliaFile(const string &basename) const void DynamicModel::writeDynamicCFile(const string &basename, const int order) const { - boost::filesystem::create_directories(basename + "/model/src"); + filesystem::create_directories(basename + "/model/src"); string filename = basename + "/model/src/dynamic.c"; string filename_mex = basename + "/model/src/dynamic_mex.c"; ofstream mDynamicModelFile, mDynamicMexFile; @@ -3378,7 +3378,7 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de if (estimation_present) { ofstream KF_index_file; - boost::filesystem::create_directories(basename + "/model/bytecode"); + filesystem::create_directories(basename + "/model/bytecode"); string main_name = basename + "/model/bytecode/kfi"; KF_index_file.open(main_name, ios::out | ios::binary | ios::ate); int n_obs = symbol_table.observedVariablesNbr(); @@ -5343,7 +5343,7 @@ DynamicModel::collectBlockVariables() } void -DynamicModel::writeDynamicFile(const string &basename, bool block, bool linear_decomposition, bool bytecode, bool use_dll, const string &mexext, const boost::filesystem::path &matlabroot, const boost::filesystem::path &dynareroot, int order, bool julia) const +DynamicModel::writeDynamicFile(const string &basename, bool block, bool linear_decomposition, bool bytecode, bool use_dll, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot, int order, bool julia) const { if (block && bytecode) writeModelEquationsCode_Block(basename, map_idx, linear_decomposition); @@ -6702,7 +6702,7 @@ DynamicModel::isChecksumMatching(const string &basename, bool block) const result.process_bytes(private_buffer, strlen(private_buffer)); } - bool basename_dir_exists = !boost::filesystem::create_directory(basename); + bool basename_dir_exists = !filesystem::create_directory(basename); // check whether basename directory exist. If not, create it. // If it does, read old checksum if it exist diff --git a/src/DynamicModel.hh b/src/DynamicModel.hh index 5264a22b..1af8883f 100644 --- a/src/DynamicModel.hh +++ b/src/DynamicModel.hh @@ -23,10 +23,10 @@ using namespace std; #include <fstream> +#include <filesystem> #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wold-style-cast" -#include <boost/filesystem.hpp> #include <boost/crc.hpp> #pragma GCC diagnostic pop @@ -365,7 +365,7 @@ public: void Write_Inf_To_Bin_File_Block(const string &basename, const int &num, int &u_count_int, bool &file_open, bool is_two_boundaries, const bool linear_decomposition) const; //! Writes dynamic model file - void writeDynamicFile(const string &basename, bool block, bool linear_decomposition, bool bytecode, bool use_dll, const string &mexext, const boost::filesystem::path &matlabroot, const boost::filesystem::path &dynareroot, int order, bool julia) const; + void writeDynamicFile(const string &basename, bool block, bool linear_decomposition, bool bytecode, bool use_dll, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot, int order, bool julia) const; //! Writes file containing parameters derivatives void writeParamsDerivativesFile(const string &basename, bool julia) const; diff --git a/src/DynareMain.cc b/src/DynareMain.cc index bc154886..37990b86 100644 --- a/src/DynareMain.cc +++ b/src/DynareMain.cc @@ -23,6 +23,7 @@ #include <vector> #include <string> #include <regex> +#include <filesystem> #include <cstdlib> @@ -32,11 +33,6 @@ #include <unistd.h> -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#include <boost/filesystem.hpp> -#pragma GCC diagnostic pop - #include "ParsingDriver.hh" #include "ExtendedPreprocessorTypes.hh" #include "ConfigFile.hh" @@ -52,8 +48,8 @@ void main2(stringstream &in, const string &basename, bool debug, bool clear_all, bool minimal_workspace, bool compute_xrefs, FileOutputType output_mode, LanguageOutputType lang, int params_derivs_order, bool transform_unary_ops, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple, - const string &mexext, const boost::filesystem::path &matlabroot, - const boost::filesystem::path &dynareroot, bool onlymodel); + const string &mexext, const filesystem::path &matlabroot, + const filesystem::path &dynareroot, bool onlymodel); void main1(const string &filename, const string &basename, istream &modfile, bool debug, bool save_macro, string &save_macro_file, bool no_line_macro, bool no_empty_line_macro, const vector<pair<string, string>> &defines, const vector<string> &path, stringstream ¯o_output); @@ -167,8 +163,8 @@ main(int argc, char **argv) bool jsonderivsimple = false; LanguageOutputType language{LanguageOutputType::matlab}; string mexext; - boost::filesystem::path matlabroot; - boost::filesystem::path dynareroot{argv[0]}; + filesystem::path matlabroot; + filesystem::path dynareroot{argv[0]}; dynareroot = dynareroot.parent_path(); dynareroot = dynareroot / ".." / ".."; bool onlymodel = false; @@ -382,7 +378,7 @@ main(int argc, char **argv) cerr << "Incorrect syntax for matlabroot option" << endl; usage(); } - matlabroot = boost::filesystem::path{s.substr(11)}; + matlabroot = filesystem::path{s.substr(11)}; } else if (s == "onlymodel") onlymodel = true; diff --git a/src/DynareMain2.cc b/src/DynareMain2.cc index 1c0819e4..b5b2e68a 100644 --- a/src/DynareMain2.cc +++ b/src/DynareMain2.cc @@ -18,11 +18,7 @@ */ #include <iostream> - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#include <boost/filesystem.hpp> -#pragma GCC diagnostic pop +#include <filesystem> #include "ParsingDriver.hh" #include "ModFile.hh" @@ -37,12 +33,12 @@ main2(stringstream &in, const string &basename, bool debug, bool clear_all, bool bool minimal_workspace, bool compute_xrefs, FileOutputType output_mode, LanguageOutputType language, int params_derivs_order, bool transform_unary_ops, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple, - const string &mexext, const boost::filesystem::path &matlabroot, - const boost::filesystem::path &dynareroot, bool onlymodel) + const string &mexext, const filesystem::path &matlabroot, + const filesystem::path &dynareroot, bool onlymodel) { ParsingDriver p(warnings, nostrict); - boost::filesystem::remove_all(basename + "/model/json"); + filesystem::remove_all(basename + "/model/json"); // Do parsing and construct internal representation of mod file unique_ptr<ModFile> mod_file = p.parse(in, debug); diff --git a/src/Makefile.am b/src/Makefile.am index 8bf944bd..b14f11a0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -66,7 +66,7 @@ EXTRA_DIST = \ # The -I. is for <FlexLexer.h> dynare_m_CPPFLAGS = $(BOOST_CPPFLAGS) -I. dynare_m_LDFLAGS = $(AM_LDFLAGS) $(BOOST_LDFLAGS) -dynare_m_LDADD = macro/libmacro.a $(BOOST_FILESYSTEM_LIB) $(BOOST_SYSTEM_LIB) +dynare_m_LDADD = macro/libmacro.a -lstdc++fs DynareFlex.cc: DynareFlex.ll $(LEX) -o DynareFlex.cc DynareFlex.ll diff --git a/src/ModFile.cc b/src/ModFile.cc index 00ea67b1..f73291ce 100644 --- a/src/ModFile.cc +++ b/src/ModFile.cc @@ -22,11 +22,9 @@ #include <fstream> #include <typeinfo> #include <cassert> +#include <random> -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#include <boost/filesystem.hpp> -#pragma GCC diagnostic pop +#include <filesystem> #include "ModFile.hh" #include "ConfigFile.hh" @@ -843,8 +841,8 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo bool console, bool nograph, bool nointeractive, const ConfigFile &config_file, bool check_model_changes, bool minimal_workspace, bool compute_xrefs, const string &mexext, - const boost::filesystem::path &matlabroot, - const boost::filesystem::path &dynareroot, bool onlymodel) const + const filesystem::path &matlabroot, + const filesystem::path &dynareroot, bool onlymodel) const { bool hasModelChanged = !dynamic_model.isChecksumMatching(basename, block); if (!check_model_changes) @@ -858,21 +856,21 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo preprocessor is not able to recreate it afterwards (presumably because MATLAB maintains some sort of lock on it). The workaround is to rename it before deleting it. */ - if (boost::filesystem::exists("+" + basename)) + if (filesystem::exists("+" + basename)) { - auto tmp = boost::filesystem::unique_path(); - boost::filesystem::rename("+" + basename, tmp); - boost::filesystem::remove_all(tmp); + auto tmp = unique_path(); + filesystem::rename("+" + basename, tmp); + filesystem::remove_all(tmp); } - boost::filesystem::remove_all(basename + "/model/src"); - boost::filesystem::remove_all(basename + "/model/bytecode"); + filesystem::remove_all(basename + "/model/src"); + filesystem::remove_all(basename + "/model/bytecode"); } ofstream mOutputFile; if (basename.size()) { - boost::filesystem::create_directory("+" + basename); + filesystem::create_directory("+" + basename); string fname = "+" + basename + "/driver.m"; mOutputFile.open(fname, ios::out | ios::binary); if (!mOutputFile.is_open()) @@ -1438,7 +1436,7 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType if (basename.size()) { - boost::filesystem::create_directories(basename + "/model/json"); + filesystem::create_directories(basename + "/model/json"); string fname{basename + "/model/json/modfile.json"}; jsonOutputFile.open(fname, ios::out | ios::binary); if (!jsonOutputFile.is_open()) @@ -1545,7 +1543,7 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType } else { - boost::filesystem::create_directories(basename + "/model/json"); + filesystem::create_directories(basename + "/model/json"); writeJsonFileHelper(basename + "/model/json/static.json", static_output); writeJsonFileHelper(basename + "/model/json/dynamic.json", dynamic_output); @@ -1571,3 +1569,24 @@ ModFile::writeJsonFileHelper(const string &fname, ostringstream &output) const jsonOutput << output.str(); jsonOutput.close(); } + +filesystem::path +ModFile::unique_path() +{ + filesystem::path path; + string possible_characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + random_device rd; + mt19937 generator(rd()); + uniform_int_distribution<int> distribution{0, static_cast<int>(possible_characters.size())-1}; + do + { + constexpr int rand_length = 10; + string rand_str(rand_length, '\0'); + for (auto &dis : rand_str) + dis = possible_characters[distribution(generator)]; + path = filesystem::temp_directory_path() / rand_str; + } + while (filesystem::exists(path)); + + return path; +} diff --git a/src/ModFile.hh b/src/ModFile.hh index 424d76ce..5c3950d1 100644 --- a/src/ModFile.hh +++ b/src/ModFile.hh @@ -131,6 +131,10 @@ private: void writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonderivsimple) const; void writeJsonFileHelper(const string &fname, ostringstream &output) const; vector<expr_t> pac_growth; + /* Generate a random temporary path. Equivalent to + boost::filesystem::unique_path(). Both are insecure, but currently there + is no better portable solution. Maybe in a later C++ standard? */ + static filesystem::path unique_path(); public: //! Add a statement void addStatement(unique_ptr<Statement> st); @@ -164,8 +168,8 @@ public: void writeOutputFiles(const string &basename, bool clear_all, bool clear_global, bool no_log, bool no_warn, bool console, bool nograph, bool nointeractive, const ConfigFile &config_file, bool check_model_changes, bool minimal_workspace, bool compute_xrefs, - const string &mexext, const boost::filesystem::path &matlabroot, - const boost::filesystem::path &dynareroot, bool onlymodel) const; + const string &mexext, const filesystem::path &matlabroot, + const filesystem::path &dynareroot, bool onlymodel) const; void writeExternalFiles(const string &basename, FileOutputType output, LanguageOutputType language) const; void writeExternalFilesJulia(const string &basename, FileOutputType output) const; diff --git a/src/ModelEquationBlock.cc b/src/ModelEquationBlock.cc index f765a897..923a7b27 100644 --- a/src/ModelEquationBlock.cc +++ b/src/ModelEquationBlock.cc @@ -132,7 +132,7 @@ SteadyStateModel::checkPass(ModFileStructure &mod_file_struct, WarningConsolidat void SteadyStateModel::writeLatexSteadyStateFile(const string &basename) const { - boost::filesystem::create_directories(basename + "/latex"); + filesystem::create_directories(basename + "/latex"); ofstream output, content_output; string filename = basename + "/latex/steady_state.tex"; diff --git a/src/ModelTree.cc b/src/ModelTree.cc index 3f3d045c..3015385f 100644 --- a/src/ModelTree.cc +++ b/src/ModelTree.cc @@ -1845,7 +1845,7 @@ ModelTree::Write_Inf_To_Bin_File(const string &filename, void ModelTree::writeLatexModelFile(const string &mod_basename, const string &latex_basename, ExprNodeOutputType output_type, const bool write_equation_tags) const { - boost::filesystem::create_directories(mod_basename + "/latex"); + filesystem::create_directories(mod_basename + "/latex"); ofstream output, content_output; string filename = mod_basename + "/latex/" + latex_basename + ".tex"; @@ -2212,11 +2212,11 @@ ModelTree::matlab_arch(const string &mexext) } void -ModelTree::compileDll(const string &basename, const string &static_or_dynamic, const string &mexext, const boost::filesystem::path &matlabroot, const boost::filesystem::path &dynareroot) +ModelTree::compileDll(const string &basename, const string &static_or_dynamic, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot) { const string opt_flags = "-O3 -g0 --param ira-max-conflict-table-size=1 -fno-forward-propagate -fno-gcse -fno-dce -fno-dse -fno-tree-fre -fno-tree-pre -fno-tree-cselim -fno-tree-dse -fno-tree-dce -fno-tree-pta -fno-gcse-after-reload"; - boost::filesystem::path compiler; + filesystem::path compiler; ostringstream flags; string libs; @@ -2254,7 +2254,7 @@ ModelTree::compileDll(const string &basename, const string &static_or_dynamic, c // Windows flags << " -static-libgcc -static-libstdc++ -shared"; // Put the MinGW environment shipped with Dynare in the path - boost::filesystem::path mingwpath = dynareroot / (string{"mingw"} + (mexext == "mexw32" ? "32" : "64")) / "bin"; + filesystem::path mingwpath = dynareroot / (string{"mingw"} + (mexext == "mexw32" ? "32" : "64")) / "bin"; string newpath = "PATH=" + mingwpath.string() + ';' + string{getenv("PATH")}; if (putenv(const_cast<char *>(newpath.c_str())) != 0) { @@ -2272,12 +2272,12 @@ ModelTree::compileDll(const string &basename, const string &static_or_dynamic, c } } - auto model_dir = boost::filesystem::path{basename} / "model" / "src"; - boost::filesystem::path main_src{model_dir / (static_or_dynamic + ".c")}, + auto model_dir = filesystem::path{basename} / "model" / "src"; + filesystem::path main_src{model_dir / (static_or_dynamic + ".c")}, mex_src{model_dir / (static_or_dynamic + "_mex.c")}; - boost::filesystem::path mex_dir{"+" + basename}; - boost::filesystem::path binary{mex_dir / (static_or_dynamic + "." + mexext)}; + filesystem::path mex_dir{"+" + basename}; + filesystem::path binary{mex_dir / (static_or_dynamic + "." + mexext)}; ostringstream cmd; diff --git a/src/ModelTree.hh b/src/ModelTree.hh index 04c26e95..2e338720 100644 --- a/src/ModelTree.hh +++ b/src/ModelTree.hh @@ -28,11 +28,7 @@ using namespace std; #include <map> #include <ostream> #include <array> - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#include <boost/filesystem.hpp> -#pragma GCC diagnostic pop +#include <filesystem> #include "DataTree.hh" #include "ExtendedPreprocessorTypes.hh" @@ -312,7 +308,7 @@ private: //! Returns the name of the MATLAB architecture given the extension used for MEX files static string matlab_arch(const string &mexext); //! Compiles the MEX file - static void compileDll(const string &basename, const string &static_or_dynamic, const string &mexext, const boost::filesystem::path &matlabroot, const boost::filesystem::path &dynareroot); + static void compileDll(const string &basename, const string &static_or_dynamic, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot); public: ModelTree(SymbolTable &symbol_table_arg, diff --git a/src/StaticModel.cc b/src/StaticModel.cc index 75340e6a..db72b53e 100644 --- a/src/StaticModel.cc +++ b/src/StaticModel.cc @@ -556,7 +556,7 @@ StaticModel::writeModelEquationsCode(const string &basename, map_idx_t map_idx) unsigned int instruction_number = 0; bool file_open = false; - boost::filesystem::create_directories(basename + "/model/bytecode"); + filesystem::create_directories(basename + "/model/bytecode"); string main_name = basename + "/model/bytecode/static.cod"; code_file.open(main_name, ios::out | ios::binary | ios::ate); @@ -733,7 +733,7 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map deriv_node_temp_terms_t tef_terms; bool file_open = false; - boost::filesystem::create_directories(basename + "/model/bytecode"); + filesystem::create_directories(basename + "/model/bytecode"); string main_name = basename + "/model/bytecode/static.cod"; code_file.open(main_name, ios::out | ios::binary | ios::ate); @@ -1889,7 +1889,7 @@ void StaticModel::writeStaticCFile(const string &basename) const { // Writing comments and function definition command - boost::filesystem::create_directories(basename + "/model/src"); + filesystem::create_directories(basename + "/model/src"); string filename = basename + "/model/src/static.c"; string filename_mex = basename + "/model/src/static_mex.c"; @@ -2027,7 +2027,7 @@ StaticModel::writeStaticJuliaFile(const string &basename) const } void -StaticModel::writeStaticFile(const string &basename, bool block, bool bytecode, bool use_dll, const string &mexext, const boost::filesystem::path &matlabroot, const boost::filesystem::path &dynareroot, bool julia) const +StaticModel::writeStaticFile(const string &basename, bool block, bool bytecode, bool use_dll, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot, bool julia) const { if (block && bytecode) writeModelEquationsCode_Block(basename, map_idx, map_idx2); diff --git a/src/StaticModel.hh b/src/StaticModel.hh index 05d66eb4..4b359e94 100644 --- a/src/StaticModel.hh +++ b/src/StaticModel.hh @@ -23,11 +23,7 @@ using namespace std; #include <fstream> - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#include <boost/filesystem.hpp> -#pragma GCC diagnostic pop +#include <filesystem> #include "ModelTree.hh" @@ -200,7 +196,7 @@ public: int &u_count_int, bool &file_open) const; //! Writes static model file - void writeStaticFile(const string &basename, bool block, bool bytecode, bool use_dll, const string &mexext, const boost::filesystem::path &matlabroot, const boost::filesystem::path &dynareroot, bool julia) const; + void writeStaticFile(const string &basename, bool block, bool bytecode, bool use_dll, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot, bool julia) const; //! Write JSON Output (used by PlannerObjectiveStatement) void writeJsonOutput(ostream &output) const; -- GitLab