From 5e8a578a1ec0982b3fa2ce69dc38d8089fc751d6 Mon Sep 17 00:00:00 2001
From: Michael Kuron <mkuron@icp.uni-stuttgart.de>
Date: Wed, 14 Mar 2018 11:09:11 +0100
Subject: [PATCH] mac CI build jobs

- fix find_package(MPI) when WARNING_ERROR is defined and recent version of CMake is used
- fix python_coupling Manager::addPath
---
 .gitlab-ci.yml                  | 67 ++++++++++++++++++++++++++++++++-
 CMakeLists.txt                  | 27 +++++++------
 src/python_coupling/Manager.cpp | 27 +++++++++----
 3 files changed, 101 insertions(+), 20 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4a4447405..c9338c550 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,6 +1,6 @@
 ###############################################################################
 ##                                                                           ##
-##    Genral settings                                                        ##
+##    General settings                                                       ##
 ##                                                                           ##
 ###############################################################################
 
@@ -970,6 +970,71 @@ msvc-14.1_MpiOnly:
       - triggers
 
 
+###############################################################################
+##                                                                           ##
+##    macOS Builds                                                           ##
+##                                                                           ##
+###############################################################################
+
+
+.mac_build_template: &mac_build_definition
+   script:
+      - export NUM_CORES=$(system_profiler SPHardwareDataType | grep 'Total Number of Cores' | awk '{print $5}')
+      - export MAX_BUILD_CORES=$(( $(system_profiler SPHardwareDataType | grep 'Memory' | awk '{print $2}') / 4 ))
+      - "[[ $MAX_BUILD_CORES -lt $NUM_CORES ]] && export NUM_BUILD_CORES=$MAX_BUILD_CORES || export NUM_BUILD_CORES=$NUM_CORES"
+      - c++ --version
+      - cmake --version
+      - mpirun --version
+      - mkdir build
+      - cd build
+      - cmake .. -DWALBERLA_BUILD_TESTS=ON -DWALBERLA_BUILD_BENCHMARKS=ON -DWALBERLA_BUILD_TUTORIALS=ON -DWALBERLA_BUILD_TOOLS=ON -DWALBERLA_BUILD_WITH_MPI=$WALBERLA_BUILD_WITH_MPI -DWALBERLA_BUILD_WITH_PYTHON=$WALBERLA_BUILD_WITH_PYTHON -DWALBERLA_BUILD_WITH_OPENMP=$WALBERLA_BUILD_WITH_OPENMP -DWALBERLA_BUILD_WITH_CUDA=$WALBERLA_BUILD_WITH_CUDA -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DWARNING_ERROR=ON
+      - cmake . -LAH
+      - make -j $NUM_BUILD_CORES -l $NUM_CORES
+      - ctest -LE $CTEST_EXCLUDE_LABELS -C $CMAKE_BUILD_TYPE --output-on-failure -j $NUM_CORES
+   tags:
+      - mac
+
+mac_Serial_Dbg:
+   <<: *mac_build_definition
+   variables:
+      CMAKE_BUILD_TYPE: "DebugOptimized"
+      CTEST_EXCLUDE_LABELS: "longrun|cuda"
+      WALBERLA_BUILD_WITH_MPI: "OFF"
+      WALBERLA_BUILD_WITH_OPENMP: "OFF"
+      WALBERLA_BUILD_WITH_PYTHON: "ON"
+      WALBERLA_BUILD_WITH_CUDA: "ON"
+
+mac_Serial:
+   <<: *mac_build_definition
+   variables:
+      CMAKE_BUILD_TYPE: "Release"
+      CTEST_EXCLUDE_LABELS: "longrun|cuda"
+      WALBERLA_BUILD_WITH_MPI: "OFF"
+      WALBERLA_BUILD_WITH_OPENMP: "OFF"
+      WALBERLA_BUILD_WITH_PYTHON: "ON"
+      WALBERLA_BUILD_WITH_CUDA: "ON"
+
+mac_MpiOnly_Dbg:
+   <<: *mac_build_definition
+   variables:
+      CMAKE_BUILD_TYPE: "DebugOptimized"
+      CTEST_EXCLUDE_LABELS: "longrun|cuda"
+      WALBERLA_BUILD_WITH_MPI: "ON"
+      WALBERLA_BUILD_WITH_OPENMP: "OFF"
+      WALBERLA_BUILD_WITH_PYTHON: "ON"
+      WALBERLA_BUILD_WITH_CUDA: "ON"
+
+mac_MpiOnly:
+   <<: *mac_build_definition
+   variables:
+      CMAKE_BUILD_TYPE: "Release"
+      CTEST_EXCLUDE_LABELS: "longrun|cuda"
+      WALBERLA_BUILD_WITH_MPI: "ON"
+      WALBERLA_BUILD_WITH_OPENMP: "OFF"
+      WALBERLA_BUILD_WITH_PYTHON: "ON"
+      WALBERLA_BUILD_WITH_CUDA: "ON"
+
+
 ###############################################################################
 ##                                                                           ##
 ##    Deploy jobs                                                            ##
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6ad1c28c1..ef327f605 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -360,17 +360,6 @@ if( NOT WARNING_DEPRECATED)
    endif()
 endif()
 
