fix regex, use boost for GCC < 4.9.0 05/50405/5
authorKrzysztof Dynowski <k.dynowski@samsung.com>
Sun, 25 Oct 2015 21:26:17 +0000 (22:26 +0100)
committerKrzysztof Dynowski <k.dynowski@samsung.com>
Fri, 30 Oct 2015 20:59:11 +0000 (21:59 +0100)
[Feature/Bug] Tests using regex fails (gcc 4.8.x)
[Cause]         Older C++ libs does not support regex
[Solution]      use boost
[Verification]  build, install, run unit tests

Change-Id: I635d678ca4bd2625b18241d5ba0cab89f5351eee

CMakeLists.txt
libs/lxcpp/CMakeLists.txt
libs/lxcpp/cgroups/devices.cpp
server/CMakeLists.txt
server/input-monitor.cpp
server/zone.hpp
server/zones-manager.cpp
tests/unit_tests/CMakeLists.txt
tests/unit_tests/server/ut-zones-manager.cpp

index b1b6ed5..0443246 100644 (file)
@@ -59,6 +59,14 @@ else()
     SET(CXX_11_STD "c++11")
 endif()
 
+# special case for a GCC < 4.9, use boost for regex
+IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
+    SET(USE_BOOST_REGEX "regex")
+    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST_REGEX")
+else()
+    SET(USE_BOOST_REGEX "")
+endif()
+
 SET(CMAKE_C_FLAGS_PROFILING    "-O0 -pg")
 SET(CMAKE_CXX_FLAGS_PROFILING  "-std=${CXX_11_STD} -O0 -pg")
 SET(CMAKE_C_FLAGS_DEBUG        "-O0 -ggdb")
index e3056dc..f78aae0 100644 (file)
@@ -54,7 +54,7 @@ TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME}
 ADD_DEPENDENCIES(${PROJECT_NAME} Common Logger Config Ipc)
 
 ## Link libraries ##############################################################
-FIND_PACKAGE(Boost COMPONENTS system filesystem)
+FIND_PACKAGE(Boost COMPONENTS system filesystem ${USE_BOOST_REGEX})
 PKG_CHECK_MODULES(LXCPP_DEPS REQUIRED glib-2.0)
 
 INCLUDE_DIRECTORIES(${LIBS_FOLDER} ${COMMON_FOLDER})
index 6bf8201..b8268b1 100644 (file)
 #include "utils/text.hpp"
 #include "logger/logger.hpp"
 
+#ifdef USE_BOOST_REGEX
+#include <boost/regex.hpp>
+namespace rgx = boost;
+#else
 #include <regex>
+namespace rgx = std;
+#endif
 
 namespace lxcpp {
 
@@ -39,10 +45,10 @@ std::string devString(int n)
 DevicePermission& parsePerms(DevicePermission& p,const std::string& line)
 {
     std::string re = "^([a-z]) ([0-9]+|\\*):([0-9]+|\\*) ([a-z]+)$";
-    std::smatch match;
+    rgx::smatch match;
     try {
-        std::regex rgx(re);
-        if (!std::regex_search(line, match, rgx)) {
+        rgx::regex rgex(re);
+        if (!rgx::regex_search(line, match, rgex)) {
             throw CGroupException("wrong input: " + line);
         }
     } catch (CGroupException) {
index 86b4f79..886d27d 100644 (file)
@@ -29,7 +29,7 @@ ADD_EXECUTABLE(${SERVER_CODENAME} ${project_SRCS})
 ADD_DEPENDENCIES(${SERVER_CODENAME} Common Logger Config Ipc)
 
 ## Link libraries ##############################################################
-FIND_PACKAGE(Boost COMPONENTS program_options system filesystem regex)
+FIND_PACKAGE(Boost COMPONENTS program_options system filesystem ${USE_BOOST_REGEX})
 PKG_CHECK_MODULES(SERVER_DEPS REQUIRED lxc glib-2.0 gio-2.0)
 
 INCLUDE_DIRECTORIES(${COMMON_FOLDER})
index 5ac6e68..4d97cad 100644 (file)
 #include <unistd.h>
 
 #include <boost/filesystem.hpp>
-#include <boost/regex.hpp>
 #include <vector>
 #include <functional>
 
+#ifdef USE_BOOST_REGEX
+#include <boost/regex.hpp>
+namespace rgx = boost;
+#else
+#include <regex>
+namespace rgx = std;
+#endif
+
 using namespace utils;
 namespace fs = boost::filesystem;
 
@@ -115,7 +122,7 @@ void InputMonitor::stop()
 
 namespace {
 
-bool isDeviceWithName(const boost::regex& deviceNameRegex,
+bool isDeviceWithName(const rgx::regex& deviceNameRegex,
                       const fs::directory_entry& directoryEntry)
 {
     std::string path = directoryEntry.path().string();
@@ -144,7 +151,7 @@ bool isDeviceWithName(const boost::regex& deviceNameRegex,
     }
 
     LOGD("Checking device: " << name);
-    if (boost::regex_match(name, deviceNameRegex)) {
+    if (rgx::regex_match(name, deviceNameRegex)) {
         LOGI("Device file found under: " << path);
         return true;
     }
@@ -167,7 +174,7 @@ std::string InputMonitor::getDevicePath() const
     LOGT("Determining, which device node is assigned to '" << device << "'");
     using namespace std::placeholders;
     fs::directory_iterator end;
-    boost::regex deviceNameRegex(".*" + device + ".*");
+    rgx::regex deviceNameRegex(".*" + device + ".*");
     const auto it = std::find_if(fs::directory_iterator(DEVICE_DIR),
                                  end,
                                  std::bind(isDeviceWithName, deviceNameRegex, _1));
index 0d3a920..7379571 100644 (file)
@@ -36,7 +36,6 @@
 #include <string>
 #include <memory>
 #include <thread>
-#include <boost/regex.hpp>
 
 
 namespace vasum {
index c45aa22..ab29182 100644 (file)
@@ -41,7 +41,6 @@
 #include "api/messages.hpp"
 
 #include <boost/filesystem.hpp>
-#include <boost/regex.hpp>
 #include <boost/exception/diagnostic_information.hpp>
 #include <cassert>
 #include <string>
 #include <cctype>
 #include <set>
 
+#ifdef USE_BOOST_REGEX
+#include <boost/regex.hpp>
+namespace rgx = boost;
+#else
+#include <regex>
+namespace rgx = std;
+#endif
 
 namespace vasum {
 
@@ -59,8 +65,8 @@ namespace {
 const std::string HOST_ID = "host";
 const std::string ENABLED_FILE_NAME = "enabled";
 
-const boost::regex ZONE_NAME_REGEX("~NAME~");
-const boost::regex ZONE_IP_THIRD_OCTET_REGEX("~IP~");
+const rgx::regex ZONE_NAME_REGEX("~NAME~");
+const rgx::regex ZONE_IP_THIRD_OCTET_REGEX("~IP~");
 
 const unsigned int ZONE_IP_BASE_THIRD_OCTET = 100;
 
@@ -1148,7 +1154,7 @@ void ZonesManager::generateNewConfig(const std::string& id,
     config::loadFromKVStoreWithJsonFile(mConfig.dbPath, templatePath, dynamicConfig, dbPrefix);
 
     // update mount point path
-    dynamicConfig.runMountPoint = boost::regex_replace(dynamicConfig.runMountPoint,
+    dynamicConfig.runMountPoint = rgx::regex_replace(dynamicConfig.runMountPoint,
                                                        ZONE_NAME_REGEX,
                                                        id);
 
@@ -1162,10 +1168,10 @@ void ZonesManager::generateNewConfig(const std::string& id,
             // generate third IP octet for network config
             std::string thirdOctetStr = std::to_string(ZONE_IP_BASE_THIRD_OCTET + freeVT);
             LOGD("IP third octet: " << thirdOctetStr);
-            dynamicConfig.ipv4Gateway = boost::regex_replace(dynamicConfig.ipv4Gateway,
+            dynamicConfig.ipv4Gateway = rgx::regex_replace(dynamicConfig.ipv4Gateway,
                                                              ZONE_IP_THIRD_OCTET_REGEX,
                                                              thirdOctetStr);
-            dynamicConfig.ipv4 = boost::regex_replace(dynamicConfig.ipv4,
+            dynamicConfig.ipv4 = rgx::regex_replace(dynamicConfig.ipv4,
                                                       ZONE_IP_THIRD_OCTET_REGEX,
                                                       thirdOctetStr);
         }
index 1c05576..39c9666 100644 (file)
@@ -56,7 +56,7 @@ ADD_EXECUTABLE(${SOCKET_TEST_CODENAME} ${socket_test_SRCS} ${client_SRCS})
 ENDIF(NOT WITHOUT_SYSTEMD)
 
 ## Link libraries ##############################################################
-FIND_PACKAGE (Boost COMPONENTS unit_test_framework system filesystem regex)
+FIND_PACKAGE (Boost COMPONENTS unit_test_framework system filesystem ${USE_BOOST_REGEX})
 
 PKG_CHECK_MODULES(UT_SERVER_DEPS REQUIRED lxc gio-2.0)
 INCLUDE_DIRECTORIES(${COMMON_FOLDER} ${SERVER_FOLDER} ${UNIT_TESTS_FOLDER} ${CLIENT_FOLDER}
index 6d6a71d..41e2a41 100644 (file)
@@ -49,6 +49,7 @@
 
 #include <vector>
 #include <map>
+#include <set>
 #include <memory>
 #include <string>
 #include <algorithm>