From b623bb06187b81c8c6d2575facd0ed5027ef9592 Mon Sep 17 00:00:00 2001 From: "Jeongseok (JS) Lee" Date: Fri, 30 Dec 2022 16:34:54 -0800 Subject: [PATCH] Fix CI for macOS (#1689) --- .ci/build.sh | 9 +++++---- Brewfile | 1 + python/CMakeLists.txt | 6 ++++++ python/dartpy/CMakeLists.txt | 5 +++-- python/tests/CMakeLists.txt | 26 ++++++++++++++++---------- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/.ci/build.sh b/.ci/build.sh index c7aaeef4ba486..d1c02194ed19d 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -93,11 +93,11 @@ fi # Ref: https://unix.stackexchange.com/a/129401 if [ "$OSTYPE" = "linux-gnu" ]; then num_available_threads=$(nproc) -elif [ "$OSTYPE" = "darwin" ]; then +elif [[ $OSTYPE = darwin* ]]; then num_available_threads=$(sysctl -n hw.logicalcpu) else num_available_threads=1 - echo "$OSTYPE is not supported to detect the number of logical CPU cores." + echo "[WARN] $OSTYPE is not supported to detect the number of logical CPU cores." fi if [ "$NUM_CORES" = "MAX" ]; then @@ -128,6 +128,7 @@ echo "" echo " [ SYSTEM INFO ]" echo "" echo " OS : $OS $VER ($(uname -m))" +echo " OSTYPE : $OSTYPE" echo " Cores : $num_threads / $num_available_threads" echo " Compiler: $COMPILER $($CXX --version | perl -pe '($_)=/([0-9]+([.][0-9]+)+)/')" echo " CMake : $(cmake --version | perl -pe '($_)=/([0-9]+([.][0-9]+)+)/')" @@ -138,8 +139,8 @@ echo "=====================================" mkdir build && cd build if [ "$OSTYPE" = "linux-gnu" ]; then install_prefix_option="-DCMAKE_INSTALL_PREFIX=/usr/" -elif [ "$OSTYPE" = "darwin" ]; then - install_prefix_option="-DCMAKE_INSTALL_PREFIX=/usr/local/" +elif [[ $OSTYPE = darwin* ]]; then + install_prefix_option="-DCMAKE_INSTALL_PREFIX=/usr/local/ -DCMAKE_INSTALL_RPATH=/usr/local/lib/" fi cmake .. \ diff --git a/Brewfile b/Brewfile index 68ff9e0013232..63c740ec8629a 100644 --- a/Brewfile +++ b/Brewfile @@ -20,4 +20,5 @@ brew 'tinyxml2' brew 'urdfdom' # dartpy dependencies +brew 'python3' brew 'pybind11' diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 92501341ac708..c578a5229a4ac 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -11,3 +11,9 @@ add_subdirectory(dartpy) add_subdirectory(tests) add_subdirectory(examples) add_subdirectory(tutorials) + +message(STATUS "") +message(STATUS "[ dartpy ]") +message(STATUS "- PYTHON_EXECUTABLE : ${PYTHON_EXECUTABLE}") +message(STATUS "- PYTHON_SITE_PACKAGES: ${PYTHON_SITE_PACKAGES}") +message(STATUS "- DARTPY_PYTEST_FOUND : ${DARTPY_PYTEST_FOUND}") diff --git a/python/dartpy/CMakeLists.txt b/python/dartpy/CMakeLists.txt index 5805ebca6e82f..9a897351a4523 100644 --- a/python/dartpy/CMakeLists.txt +++ b/python/dartpy/CMakeLists.txt @@ -24,13 +24,14 @@ endif() execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib;\ - print(get_python_lib(plat_specific=True, prefix=''))" + print(get_python_lib(plat_specific=True))" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE ) -if(NOT IS_ABSOLUTE PYTHON_SITE_PACKAGES) +if(NOT IS_ABSOLUTE ${PYTHON_SITE_PACKAGES}) set(PYTHON_SITE_PACKAGES "${CMAKE_INSTALL_PREFIX}/${PYTHON_SITE_PACKAGES}") endif() +set(PYTHON_SITE_PACKAGES ${PYTHON_SITE_PACKAGES} PARENT_SCOPE) file(GLOB_RECURSE dartpy_headers "*.h" "*.hpp") file(GLOB_RECURSE dartpy_sources "*.cpp") diff --git a/python/tests/CMakeLists.txt b/python/tests/CMakeLists.txt index 4cdd5768ae8ff..967c1c1079464 100644 --- a/python/tests/CMakeLists.txt +++ b/python/tests/CMakeLists.txt @@ -9,14 +9,14 @@ if(pytest_not_found) message(WARNING "Running the tests requires pytest. Please install it manually" " (try: ${PYTHON_EXECUTABLE} -m pip install pytest)" ) - set(DARTPY_PYTEST_FOUND FALSE) + set(DARTPY_PYTEST_FOUND FALSE PARENT_SCOPE) elseif(pytest_version VERSION_LESS 3.0) message(WARNING "Running the tests requires pytest >= 3.0. Found: ${pytest_version}" "Please update it (try: ${PYTHON_EXECUTABLE} -m pip install -U pytest)" ) - set(DARTPY_PYTEST_FOUND FALSE) + set(DARTPY_PYTEST_FOUND FALSE PARENT_SCOPE) else() - set(DARTPY_PYTEST_FOUND TRUE) + set(DARTPY_PYTEST_FOUND TRUE PARENT_SCOPE) endif() set(dartpy_test_utils @@ -26,13 +26,19 @@ set(dartpy_test_utils file(GLOB_RECURSE dartpy_test_files "test_*.py") # Add custom target to run the tests -add_custom_target(pytest - COMMAND ${CMAKE_COMMAND} -E echo "Running pytest by: PYTHONPATH=${DART_DARTPY_BUILD_DIR} ${PYTHON_EXECUTABLE} -m pytest [sources]" - COMMAND PYTHONPATH=${DART_DARTPY_BUILD_DIR} ${PYTHON_EXECUTABLE} -m pytest ${dartpy_test_files} -v - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - SOURCES ${dartpy_test_files} ${dartpy_test_utils} - DEPENDS dartpy -) +if(DARTPY_PYTEST_FOUND) + add_custom_target(pytest + COMMAND ${CMAKE_COMMAND} -E echo "Running pytest by: PYTHONPATH=${DART_DARTPY_BUILD_DIR} ${PYTHON_EXECUTABLE} -m pytest [sources]" + COMMAND PYTHONPATH=${DART_DARTPY_BUILD_DIR} ${PYTHON_EXECUTABLE} -m pytest ${dartpy_test_files} -v + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + SOURCES ${dartpy_test_files} ${dartpy_test_utils} + DEPENDS dartpy + ) +else() + add_custom_target(pytest + COMMAND ${CMAKE_COMMAND} -E echo "Warning: Failed to run pytest because pytest is not found!" + ) +endif() #=============================================================================== # Usage: