Skip to content

Commit

Permalink
Use @sanitize_paths decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
knoepfel authored and greenc-FNAL committed May 14, 2024
1 parent 26238f3 commit ae48f2b
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 44 deletions.
9 changes: 3 additions & 6 deletions packages/art-root-io/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,20 @@ class ArtRootIo(CMakePackage, FnalGithubPackage):
def cmake_args(self):
return ["--trace-expand", self.define_from_variant("CMAKE_CXX_STANDARD", "cxxstd")]

@sanitize_paths
def setup_build_environment(self, env):
prefix = Prefix(self.build_directory)
# Binaries.
env.prepend_path("PATH", prefix.bin)
# Ensure we can find plugin libraries.
env.prepend_path("CET_PLUGIN_PATH", prefix.lib)
# Cleanup.
sanitize_environments(env, "PATH", "CET_PLUGIN_PATH")

@sanitize_paths
def setup_run_environment(self, env):
# Ensure we can find plugin libraries.
env.prepend_path("CET_PLUGIN_PATH", self.prefix.lib)
# Cleanup.
sanitize_environments(env, "CET_PLUGIN_PATH")

@sanitize_paths
def setup_dependent_build_environment(self, env, dependent_spec):
# Ensure we can find plugin libraries.
env.prepend_path("CET_PLUGIN_PATH", self.prefix.lib)
# Cleanup.
sanitize_environments(env, "CET_PLUGIN_PATH")
7 changes: 3 additions & 4 deletions packages/art/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Art(CMakePackage, FnalGithubPackage):
def cmake_args(self):
return [self.define_from_variant("CMAKE_CXX_STANDARD", "cxxstd")]

@sanitize_paths
def setup_build_environment(self, env):
prefix = Prefix(self.build_directory)
# Binaries.
Expand All @@ -84,18 +85,16 @@ def setup_build_environment(self, env):
env.prepend_path("CET_PLUGIN_PATH", prefix.lib)
# Perl modules.
env.prepend_path("PERL5LIB", prefix.perllib)
# Cleaup.
sanitize_environments(env, "PATH", "CET_PLUGIN_PATH", "PERL5LIB")

@sanitize_paths
def setup_dependent_build_environment(self, env, dependent_spec):
prefix = self.prefix
# Ensure we can find plugin libraries.
env.prepend_path("CET_PLUGIN_PATH", prefix.lib)
# Perl modules.
env.prepend_path("PERL5LIB", prefix.perllib)
# Cleaup.
sanitize_environments(env, "CET_PLUGIN_PATH", "PERL5LIB")

@sanitize_paths
def setup_run_environment(self, env):
prefix = self.prefix
# Ensure we can find plugin libraries.
Expand Down
10 changes: 3 additions & 7 deletions packages/canvas-root-io/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class CanvasRootIo(CMakePackage, FnalGithubPackage):
def cmake_args(self):
return [self.define_from_variant("CMAKE_CXX_STANDARD", "cxxstd")]

@sanitize_paths
def setup_build_environment(self, env):
prefix = Prefix(self.build_directory)
# Binaries.
Expand All @@ -80,9 +81,8 @@ def setup_build_environment(self, env):
root=False, cover="nodes", order="post", deptype=("link"), direction="children"
):
env.prepend_path("ROOT_INCLUDE_PATH", self.spec[d.name].prefix.include)
# Cleanup.
sanitize_environments(env, "PATH", "LD_LIBRARY_PATH", "ROOT_INCLUDE_PATH")

@sanitize_paths
def setup_run_environment(self, env):
prefix = self.prefix
# Set LD_LIBRARY_PATH so that dictionaries are available downstream
Expand All @@ -94,9 +94,7 @@ def setup_run_environment(self, env):
env.prepend_path("ROOT_INCLUDE_PATH", self.spec[d.name].prefix.include)
env.prepend_path("ROOT_INCLUDE_PATH", prefix.include)

