From 6a2554575bced122e145edeab27ae2e4ed1c4200 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Tue, 27 Feb 2024 18:23:55 +0100 Subject: [PATCH] feat: Add setup script which also handles dependencies (#2926) Currently I use a bunch of setup scripts for my daily developments and I wondered if those can be generated by CMake. In the best case this could be the standard way to setup a dev environment once the dependencies+built is figured out Sourcing our python scripts dir is currently necessary to find the ODD directory. This can later be generalized by an environment variable. Mid term we could also think about adding a dependency build script to the repo and have a CI job monitoring the dev environment setup for one or more systems --- .github/workflows/builds.yml | 14 ++------- .gitlab-ci.yml | 17 ++-------- Examples/Python/CMakeLists.txt | 5 +-- cmake/ActsCreateSetup.cmake | 8 +++++ cmake/setup_withdeps.sh.in | 57 ++++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 30 deletions(-) create mode 100644 cmake/setup_withdeps.sh.in diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 9fb71cc2a65..71656704057 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -146,12 +146,7 @@ jobs: PYTEST_MD_REPORT_OUTPUT: pytest.md run: > /usr/local/bin/geant4-config --install-datasets - && source /usr/local/bin/thisroot.sh - && source /usr/local/bin/thisdd4hep_only.sh - && source /usr/local/bin/geant4.sh - && source build/python/setup.sh - && export PYTHONPATH=/usr/local/python:$PYTHONPATH - && export LD_LIBRARY_PATH=$PWD/build/thirdparty/OpenDataDetector/factory:$LD_LIBRARY_PATH + && source build/this_acts_withdeps.sh && pip3 install -r Examples/Python/tests/requirements.txt && pip3 install pytest-md-report && pytest -rFsv -k "not exatrkx" -v @@ -195,13 +190,8 @@ jobs: && pip3 install histcmp==0.6.5 spyral-cli==1.1.1 matplotlib && pip3 install -r Examples/Scripts/requirements.txt && /usr/local/bin/geant4-config --install-datasets - && source /usr/local/bin/thisroot.sh - && source /usr/local/bin/thisdd4hep_only.sh - && source /usr/local/bin/geant4.sh - && source build/python/setup.sh - && export LD_LIBRARY_PATH=$PWD/build/thirdparty/OpenDataDetector/factory:$LD_LIBRARY_PATH + && source build/this_acts_withdeps.sh && echo "::endgroup::" - && export PYTHONPATH="${PYTHONPATH}":"${GITHUB_WORKSPACE}/Examples/Scripts/Python" && CI/physmon/phys_perf_mon.sh all physmon && cat physmon/summary.md >> $GITHUB_STEP_SUMMARY diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 512fbf3630f..73068b2725b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -128,8 +128,7 @@ test_exatrkx_python: script: - apt-get update -y - apt-get install -y python3 libxxhash0 - - source /usr/local/bin/thisroot.sh - - source build/python/setup.sh + - source build/this_acts_withdeps.sh - git clone $CLONE_URL src - cd src - git checkout $HEAD_SHA @@ -205,12 +204,7 @@ linux_test_examples: - cd .. - /usr/local/bin/geant4-config --install-datasets - - "source /usr/local/bin/thisroot.sh || true" - - "source /usr/local/bin/thisdd4hep_only.sh || true" - - "source /usr/local/bin/geant4.sh || true" - - source build/python/setup.sh - - export PYTHONPATH=/usr/local/python:$PYTHONPATH - - export LD_LIBRARY_PATH=$PWD/build/thirdparty/OpenDataDetector/factory:$LD_LIBRARY_PATH + - source build/this_acts_withdeps.sh - cd src - pip3 install -r Examples/Python/tests/requirements.txt - pytest -rFsv -k "not exatrkx" -v @@ -240,13 +234,8 @@ linux_physmon: - pip3 install histcmp==0.6.5 spyral-cli==1.1.0 matplotlib - pip3 install -r src/Examples/Scripts/requirements.txt - /usr/local/bin/geant4-config --install-datasets - - "source /usr/local/bin/thisroot.sh || true" - - "source /usr/local/bin/thisdd4hep_only.sh || true" - - "source /usr/local/bin/geant4.sh || true" - - source build/python/setup.sh - - export LD_LIBRARY_PATH=$PWD/build/thirdparty/OpenDataDetector/factory:$LD_LIBRARY_PATH + - source build/this_acts_withdeps.sh - cd src - - export PYTHONPATH="${PYTHONPATH}":"${PWD}/Examples/Scripts/Python" - CI/physmon/phys_perf_mon.sh all physmon ############################### diff --git a/Examples/Python/CMakeLists.txt b/Examples/Python/CMakeLists.txt index 282f4d73852..8d835a3f736 100644 --- a/Examples/Python/CMakeLists.txt +++ b/Examples/Python/CMakeLists.txt @@ -180,9 +180,8 @@ else() target_sources(ActsPythonBindings PRIVATE src/OnnxNeuralCalibratorStub.cpp) endif() -add_custom_target(ActsPythonGlueCode) configure_file(setup.sh.in ${_python_dir}/setup.sh @ONLY) -install(FILES setup.sh.in DESTINATION "python" RENAME setup.sh) +install(FILES ${_python_dir}/setup.sh DESTINATION "python") foreach(f ${py_files}) set(_target ${_python_dir}/acts/${f}) @@ -193,5 +192,3 @@ file(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/python/acts/${f} ${_target} SYMBOLI endforeach() install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python/acts/ DESTINATION ${_python_install_dir}) - -add_dependencies(ActsPythonBindings ActsPythonGlueCode) diff --git a/cmake/ActsCreateSetup.cmake b/cmake/ActsCreateSetup.cmake index 7c921e66dd6..ef37ea1db3b 100644 --- a/cmake/ActsCreateSetup.cmake +++ b/cmake/ActsCreateSetup.cmake @@ -6,3 +6,11 @@ configure_file( install( FILES ${PROJECT_BINARY_DIR}/this_acts.sh DESTINATION ${CMAKE_INSTALL_BINDIR}) + +configure_file( + ${CMAKE_CURRENT_LIST_DIR}/setup_withdeps.sh.in + ${PROJECT_BINARY_DIR}/this_acts_withdeps.sh + @ONLY) +install( + FILES ${PROJECT_BINARY_DIR}/this_acts_withdeps.sh + DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/cmake/setup_withdeps.sh.in b/cmake/setup_withdeps.sh.in new file mode 100644 index 00000000000..953f472d78e --- /dev/null +++ b/cmake/setup_withdeps.sh.in @@ -0,0 +1,57 @@ +# This file is part of the Acts project. +# +# Copyright (C) 2024 CERN for the benefit of the Acts project +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# This script sets up the ACTS Examples environment in a somewhat robust way. + +if [ -n "$ZSH_VERSION" ]; then + script_dir=${0:a:h} +elif [ -n "$BASH_VERSION" ]; then + script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +else + # If the current shell is not ZSH or Bash, we can't guarantee that the + # script will work, so we throw an error. + echo "ERROR: neither ZSH nor Bash was detected, other shells are not supported. The environment has not been modified." + exit 1 +fi + +# source the python and ODD environment +. $script_dir/python/setup.sh + +# set ACTS and ODD environment variables +ACTS_SOURCE_DIR=@CMAKE_CURRENT_SOURCE_DIR@ +ODD_SOURCE_DIR=@CMAKE_CURRENT_SOURCE_DIR@/thirdparty/OpenDataDetector + +# modify python environment to include some ACTS helpers +export PYTHONPATH="$ACTS_SOURCE_DIR/Examples/Scripts/Python:${PYTHONPATH}" + +# make ACTS binaries available +export PATH="$script_dir/bin:${PATH}" +export LD_LIBRARY_PATH="$script_dir/lib:${LD_LIBRARY_PATH}" +export DYLD_LIBRARY_PATH="$script_dir/lib:${DYLD_LIBRARY_PATH}" + +# activate dependencies if present +if [[ -d "@ROOT_DIR@" ]]; then + . @ROOT_BINDIR@/thisroot.sh +fi +if [[ -d "@Geant4_DIR@" ]]; then + . @Geant4_INCLUDE_DIR@/../../bin/geant4.sh +fi +if [[ -d "@DD4hep_DIR@" ]]; then + . @DD4hep_INCLUDE_DIRS@/../bin/thisdd4hep.sh +fi +if [[ -d "@podio_DIR@" ]]; then + export LD_LIBRARY_PATH="@podio_LIBRARY_DIR@:${LD_LIBRARY_PATH}" + export DYLD_LIBRARY_PATH="@podio_LIBRARY_DIR@:${DYLD_LIBRARY_PATH}" + export ROOT_INCLUDE_PATH="@podio_INCLUDE_DIR@:${ROOT_INCLUDE_PATH}" + export PYTHONPATH="@podio_PYTHON_DIR@:${PYTHONPATH}" +fi +if [[ -d "@EDM4HEP_DIR@" ]]; then + export LD_LIBRARY_PATH="@EDM4HEP_LIBRARY_DIR@/lib:${LD_LIBRARY_PATH}" + export DYLD_LIBRARY_PATH="@EDM4HEP_LIBRARY_DIR@/lib:${DYLD_LIBRARY_PATH}" + export ROOT_INCLUDE_PATH="@EDM4HEP_INCLUDE_DIR@:${ROOT_INCLUDE_PATH}" +fi