Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:44

0001 #!/bin/bash
0002 
0003 function run() {
0004     set -x
0005     "$@"
0006     { set +x;  } 2> /dev/null
0007 }
0008 
0009 function set_env {
0010   key="$1"
0011   value="$2"
0012 
0013   echo "=> ${key}=${value}"
0014 
0015   if [ -n "${GITHUB_ACTIONS:-}" ]; then
0016     echo "${key}=${value}" >> $GITHUB_ENV
0017   else
0018     export ${key}=${value}
0019   fi
0020 }
0021 
0022 url=${1:-${DEPENDENCY_URL:-}}
0023 
0024 if [ -n "${GITHUB_ACTIONS:-}" ]; then
0025     destination="${GITHUB_WORKSPACE}/dependencies"
0026 elif [ -n "${GITLAB_CI:-}" ];then
0027     destination="${CI_PROJECT_DIR}/dependencies"
0028 else
0029     destination=${2}
0030 fi
0031 
0032 set_env DEPENDENCY_DIR "${destination}"
0033 
0034 if [ -z "${url}" ]; then
0035     echo "url is not set"
0036     exit 1
0037 fi
0038 
0039 echo "URL: $url"
0040 echo "DESTINATION: $destination"
0041 
0042 # check curl location
0043 CURL=$(command -v curl)
0044 if [ -z "$CURL" ]; then
0045     echo "curl is not available"
0046     exit 1
0047 fi
0048 
0049 UNZSTD=$(command -v unzstd)
0050 if [ -z "$UNZSTD" ]; then
0051     echo "unzstd is not available"
0052     exit 1
0053 fi
0054 
0055 TAR=$(command -v tar)
0056 if [ -z "$TAR" ]; then
0057     echo "tar is not available"
0058     exit 1
0059 fi
0060 
0061 run mkdir -p "${destination}"
0062 
0063 run $CURL \
0064   --retry 5 \
0065   --connect-timeout 2 \
0066   --location $url \
0067   | unzstd \
0068   | tar \
0069     -x \
0070     --strip-components=1 \
0071     --directory "${destination}"
0072 
0073 # Patch up geant4-config data install script
0074 out=$(${destination}/bin/geant4-config --datasets)
0075 line=$(echo "$out" | head -n1)
0076 orig_share=$(echo "$line" | perl -pe 's|.*?(\/.*)\/share.*|\1|')
0077 orig_share_escaped=$(echo $orig_share|perl -pe 's|/|\\/|g')
0078 destination_escaped=$(echo "$destination"|perl -pe 's|/|\\/|g')
0079 perl -pi.bak -e "s/$orig_share_escaped/$destination_escaped/g" ${destination}/bin/geant4-config
0080 
0081 if [ -n "${GITHUB_ACTIONS:-}" ]; then
0082   echo "Running in GitHub Actions"
0083   venv="${GITHUB_WORKSPACE}/venv"
0084 fi
0085 
0086 if [ -n "${GITLAB_CI:-}" ];then
0087   echo "Running in GitLab CI"
0088   venv="${CI_PROJECT_DIR}/venv"
0089 fi
0090 
0091 if [ -n "${CI:-}" ];then
0092   run "${destination}/bin/python3" -m venv "${venv}"
0093   run "${venv}/bin/python3" -m pip install pyyaml jinja2
0094   set_env PATH "${venv}/bin:${destination}/bin/:${PATH}"
0095 fi
0096 
0097 set_env CMAKE_PREFIX_PATH "${destination}"
0098 set_env LD_LIBRARY_PATH "${destination}/lib"
0099 set_env ROOT_INCLUDE_PATH "${destination}/include"
0100 # Geant4 puts CLHEP in a subdirectory
0101 set_env ROOT_INCLUDE_PATH "${destination}/include/Geant4"
0102 # Pythia8 looks for settings in this directory
0103 set_env PYTHIA8DATA "${destination}/share/Pythia8/xmldoc"