# Cleanup.
sanitize_environments(env, "CET_PLUGIN_PATH", "ROOT_INCLUDE_PATH")

@sanitize_paths
def setup_dependent_build_environment(self, env, dependent_spec):
# Set LD_LIBRARY_PATH so CheckClassVersion.py can find cppyy lib
env.prepend_path("LD_LIBRARY_PATH", self.spec["root"].prefix.lib)
Expand All @@ -105,5 +103,3 @@ def setup_dependent_build_environment(self, env, dependent_spec):
root=False, cover="nodes", order="post", deptype=("link"), direction="children"
):
env.prepend_path("ROOT_INCLUDE_PATH", dependent_spec[d.name].prefix.include)
# Cleanup.
sanitize_environments(env, "CET_PLUGIN_PATH", "LD_LIBRARY_PATH", "ROOT_INCLUDE_PATH")
3 changes: 1 addition & 2 deletions packages/canvas/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ class Canvas(CMakePackage, FnalGithubPackage):
def cmake_args(self):
return [self.define_from_variant("CMAKE_CXX_STANDARD", "cxxstd")]

@sanitize_paths
def setup_build_environment(self, env):
# Binaries.
env.prepend_path("PATH", os.path.join(self.build_directory, "bin"))
# Cleanup.
sanitize_environments(env, "PATH")
3 changes: 1 addition & 2 deletions packages/cetlib-except/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class CetlibExcept(CMakePackage, FnalGithubPackage):
def cmake_args(self):
return [self.define_from_variant("CMAKE_CXX_STANDARD", "cxxstd")]

@sanitize_paths
def setup_build_environment(self, env):
# For tests.
env.prepend_path("PATH", os.path.join(self.build_directory, "bin"))
# Cleanup.
sanitize_environments(env, "PATH")
9 changes: 3 additions & 6 deletions packages/cetlib/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Cetlib(CMakePackage, FnalGithubPackage):
def cmake_args(self):
return [self.define_from_variant("CMAKE_CXX_STANDARD", "cxxstd")]

@sanitize_paths
def setup_build_environment(self, env):
prefix = Prefix(self.build_directory)
# Binaries required for some of the tests.
Expand All @@ -76,17 +77,13 @@ def setup_build_environment(self, env):
env.prepend_path("CET_PLUGIN_PATH", prefix.lib)
# Perl modules.
env.prepend_path("PERL5LIB", prefix.perllib)
# Cleanup.
sanitize_environments(env, "PATH", "CET_PLUGIN_PATH", "PERL5LIB")

@sanitize_paths
def setup_run_environment(self, env):
# Perl modules.
env.prepend_path("PERL5LIB", self.prefix.perllib)
# Cleanup.
sanitize_environments(env, "PATH", "PERL5LIB")

@sanitize_paths
def setup_dependent_build_environment(self, env, dependent_spec):
# Perl modules.
env.prepend_path("PERL5LIB", self.prefix.perllib)
# Cleanup.
sanitize_environments(env, "PERL5LIB")
2 changes: 1 addition & 1 deletion packages/critic/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ def setup_build_environment(self, env):
# ... and in the interpreter.
env.env_modifications.append(PrependEnv("LD_LIBRARY_PATH", "CET_PLUGIN_PATH"))
# Cleanup.
sanitize_environments(env, "PATH", "CET_PLUGIN_PATH", "LD_LIBRARY_PATH")
sanitize_environment(env, "PATH", "CET_PLUGIN_PATH", "LD_LIBRARY_PATH")
4 changes: 2 additions & 2 deletions packages/fhicl-cpp/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ class FhiclCpp(CMakePackage, FnalGithubPackage):
def cmake_args(self):
return [self.define_from_variant("CMAKE_CXX_STANDARD", "cxxstd")]

@sanitize_paths
def setup_build_environment(self, env):
# Path for tests.
env.prepend_path("PATH", os.path.join(self.build_directory, "bin"))
# Cleanup
sanitize_environments(env, "PATH")

