From f89f7cd28e0bdb959180b6d8216e232cd99cb335 Mon Sep 17 00:00:00 2001
From: Samuel Jackson <samueljackson@outlook.com>
Date: Tue, 5 Jun 2018 14:08:49 +0100
Subject: [PATCH] Make OSX mantidpython more consistent

This make several changes to the mantid python executable:
    - Changes the templated executable to be called mantidpython.in to
    follow the conventions we've followed elsewhere
    - Moves the executable into the bin folder
    - Fixes the start script so that it can be run in a developer build.
---
 CMakeLists.txt                                |  3 +++
 buildconfig/CMake/CommonSetup.cmake           |  3 ---
 buildconfig/CMake/DarwinSetup.cmake           |  6 ++---
 .../osx/{mantidpython_osx => mantidpython.in} | 23 +++++++++++++------
 4 files changed, 22 insertions(+), 13 deletions(-)
 rename buildconfig/CMake/Packaging/osx/{mantidpython_osx => mantidpython.in} (65%)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b88bb2cf0cd..be7664bc6b7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,6 +21,9 @@ set ( SYSTEM_PACKAGE_TARGET "" )
 
 # Add the path to our custom 'find' modules
 set ( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/buildconfig/CMake")
+# Send libraries to common place, reference in several places so must be at top level
+set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin )
+set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin )
 
 set ( ENABLE_MANTIDPLOT ON CACHE BOOL "Enable Qt4-based gui & components" )
 set ( ENABLE_WORKBENCH OFF CACHE BOOL "Enable Qt5-based gui & components" )
diff --git a/buildconfig/CMake/CommonSetup.cmake b/buildconfig/CMake/CommonSetup.cmake
index 2f3fdf48352..6fe1f6c128c 100644
--- a/buildconfig/CMake/CommonSetup.cmake
+++ b/buildconfig/CMake/CommonSetup.cmake
@@ -17,9 +17,6 @@ endif()
 # We want shared libraries everywhere
 set ( BUILD_SHARED_LIBS On )
 
-# Send libraries to common place
-set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin )
-set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin )
 if ( CMAKE_GENERATOR MATCHES "Visual Studio" OR CMAKE_GENERATOR MATCHES "Xcode" )
   set ( PVPLUGINS_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$<CONFIG>/plugins/paraview )
 else ()
diff --git a/buildconfig/CMake/DarwinSetup.cmake b/buildconfig/CMake/DarwinSetup.cmake
index b666ae5752c..093cc4fb0b9 100644
--- a/buildconfig/CMake/DarwinSetup.cmake
+++ b/buildconfig/CMake/DarwinSetup.cmake
@@ -79,11 +79,11 @@ if ( NOT TARGET mantidpython )
   else ()
     set ( PARAVIEW_PYTHON_PATHS "" )
   endif ()
-  configure_file ( ${CMAKE_MODULE_PATH}/Packaging/osx/mantidpython_osx ${CMAKE_CURRENT_BINARY_DIR}/mantidpython_osx @ONLY )
+  configure_file ( ${CMAKE_MODULE_PATH}/Packaging/osx/mantidpython.in ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mantidpython @ONLY )
 
   add_custom_target ( mantidpython ALL
       COMMAND ${CMAKE_COMMAND} -E copy_if_different
-      ${CMAKE_CURRENT_BINARY_DIR}/mantidpython_osx
+      ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mantidpython
       ${PROJECT_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/mantidpython
       COMMENT "Generating mantidpython" )
   #Configure install script at the same time. Doing it later causes a warning from ninja.
@@ -93,7 +93,7 @@ if ( NOT TARGET mantidpython )
     set ( PARAVIEW_PYTHON_PATHS "" )
   endif ()
 
-  configure_file ( ${CMAKE_MODULE_PATH}/Packaging/osx/mantidpython_osx ${CMAKE_BINARY_DIR}/mantidpython_osx_install @ONLY )
+  configure_file ( ${CMAKE_MODULE_PATH}/Packaging/osx/mantidpython.in ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mantidpython_osx_install @ONLY )
 endif ()
 
 
diff --git a/buildconfig/CMake/Packaging/osx/mantidpython_osx b/buildconfig/CMake/Packaging/osx/mantidpython.in
similarity index 65%
rename from buildconfig/CMake/Packaging/osx/mantidpython_osx
rename to buildconfig/CMake/Packaging/osx/mantidpython.in
index 017e7141cf2..51b9910c5d9 100755
--- a/buildconfig/CMake/Packaging/osx/mantidpython_osx
+++ b/buildconfig/CMake/Packaging/osx/mantidpython.in
@@ -2,6 +2,7 @@
 #
 # For OS X only
 # Launch IPython with paths set for the Mantid environment
+# Find out where we are
 
 # Get the path of this script so that we know where Mantid is installed
 # This method should be robust; work through nested symlinks etc
@@ -15,7 +16,7 @@ cd "`dirname "${SCRIPT_PATH}"`" > /dev/null
 SCRIPT_PATH="`pwd`";
 popd  > /dev/null
 
-PROG=${SCRIPT_PATH}/bin/ipython@PYTHON_VERSION_MAJOR@
+INSTALLDIR=${SCRIPT_PATH%/*}
 
 # Define extra libraries for python
 LOCAL_PYTHONPATH=${SCRIPT_PATH}
@@ -24,14 +25,22 @@ if [ -n "${PYTHONPATH}" ]; then
 	LOCAL_PYTHONPATH=${LOCAL_PYTHONPATH}:${PYTHONPATH}
 fi
 
+# Define MANTIDPATH
+MANTIDPATH="${INSTALLDIR}"
 if [ -n "$1" ] && [ "$1" = "--classic" ]; then
     shift
-    PROG=@PYTHON_EXECUTABLE@
+
+    set -- @WRAPPER_PREFIX@@PYTHON_EXECUTABLE@ $*@WRAPPER_POSTFIX@
+
+else
+    IPYTHON_STARTUP="import IPython;IPython.start_ipython()"
+
+    set -- @WRAPPER_PREFIX@@PYTHON_EXECUTABLE@ -c "${IPYTHON_STARTUP}" $*@WRAPPER_POSTFIX@
+
 fi
 
-# Define MANTIDPATH
-MANTIDPATH="${SCRIPT_PATH}"
 
-PYTHONPATH=${LOCAL_PYTHONPATH} \
-    MANTIDPATH=$MANTIDPATH \
-    ${PROG} $*
+PV_PLUGIN_PATH=${PV_PLUGIN_PATH} \
+  MANTIDPATH=${MANTIDPATH} \
+  PYTHONPATH=${LOCAL_PYTHONPATH} \
+  exec "$@"
-- 
GitLab