-# Treat warnings as errors
-if ( WARNING_ERROR )
-   if( WALBERLA_CXX_COMPILER_IS_GNU OR WALBERLA_CXX_COMPILER_IS_INTEL OR WALBERLA_CXX_COMPILER_IS_CLANG )
-      add_flag ( CMAKE_CXX_FLAGS "-pedantic-errors -Werror" )
-   elseif( WALBERLA_CXX_COMPILER_IS_MSVC )
-      add_flag ( CMAKE_CXX_FLAGS "/WX" )
-   elseif ( WALBERLA_CXX_COMPILER_IS_CRAY )
-      add_flag ( CMAKE_CXX_FLAGS "-h error_on_warning" )
-   endif()
-endif ( )
-
 
 if ( WALBERLA_CXX_COMPILER_IS_CLANG )
     add_flag ( CMAKE_CXX_FLAGS "-Wall -Wconversion -Wshadow -Wno-c++11-extensions -Qunused-arguments" )
@@ -1233,8 +1222,24 @@ if ( WALBERLA_BUILD_WITH_LTO  )
    endif( )
 
 endif ( )
+
+############################################################################################################################
+##
+##  Some more compiler flags that need to happen after any try_compile (e.g. inside FindMPI)
+##
 ############################################################################################################################
 
+# Treat warnings as errors
+if ( WARNING_ERROR )
+   if( WALBERLA_CXX_COMPILER_IS_GNU OR WALBERLA_CXX_COMPILER_IS_INTEL OR WALBERLA_CXX_COMPILER_IS_CLANG )
+      add_flag ( CMAKE_CXX_FLAGS "-pedantic-errors -Werror" )
+   elseif( WALBERLA_CXX_COMPILER_IS_MSVC )
+      add_flag ( CMAKE_CXX_FLAGS "/WX" )
+   elseif ( WALBERLA_CXX_COMPILER_IS_CRAY )
+      add_flag ( CMAKE_CXX_FLAGS "-h error_on_warning" )
+   endif()
+endif ( )
+
 ############################################################################################################################
 ##
 ##  Sanitizer
diff --git a/src/python_coupling/Manager.cpp b/src/python_coupling/Manager.cpp
index 264ba49b6..9ccf4a597 100644
--- a/src/python_coupling/Manager.cpp
+++ b/src/python_coupling/Manager.cpp
@@ -75,11 +75,9 @@ void Manager::addPath( const std::string & path )
 {
    WALBERLA_ASSERT( initialized_ );
 
-   object main_module  = import("__main__");
-   dict globals = extract<dict>( main_module.attr( "__dict__" ) );
-   exec( "import sys", globals );
-   std::string pathCommand = std::string ( "sys.path.append( \"") + path + "\" ) ";
-   exec( str(pathCommand), globals );
+   object sys = import("sys");
+   list sys_path = extract<list>( sys.attr("path") );
+   sys_path.append(path);
 }
 
 void Manager::triggerInitialization()
@@ -116,10 +114,24 @@ void Manager::triggerInitialization()
 
    }
    catch ( boost::python::error_already_set & ) {
-      PyErr_Print();
+      PyObject *type_ptr = NULL, *value_ptr = NULL, *traceback_ptr = NULL;
+      PyErr_Fetch(&type_ptr, &value_ptr, &traceback_ptr);
+
+      if( type_ptr )
+      {
+         extract<std::string> type_str(( str( handle<>( type_ptr ) ) ));
+         if( type_str.check() )
+            WALBERLA_LOG_DEVEL( type_str() );
+      }
+      if(value_ptr)
+      {
+         extract<std::string> value_str(( str( handle<>( value_ptr ) ) ));
+         if ( value_str.check() )
+            WALBERLA_LOG_DEVEL( value_str() );
+      }
+
       WALBERLA_ABORT( "Error while initializing Python" );
    }
-
 }
 
 
@@ -159,4 +171,3 @@ int someSymbolSoThatLinkerDoesNotComplain=0;
 
 
 
-
-- 
GitLab