@sanitize_paths
def setup_run_environment(self, env):
# Bash completions.
bindir = self.prefix.bin
Expand Down
19 changes: 15 additions & 4 deletions packages/fnal-github-package/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import llnl.util.tty as tty
import spack.util.spack_json as sjson
from spack.util.environment import PrependPath
from spack.package import *
from spack.version import *
from functools import wraps
Expand Down Expand Up @@ -36,10 +37,20 @@ def wrapped_cmake_args(pkg):
return wrapped_cmake_args


def sanitize_environments(env, *env_vars):
for var in env_vars:
env.prune_duplicate_paths(var)
env.deprioritize_system_paths(var)
def sanitize_environment(env, *env_paths):
for path in env_paths:
env.prune_duplicate_paths(path)
env.deprioritize_system_paths(path)


def sanitize_paths(f):
@wraps(f)
def wrapped_setup_build_environment(pkg, env, *extra_args):
f(pkg, env, *extra_args)
paths = [mod.name for mod in env.env_modifications if type(mod) == PrependPath]
sanitize_environment(env, *paths)

return wrapped_setup_build_environment


def dotted_version_str(name):
Expand Down
4 changes: 2 additions & 2 deletions packages/gallery/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ class Gallery(CMakePackage, FnalGithubPackage):
def cmake_args(self):
return [self.define_from_variant("CMAKE_CXX_STANDARD", "cxxstd")]

@sanitize_paths
def setup_dependent_build_environment(self, env, dependent_spec):
prefix = self.prefix
# Ensure we can find plugin libraries.
env.prepend_path("CET_PLUGIN_PATH", prefix.lib)
# Cleaup.
sanitize_environments(env, "CET_PLUGIN_PATH")

@sanitize_paths
def setup_run_environment(self, run_env):
run_env.prepend_path("ROOT_INCLUDE_PATH", self.prefix.include)
3 changes: 1 addition & 2 deletions packages/hep-concurrency/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class HepConcurrency(CMakePackage, FnalGithubPackage):
def cmake_args(self):
return [self.define_from_variant("CMAKE_CXX_STANDARD", "cxxstd")]

@sanitize_paths
def setup_build_environment(self, env):
# PATH for tests.
env.prepend_path("PATH", os.path.join(self.build_directory, "bin"))
# Cleanup.
sanitize_environments(env, "PATH")
9 changes: 3 additions & 6 deletions packages/messagefacility/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Messagefacility(CMakePackage, FnalGithubPackage):
def cmake_args(self):
return [self.define_from_variant("CMAKE_CXX_STANDARD", "cxxstd")]

@sanitize_paths
def setup_build_environment(self, env):
prefix = Prefix(self.build_directory)
# Binaries.
Expand All @@ -73,23 +74,19 @@ def setup_build_environment(self, env):
env.prepend_path("CET_PLUGIN_PATH", prefix.lib)
# Perl modules.
env.prepend_path("PERL5LIB", prefix.perllib)
# Cleaup.
sanitize_environments(env, "PATH", "CET_PLUGIN_PATH", "PERL5LIB")

@sanitize_paths
def setup_run_environment(self, env):
prefix = self.prefix
# Ensure we can find plugin libraries.
env.prepend_path("CET_PLUGIN_PATH", prefix.lib)
# Perl modules.
env.prepend_path("PERL5LIB", prefix.perllib)
# Cleaup.
sanitize_environments(env, "CET_PLUGIN_PATH", "PERL5LIB")

@sanitize_paths
def setup_dependent_build_environment(self, env, dependent_spec):
prefix = self.prefix
# Ensure we can find plugin libraries.
env.prepend_path("CET_PLUGIN_PATH", prefix.lib)
# Perl modules.
env.prepend_path("PERL5LIB", prefix.perllib)
# Cleaup.
sanitize_environments(env, "CET_PLUGIN_PATH", "PERL5LIB")

0 comments on commit ae48f2b

Please sign in to comment.