Skip to content

Commit

Permalink
[cms] Add option to pass args to custom cmssw setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
riga committed Apr 2, 2024
1 parent d585cf8 commit 64dbe8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 9 additions & 2 deletions law/contrib/cms/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CMSSWSandbox(BashSandbox):
# (names corresond to variables used in setup_cmssw.sh script)
Variables = collections.namedtuple(
"Variables",
["version", "setup", "dir", "arch", "cores"],
["version", "setup", "args", "dir", "arch", "cores"],
)

@classmethod
Expand Down Expand Up @@ -72,7 +72,14 @@ def __init__(self, *args, **kwargs):

# when no env cache path was given, set it to a deterministic path in LAW_HOME
if not self.env_cache_path:
h = create_hash((self.sandbox_type, self.env_cache_key))
h = create_hash((
self.sandbox_type,
self.env_cache_key,
self.variables.arch,
self.variables.setup,
self.variables.args,
self.variables.dir,
))
self.env_cache_path = law_home_path(
"cms",
"{}_cache".format(self.sandbox_type),
Expand Down
9 changes: 6 additions & 3 deletions law/contrib/cms/scripts/setup_cmssw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# The scram architecture to use. Optional.
# - LAW_CMSSW_SETUP:
# A path to a script that is called inside the src directory upon installation. Optional.
# - LAW_CMSSW_ARGS:
# Space-separated arguments that are passed to the setup script when given. Optional.
# - LAW_CMSSW_DIR:
# The directory in which CMSSW is installed. Defaults to $LAW_HOME/cms/cmssw.
# - LAW_CMSSW_CORES:
Expand Down Expand Up @@ -77,6 +79,7 @@ setup_cmssw() {
local custom_cmssw_version="${LAW_CMSSW_VERSION}"
local custom_scram_arch="${LAW_CMSSW_ARCH}"
local custom_setup_script="${LAW_CMSSW_SETUP}"
local custom_setup_args="${LAW_CMSSW_ARGS}"
local custom_install_dir="${LAW_CMSSW_DIR}"
local custom_install_cores="${LAW_CMSSW_CORES:-1}"

Expand All @@ -86,7 +89,7 @@ setup_cmssw() {
return "3"
fi
if [ ! -z "${custom_setup_script}" ] && [ ! -f "${custom_setup_script}" ]; then
>&2 echo "custom setup script ${custom_setup_script} (LAW_CMSSW_SETUP) does not exist"
>&2 echo "custom setup script '${custom_setup_script}' (LAW_CMSSW_SETUP) does not exist"
return "4"
fi
if [ -z "${custom_install_dir}" ]; then
Expand Down Expand Up @@ -158,11 +161,11 @@ setup_cmssw() {

# call the custom setup on top
if [ -f "${custom_setup_script}" ]; then
echo "running custom setup script ${custom_setup_script}"
echo "running custom setup script '${custom_setup_script}' with arguments '${custom_setup_args}'"
(
cd "${custom_src_dir}"
eval "$( scramv1 runtime -sh )" && \
bash "${custom_setup_script}" && \
source "${custom_setup_script}" ${custom_setup_args} && \
scram b -j "${custom_install_cores}"
)
fi
Expand Down

0 comments on commit 64dbe8d

Please sign in to comment.