Skip to content

Commit e7cd7c0

Browse files
authored
Hotfix | Packaging issues on OSX (#383)
* Don't run streamer multitab tests on OSX/Travis. * Disable all socket streamer tests. * - Make python3 default python. - cmake 3.12 is minimum required. - Fixes to Python API. strncpy can not write to `const char*`. Instead initialize with value. - Build system fixes. * Fixes for gcc5 series. It is not smart enough to figure out which field is being updated. These needs to be ported to branch chamcham as well. * Create cmake.yml * Updated commands. * removing github actions. * Create build.yml * Added sudo ... * Run sudo apt-update ... * Fixed the name of package... * Fixed make and test targets. * Added workflow file. * Update build.yml
1 parent 16cd0d6 commit e7cd7c0

File tree

8 files changed

+193
-292
lines changed

8 files changed

+193
-292
lines changed

.github/main.workflow

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
workflow "build pymoose" {
2+
resolves = "build"
3+
on = "push"
4+
}
5+
6+
action "build" {
7+
uses = "./"
8+
args = "install"
9+
env = {
10+
CMAKE_GIT_REPO = "https://github.com/dilawar/moose-core",
11+
CMAKE_INSTALL_DEPS_SCRIPT = ".travis/travis_prepare_linux.sh",
12+
CMAKE_FLAGS = "-DCMAKE_INSTALL_PREFIX:PATH=/tmp/foo",
13+
CMAKE_BUILD_THREADS = "4"
14+
}
15+
}

.github/workflows/build.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: C/C++ CI
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Install dependencies
13+
run: |
14+
sudo apt update
15+
sudo apt install libgsl-dev g++ cmake python3-dev python3-numpy
16+
- name: configure
17+
run: mkdir -p build && cd build && cmake ..
18+
- name: make
19+
run: cd build && make
20+
- name: ctest --output-on-failure
21+
run: cd build && make check

CMakeLists.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
2-
project(pymoose)
1+
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
2+
project(MOOSE)
33

44
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules")
55
include(CheckCXXCompiler.cmake)
@@ -333,8 +333,19 @@ endif( WITH_BOOST )
333333

334334

335335
######################### BUILD PYMOOSE ########################################
336+
337+
# We find python executable here. Though mainly used inside pymoose.
338+
# FIXME: When cmake 3.12 is widely available use the following:
339+
# find_package(Python3 COMPONENTS Interpreter Numpy)
340+
# set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
341+
# See the cmake doc.
342+
# Till then, stay with the old macro.
343+
set(Python_ADDITIONAL_VERSIONS 2.7)
344+
find_package(PythonInterp 3.4)
345+
336346
# This target is built by pymoose/CMakeLists.txt file.
337-
add_subdirectory( pymoose )
347+
add_subdirectory(pymoose)
348+
338349

339350
# always override debian default installation directory. It will be installed in
340351
# site-packages instead of dist-packages.

cmake_modules/FindNumPy.cmake

Lines changed: 0 additions & 94 deletions
This file was deleted.

pymoose/CMakeLists.txt

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
cmake_minimum_required(VERSION 2.8)
2-
include( ${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake)
1+
include(${CMAKE_CURRENT_SOURCE_DIR}/../CheckCXXCompiler.cmake)
32

43
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_modules/")
54

6-
find_package(PythonInterp REQUIRED)
5+
execute_process(COMMAND
6+
${PYTHON_EXECUTABLE} -c "import numpy;print(numpy.get_include())"
7+
OUTPUT_VARIABLE NUMPY_INCLUDE_DIRS
8+
OUTPUT_STRIP_TRAILING_WHITESPACE)
9+
10+
if("${NUMPY_INCLUDE_DIRS}" STREQUAL "")
11+
message(FATAL_ERROR "Could not find numpy: ${NUMPY_INCLUDE_DIRS}")
12+
else()
13+
message(STATUS "Numpy is found at ${NUMPY_INCLUDE_DIRS}")
14+
endif()
715

8-
# Find Numpy
9-
find_package(NumPy REQUIRED)
1016
include_directories(${NUMPY_INCLUDE_DIRS})
11-
add_definitions( -std=c++11 )
17+
add_definitions(-std=c++11)
1218
add_definitions(-DUSE_NUMPY)
1319
add_definitions(-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION)
1420

1521
# set module extensiton. default is .so. Also check ../python/setup.cmake.py
16-
execute_process( COMMAND
22+
execute_process(COMMAND
1723
${PYTHON_EXECUTABLE} -c
1824
"import importlib.machinery
1925
print(importlib.machinery.EXTENSION_SUFFIXES[-1])"
2026
OUTPUT_VARIABLE PYTHON_SO_EXTENSION
21-
OUTPUT_STRIP_TRAILING_WHITESPACE
22-
)
27+
OUTPUT_STRIP_TRAILING_WHITESPACE)
2328
if(NOT PYTHON_SO_EXTENSION)
2429
message(STATUS "Python so ext could not be determined. Using default .so")
2530
set(PYTHON_SO_EXTENSION ".so")
@@ -44,38 +49,36 @@ set(PYMOOSE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../python/moose")
4449
message(STATUS "Python module will be saved to ${PYMOOSE_OUTPUT_DIRECTORY}" )
4550

4651
# make sure the Python.h is found.
47-
find_package( PythonLibs)
48-
if(PYTHON_INCLUDE_DIRS)
49-
include_directories( ${PYTHON_INCLUDE_DIRS} )
50-
else()
51-
# Use python executable to find include paths. For building wheel, we are
52-
# stuck with cmake-2.8 with which PythonLibs module might fail.
53-
message( STATUS "Using ${PYTHON_EXECUTABLE}-config to find Python.h" )
54-
execute_process( COMMAND ${PYTHON_EXECUTABLE}-config --includes
55-
OUTPUT_VARIABLE PYTHON_INCLUDE_FLAGS
56-
OUTPUT_STRIP_TRAILING_WHITESPACE
57-
)
58-
execute_process( COMMAND ${PYTHON_EXECUTABLE}-config --libs
59-
OUTPUT_VARIABLE PYTHON_LIBRARIES
60-
OUTPUT_STRIP_TRAILING_WHITESPACE
61-
)
62-
message( STATUS "Python include flags: ${PYTHON_INCLUDE_FLAGS}" )
63-
set_target_properties(_moose PROPERTIES
64-
COMPILE_DEFINITIONS "PYMOOSE"
65-
COMPILE_FLAGS "${PYTHON_INCLUDE_FLAGS}"
66-
)
52+
# Use python executable to find include paths. For building wheel, we are
53+
# stuck with cmake-2.8 with which PythonLibs module might fail.
54+
message(STATUS "Using ${PYTHON_EXECUTABLE}-config to find Python.h" )
55+
execute_process( COMMAND ${PYTHON_EXECUTABLE}-config --includes
56+
OUTPUT_VARIABLE PYTHON_INCLUDE_FLAGS
57+
OUTPUT_STRIP_TRAILING_WHITESPACE)
6758

59+
if("${PYTHON_INCLUDE_FLAGS}" STREQUAL "")
60+
message(FATAL_ERROR "Could not determine path of Python.h.")
61+
else()
62+
message(STATUS "Python.h is found at ${PYTHON_INCLUDE_FLAGS}")
6863
endif()
6964

65+
execute_process( COMMAND ${PYTHON_EXECUTABLE}-config --libs
66+
OUTPUT_VARIABLE PYTHON_LIBRARIES
67+
OUTPUT_STRIP_TRAILING_WHITESPACE)
68+
69+
set_target_properties(_moose PROPERTIES
70+
COMPILE_DEFINITIONS "PYMOOSE"
71+
COMPILE_FLAGS "${COMPILE_FLAGS} ${PYTHON_INCLUDE_FLAGS}"
72+
)
73+
7074
# Remove prefix lib from python module.
7175
if(NOT(PYTHON_SO_EXTENSION STREQUAL ""))
7276
set_target_properties(_moose PROPERTIES SUFFIX ${PYTHON_SO_EXTENSION})
7377
endif()
7478
set_target_properties(_moose PROPERTIES
7579
LIBRARY_OUTPUT_DIRECTORY ${PYMOOSE_OUTPUT_DIRECTORY}
7680
PREFIX ""
77-
SUFFIX ${PYTHON_SO_EXTENSION}
78-
)
81+
SUFFIX ${PYTHON_SO_EXTENSION})
7982

8083
# see issue #80
8184
if(HDF5_FOUND AND WITH_NSDF)
@@ -85,37 +88,33 @@ endif()
8588
if(APPLE)
8689
set(CMAKE_MODULE_LINKER_FLAGS "-undefined dynamic_lookup")
8790
message(STATUS "ADDING some linker flags ${CMAKE_EXE_LINKER_FLAGS}")
88-
endif(APPLE)
89-
90-
# cmake --help-policy CMP0042
91-
if(APPLE)
91+
# cmake --help-policy CMP0042
9292
set_target_properties( _moose PROPERTIES MACOSX_RPATH OFF)
9393
endif(APPLE)
9494

9595
if(APPLE)
96-
target_link_libraries( _moose
97-
"-Wl,-all_load"
98-
${MOOSE_LIBRARIES}
99-
${STATIC_LIBRARIES}
100-
)
101-
target_link_libraries(_moose
102-
${SYSTEM_SHARED_LIBS}
103-
)
96+
target_link_libraries( _moose
97+
"-Wl,-all_load"
98+
${MOOSE_LIBRARIES}
99+
${STATIC_LIBRARIES}
100+
)
101+
target_link_libraries(_moose
102+
${SYSTEM_SHARED_LIBS}
103+
)
104104
else(APPLE)
105-
target_link_libraries(_moose
106-
"-Wl,--whole-archive"
107-
${MOOSE_LIBRARIES}
108-
${STATIC_LIBRARIES}
109-
"-Wl,--no-whole-archive"
110-
${SYSTEM_SHARED_LIBS}
111-
)
112-
endif(APPLE)
105+
target_link_libraries(_moose
106+
"-Wl,--whole-archive"
107+
${MOOSE_LIBRARIES}
108+
${STATIC_LIBRARIES}
109+
"-Wl,--no-whole-archive"
110+
${SYSTEM_SHARED_LIBS})
111+
endif()
112+
113113
add_custom_command(TARGET _moose POST_BUILD
114114
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan
115115
"MOOSE python extention is successfully built. Now "
116116
" Run 'sudo make install' to install it. "
117117
" "
118118
"NOTE: Run 'pip uninstall moose' to uninstall moose."
119-
VERBATIM
120-
)
119+
VERBATIM)
121120

pymoose/moosemodule.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <cstring>
1717
#include <map>
1818
#include <ctime>
19+
#include <cstring>
1920
#include <csignal>
2021
#include <chrono>
2122
#include <thread>
@@ -2774,14 +2775,25 @@ int defineDestFinfos(const Cinfo * cinfo)
27742775
// if (name.find("get") == 0 || name.find("set") == 0){
27752776
// continue;
27762777
// }
2777-
PyGetSetDef destFieldGetSet;
2778+
PyGetSetDef destFieldGetSet = {.name = (char*) name.c_str()
2779+
, .get=nullptr, .set=nullptr
2780+
, .doc= (char*) "Destination field"
2781+
, .closure=nullptr};
27782782
vec.push_back(destFieldGetSet);
27792783

2780-
vec[currIndex].name = strdup(name.c_str());
2781-
vec[currIndex].doc = (char*) "Destination field";
2784+
// Dilawar:
2785+
// strncpy can not write to const char* especially with clang++.
2786+
// Ref: https://docs.python.org/3/c-api/structures.html#c.PyGetSetDef
2787+
//vec[currIndex].name = (char*)calloc(name.size() + 1, sizeof(char));
2788+
//strncpy(vec[currIndex].name,
2789+
// const_cast<char*>(name.c_str()),
2790+
// name.size());
2791+
// vec[currIndex].doc = (char*) "Destination field";
2792+
27822793
vec[currIndex].get = (getter)moose_ObjId_get_destField_attr;
27832794
PyObject *args = PyTuple_New(1);
2784-
if (!args || !vec[currIndex].name) {
2795+
if (!args || !vec[currIndex].name)
2796+
{
27852797
cerr << "moosemodule.cpp: defineDestFinfos: allocation failed\n";
27862798
return 0;
27872799
}

0 commit comments

Comments
 (0)