Fix entity-manager issues against GCC8
move std::experimental::filesystem to std::filesystem, and fix an error
in a function that returns bool, but didn't contain a return statement.
Change-Id: Iaedfc5ea189fa5382e4b29be5854cb72915a742d
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/include/Utils.hpp b/include/Utils.hpp
index 39e3794..176f7ef 100644
--- a/include/Utils.hpp
+++ b/include/Utils.hpp
@@ -15,13 +15,13 @@
*/
#pragma once
-#include <experimental/filesystem>
+#include "filesystem.hpp"
#include <nlohmann/json.hpp>
#include <sdbusplus/exception.hpp>
-bool findFiles(const std::experimental::filesystem::path &dirPath,
+bool findFiles(const std::filesystem::path &dirPath,
const std::string &matchString,
- std::vector<std::experimental::filesystem::path> &foundPaths);
+ std::vector<std::filesystem::path> &foundPaths);
bool validateJson(const nlohmann::json &schemaFile,
const nlohmann::json &input);
diff --git a/include/filesystem.hpp b/include/filesystem.hpp
new file mode 100644
index 0000000..ead619e
--- /dev/null
+++ b/include/filesystem.hpp
@@ -0,0 +1,14 @@
+// this file splices filesystem in depending on the implementation
+
+#if __has_include(<filesystem>)
+#include <filesystem.hpp>
+#elif __has_include(<experimental/filesystem>)
+#include <experimental/filesystem>
+namespace std
+{
+// splice experimental::filesystem into std
+namespace filesystem = std::experimental::filesystem;
+} // namespace std
+#else
+#error filesystem not available
+#endif
\ No newline at end of file
diff --git a/src/EntityManager.cpp b/src/EntityManager.cpp
index d993860..298dac3 100644
--- a/src/EntityManager.cpp
+++ b/src/EntityManager.cpp
@@ -29,7 +29,7 @@
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
#include <VariantVisitors.hpp>
-#include <experimental/filesystem>
+#include "filesystem.hpp"
constexpr const char *OUTPUT_DIR = "/var/configuration/";
constexpr const char *configurationDirectory = PACKAGE_DIR "configurations";
@@ -40,7 +40,6 @@
constexpr const int32_t MAX_MAPPER_DEPTH = 0;
constexpr const size_t SLEEP_AFTER_PROPERTIES_CHANGE_SECONDS = 5;
-namespace fs = std::experimental::filesystem;
namespace variant_ns = sdbusplus::message::variant_ns;
struct cmp_str
{
@@ -499,7 +498,7 @@
// writes output files to persist data
bool writeJsonFiles(const nlohmann::json &systemConfiguration)
{
- std::experimental::filesystem::create_directory(OUTPUT_DIR);
+ std::filesystem::create_directory(OUTPUT_DIR);
std::ofstream output(std::string(OUTPUT_DIR) + "system.json");
if (!output.good())
{
@@ -1141,8 +1140,8 @@
bool findJsonFiles(std::list<nlohmann::json> &configurations)
{
// find configuration files
- std::vector<fs::path> jsonPaths;
- if (!findFiles(fs::path(configurationDirectory),
+ std::vector<std::filesystem::path> jsonPaths;
+ if (!findFiles(std::filesystem::path(configurationDirectory),
R"(.*\.json)", jsonPaths))
{
std::cerr << "Unable to find any configuration files in "
@@ -1157,6 +1156,7 @@
std::cerr
<< "Cannot open schema file, cannot validate JSON, exiting\n\n";
std::exit(EXIT_FAILURE);
+ return false;
}
nlohmann::json schema = nlohmann::json::parse(schemaStream, nullptr, false);
if (schema.is_discarded())
@@ -1164,6 +1164,7 @@
std::cerr
<< "Illegal schema file detected, cannot validate JSON, exiting\n";
std::exit(EXIT_FAILURE);
+ return false;
}
for (auto &jsonPath : jsonPaths)
@@ -1198,6 +1199,7 @@
configurations.emplace_back(data);
}
}
+ return true;
}
struct PerformScan : std::enable_shared_from_this<PerformScan>
diff --git a/src/FruDevice.cpp b/src/FruDevice.cpp
index 0590717..ca0e541 100644
--- a/src/FruDevice.cpp
+++ b/src/FruDevice.cpp
@@ -37,7 +37,7 @@
#include <linux/i2c-dev.h>
}
-namespace fs = std::experimental::filesystem;
+namespace fs = std::filesystem;
static constexpr bool DEBUG = false;
static size_t UNKNOWN_BUS_OBJECT_COUNT = 0;
constexpr size_t MAX_FRU_SIZE = 512;
@@ -59,7 +59,7 @@
static bool isMuxBus(size_t bus)
{
- return is_symlink(std::experimental::filesystem::path(
+ return is_symlink(std::filesystem::path(
"/sys/bus/i2c/devices/i2c-" + std::to_string(bus) + "/mux_device"));
}
diff --git a/src/Overlay.cpp b/src/Overlay.cpp
index 0f25eb5..5596ac3 100644
--- a/src/Overlay.cpp
+++ b/src/Overlay.cpp
@@ -19,7 +19,7 @@
#include <regex>
#include <boost/process/child.hpp>
#include <boost/algorithm/string/predicate.hpp>
-#include <experimental/filesystem>
+#include "filesystem.hpp"
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
#include <nlohmann/json.hpp>
@@ -72,8 +72,8 @@
return;
}
- std::experimental::filesystem::path pathObj(driver);
- for (auto &p : std::experimental::filesystem::directory_iterator(pathObj))
+ std::filesystem::path pathObj(driver);
+ for (auto &p : std::filesystem::directory_iterator(pathObj))
{
// symlinks are object names
if (is_symlink(p))
@@ -109,11 +109,10 @@
// when muxes create new i2c devices, the symbols are not there to map the new
// i2c devices to the mux address. this looks up the device tree path and adds
// the new symbols so the new devices can be referenced via the phandle
-void fixupSymbols(
- const std::vector<std::experimental::filesystem::path> &i2cDevsBefore)
+void fixupSymbols(const std::vector<std::filesystem::path> &i2cDevsBefore)
{
- std::vector<std::experimental::filesystem::path> i2cDevsAfter;
- findFiles(std::experimental::filesystem::path(I2C_DEVS_DIR),
+ std::vector<std::filesystem::path> i2cDevsAfter;
+ findFiles(std::filesystem::path(I2C_DEVS_DIR),
R"(i2c-\d+)", i2cDevsAfter);
for (const auto &dev : i2cDevsAfter)
@@ -127,9 +126,8 @@
std::string bus =
std::regex_replace(dev.string(), std::regex("^.*-"), "");
std::string devtreeRef = dev.string() + "/device/of_node";
- auto devtreePath = std::experimental::filesystem::path(devtreeRef);
- std::string symbolPath =
- std::experimental::filesystem::canonical(devtreePath);
+ auto devtreePath = std::filesystem::path(devtreeRef);
+ std::string symbolPath = std::filesystem::canonical(devtreePath);
symbolPath =
symbolPath.substr(sizeof("/sys/firmware/devicetree/base") - 1);
nlohmann::json configuration = {{"Path", symbolPath},
@@ -190,12 +188,11 @@
const std::string &addressHex = hex.str();
std::string busStr = std::to_string(*bus);
- std::experimental::filesystem::path devicePath(device);
+ std::filesystem::path devicePath(device);
const std::string &dir = devicePath.parent_path().string();
- for (const auto &path :
- std::experimental::filesystem::directory_iterator(dir))
+ for (const auto &path : std::filesystem::directory_iterator(dir))
{
- if (!std::experimental::filesystem::is_directory(path))
+ if (!std::filesystem::is_directory(path))
{
continue;
}
@@ -321,8 +318,8 @@
bool loadOverlays(const nlohmann::json &systemConfiguration)
{
- std::vector<std::experimental::filesystem::path> paths;
- if (!findFiles(std::experimental::filesystem::path(TEMPLATE_DIR),
+ std::vector<std::filesystem::path> paths;
+ if (!findFiles(std::filesystem::path(TEMPLATE_DIR),
R"(.*\.template)", paths))
{
std::cerr << "Unable to find any tempate files in " << TEMPLATE_DIR
@@ -330,7 +327,7 @@
return false;
}
- std::experimental::filesystem::create_directory(OUTPUT_DIR);
+ std::filesystem::create_directory(OUTPUT_DIR);
for (auto entity = systemConfiguration.begin();
entity != systemConfiguration.end(); entity++)
{
diff --git a/src/Utils.cpp b/src/Utils.cpp
index be7b35c..dda3b40 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -15,7 +15,7 @@
*/
#include <Utils.hpp>
-#include <experimental/filesystem>
+#include "filesystem.hpp"
#include <fstream>
#include <regex>
#include <valijson/adapters/nlohmann_json_adapter.hpp>
@@ -23,7 +23,7 @@
#include <valijson/schema_parser.hpp>
#include <valijson/validator.hpp>
-namespace fs = std::experimental::filesystem;
+namespace fs = std::filesystem;
bool findFiles(const fs::path &dirPath, const std::string &matchString,
std::vector<fs::path> &foundPaths)
@@ -57,4 +57,4 @@
return false;
}
return true;
-}
\ No newline at end of file
+}