|
| 1 | +#!/bin/sh -ex |
| 2 | +#-------------------------------- -*- sh -*- ---------------------------------# |
| 3 | +# Copyright Celeritas contributors: see top-level COPYRIGHT file for details |
| 4 | +# SPDX-License-Identifier: (Apache-2.0 OR MIT) |
| 5 | +# |
| 6 | +#-----------------------------------------------------------------------------# |
| 7 | +# Note: to launch the apptainer run this |
| 8 | +apptainer_fermilab() { |
| 9 | + if ! [ -d "${SCRATCHDIR}" ]; then |
| 10 | + echo "Scratch directory does not exist: ru |
| 11 | + . scripts/env/scisoftbuild01.sh |
| 12 | +" |
| 13 | + return 1 |
| 14 | + fi |
| 15 | + |
| 16 | + image=${1:-fnal-dev-sl7:latest} |
| 17 | + |
| 18 | + # Start apptainer, forwarding necessary directories |
| 19 | + SUBDOMAIN=mis # codespell:ignore |
| 20 | + exec /cvmfs/oasis.opensciencegrid.org/$SUBDOMAIN/apptainer/current/bin/apptainer \ |
| 21 | + shell --shell=/bin/bash \ |
| 22 | + -B /cvmfs,$SCRATCHDIR,$HOME,$XDG_RUNTIME_DIR,/opt,/etc/hostname,/etc/hosts,/etc/krb5.conf \ |
| 23 | + --ipc --pid \ |
| 24 | + /cvmfs/singularity.opensciencegrid.org/fermilab/${image} |
| 25 | +} |
| 26 | + |
| 27 | +#-----------------------------------------------------------------------------# |
| 28 | + |
| 29 | +# Reduce I/O metadata overhead by avoiding language translation lookups |
| 30 | +export LC_ALL=C |
| 31 | + |
| 32 | +# Allow running from user rc setup outside of build.sh environment |
| 33 | +if ! command -v celerlog >/dev/null 2>&1; then |
| 34 | + celerlog() { |
| 35 | + printf "%s: %s\n" "$1" "$2" >&2 |
| 36 | + } |
| 37 | +fi |
| 38 | +if [ -z "${SYSTEM_NAME}" ]; then |
| 39 | + SYSTEM_NAME=$(uname -s) |
| 40 | + celerlog debug "Set SYSTEM_NAME=${SYSTEM_NAME}" |
| 41 | +fi |
| 42 | + |
| 43 | +if [ -n "${APPTAINER_CONTAINER}" ]; then |
| 44 | + export MRB_PROJECT=larsoft |
| 45 | + export MRB_PROJECT_VERSION=v10_14_01 |
| 46 | + export MRB_QUALS=e26:prof |
| 47 | + celerlog info "Running in apptainer ${APPTAINER_CONTAINER}" |
| 48 | + if [ -z "${UPS_DIR}" ]; then |
| 49 | + celerlog info "Setting up DUNE UPS" |
| 50 | + . /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh |
| 51 | + celerlog debug "Using UPS_OVERRIDE=${UPS_OVERRIDE}, MRB_PROJECT=${MRB_PROJECT}" |
| 52 | + fi |
| 53 | + if [ -z "${SETUP_LARCORE}" ]; then |
| 54 | + # Set up larsoft build defaults with UPS |
| 55 | + celerlog info "Setting up ${MRB_PROJECT} ${MRB_PROJECT_VERSION} with qualifiers '${MRB_QUALS}'" |
| 56 | + setup ${MRB_PROJECT} ${MRB_PROJECT_VERSION} -q ${MRB_QUALS} || return $? |
| 57 | + fi |
| 58 | +fi |
| 59 | + |
| 60 | +# Set default scratchdir; /scratch should exist according to excl docs |
| 61 | +export SCRATCHDIR="${SCRATCHDIR:-/scratch/$USER}" |
| 62 | +for _d in build install cache; do |
| 63 | + # Create build/install in higher-performance local-but-persistent dir |
| 64 | + _scratch="$SCRATCHDIR/$_d" |
| 65 | + if ! [ -d "${_scratch}" ]; then |
| 66 | + celerlog info "Creating scratch directory '${_scratch}'" |
| 67 | + mkdir -p "${_scratch}" || return $? |
| 68 | + chmod 700 "${_scratch}" || return $? |
| 69 | + fi |
| 70 | + unset _scratch |
| 71 | +done |
| 72 | + |
| 73 | +# Set up larsoft if running inside an apptainer |
| 74 | +if [ -n "${MRB_PROJECT}" ]; then |
| 75 | + LARSCRATCHDIR="${SCRATCHDIR}/${MRB_PROJECT}" |
| 76 | + if ! [ -d "${LARSCRATCHDIR}" ]; then |
| 77 | + celerlog info "Creating MRB dev area in ${LARSCRATCHDIR}..." |
| 78 | + mkdir -p "${LARSCRATCHDIR}" || return $? |
| 79 | + ( |
| 80 | + cd "${LARSCRATCHDIR}" |
| 81 | + mrb newDev |
| 82 | + ) |
| 83 | + celerlog debug "MRB environment created" |
| 84 | + fi |
| 85 | + _setup_filename="${LARSCRATCHDIR}/localProducts_${MRB_PROJECT}_${MRB_PROJECT_VERSION}_${MRB_QUALS//:/_}/setup" |
| 86 | + if ! [ -f "${_setup_filename}" ]; then |
| 87 | + celerlog warn "Expected setup file at ${_setup_filename}: MRB may not have been set up correctly" |
| 88 | + _setup_filename=$(print %s"${LARSCRATCHDIR}/localProducts_${MRB_PROJECT}*/setup") |
| 89 | + if [ -f "${_setup_filename}" ]; then |
| 90 | + celerlog info "Found setup file ${_setup_filename}" |
| 91 | + fi |
| 92 | + fi |
| 93 | + . "${_setup_filename}" |
| 94 | +fi |
| 95 | + |
| 96 | +# Check out a package so that mrb will load cmake (may be arbitrary?) |
| 97 | +if [ -n "${MRB_SOURCE}" ]; then |
| 98 | + _pkg=larsim |
| 99 | + if ! [ -d "${MRB_SOURCE}/${_pkg}" ]; then |
| 100 | + celerlog info "Installing ${_pkg}" |
| 101 | + mrb g ${_pkg} |
| 102 | + fi |
| 103 | + |
| 104 | + # Now that a package exists in MRB source, cmake and dependencies can load |
| 105 | + celerlog info "Activating MRB environment" |
| 106 | + mrbsetenv |
| 107 | + celerlog debug "MRB setup complete" |
| 108 | +fi |
| 109 | + |
| 110 | +if [ -n "$CELER_SOURCE_DIR" ]; then |
| 111 | + _clangd="$CELER_SOURCE_DIR/.clangd" |
| 112 | + if [ ! -e "${_clangd}" ]; then |
| 113 | + # Create clangd compatible with the system and build config |
| 114 | + _gcc_version=$(gcc -dumpversion | cut -d. -f1) |
| 115 | + celerlog info "Creating clangd config using GCC ${_gcc_version}: ${_clangd}" |
| 116 | + cat > "${_clangd}" << EOF |
| 117 | +CompileFlags: |
| 118 | + CompilationDatabase: ${SCRATCHDIR}/build/celeritas-reldeb-orange |
| 119 | + Add: |
| 120 | + [ |
| 121 | + -isystem, |
| 122 | + /usr/include/c++/${_gcc_version}, |
| 123 | + -isystem, |
| 124 | + /usr/local/include, |
| 125 | + -isystem, |
| 126 | + /usr/include, |
| 127 | + -isystem, |
| 128 | + /usr/include/x86_64-linux-gnu/c++/${_gcc_version}, |
| 129 | + ] |
| 130 | +EOF |
| 131 | + fi |
| 132 | + unset _clangd |
| 133 | +fi |
| 134 | + |
| 135 | +export XDG_CACHE_HOME="${SCRATCHDIR}/cache" |
0 commit comments