builtin: reduce boilerplate when accessing package attributes
This commit is contained in:
parent
337ab120b3
commit
fc683b87f1
@ -100,7 +100,7 @@ def cmake_py_shared(self):
|
||||
|
||||
def cmake_args(self):
|
||||
try:
|
||||
self.spec["cxx"].package.standard_flag(language="cxx", standard="14")
|
||||
self["cxx"].standard_flag(language="cxx", standard="14")
|
||||
except UnsupportedCompilerFlag:
|
||||
InstallError("clingo requires a C++14-compliant C++ compiler")
|
||||
|
||||
|
@ -76,14 +76,14 @@ def setup_run_environment(self, env):
|
||||
return
|
||||
|
||||
if self.spec.dependencies(virtuals=("c",)):
|
||||
env.set("MPICC", self.spec["c"].package.cc)
|
||||
env.set("MPICC", self["c"].cc)
|
||||
|
||||
if self.spec.dependencies(virtuals=("cxx",)):
|
||||
env.set("MPICXX", self.spec["cxx"].package.cxx)
|
||||
env.set("MPICXX", self["cxx"].cxx)
|
||||
|
||||
if self.spec.dependencies(virtuals=("fortran",)):
|
||||
env.set("MPIFC", self.spec["fortran"].package.fc)
|
||||
env.set("MPIF77", self.spec["fortran"].package.fc)
|
||||
env.set("MPIFC", self["fortran"].fc)
|
||||
env.set("MPIF77", self["fortran"].fc)
|
||||
|
||||
def setup_dependent_package(self, module, dependent_spec):
|
||||
spec = self.spec
|
||||
|
@ -30,14 +30,14 @@ class CrayMvapich2(MpichEnvironmentModifications, Package):
|
||||
|
||||
def setup_run_environment(self, env):
|
||||
if self.spec.dependencies(virtuals=("c",)):
|
||||
env.set("MPICC", self.spec["c"].package.cc)
|
||||
env.set("MPICC", self["c"].cc)
|
||||
|
||||
if self.spec.dependencies(virtuals=("cxx",)):
|
||||
env.set("MPICXX", self.spec["cxx"].package.cxx)
|
||||
env.set("MPICXX", self["cxx"].cxx)
|
||||
|
||||
if self.spec.dependencies(virtuals=("fortran",)):
|
||||
env.set("MPIFC", self.spec["fortran"].package.fc)
|
||||
env.set("MPIF77", self.spec["fortran"].package.fc)
|
||||
env.set("MPIFC", self["fortran"].fc)
|
||||
env.set("MPIF77", self["fortran"].fc)
|
||||
|
||||
def install(self, spec, prefix):
|
||||
raise InstallError(
|
||||
|
@ -78,7 +78,7 @@ def install(self, spec, prefix):
|
||||
|
||||
def _get_libraries_macho(self):
|
||||
"""Same as _get_libraries_elf but for Mach-O binaries"""
|
||||
cc = Executable(self.spec["gcc"].package.cc)
|
||||
cc = Executable(self["gcc"].cc)
|
||||
path_and_install_name = []
|
||||
|
||||
for name in self.LIBRARIES:
|
||||
|
@ -104,8 +104,8 @@ def setup_build_environment(self, env):
|
||||
env.set("GOROOT_FINAL", self.spec.prefix.go)
|
||||
# We need to set CC/CXX_FOR_TARGET, otherwise cgo will use the
|
||||
# internal Spack wrappers and fail.
|
||||
env.set("CC_FOR_TARGET", self.spec["c"].package.cc)
|
||||
env.set("CXX_FOR_TARGET", self.spec["cxx"].package.cxx)
|
||||
env.set("CC_FOR_TARGET", self["c"].cc)
|
||||
env.set("CXX_FOR_TARGET", self["cxx"].cxx)
|
||||
env.set("GOMAXPROCS", make_jobs)
|
||||
|
||||
def build(self, spec, prefix):
|
||||
|
@ -70,5 +70,5 @@ def url_for_version(self, version):
|
||||
return url.format(version)
|
||||
|
||||
def configure_args(self):
|
||||
args = ["--with-xml-catalog={0}".format(self.spec["docbook-xml"].package.catalog)]
|
||||
args = ["--with-xml-catalog={0}".format(self["docbook-xml"].catalog)]
|
||||
return args
|
||||
|
@ -88,7 +88,7 @@ def setup_build_environment(self, env):
|
||||
# devenv is needed to convert ancient MSbuild project to modern
|
||||
# msbuild project so MSBuild versions older than 2010 can build this
|
||||
# project
|
||||
devenv_path = os.path.join(self.spec["msvc"].package.vs_root, "Common7", "IDE")
|
||||
devenv_path = os.path.join(self["msvc"].vs_root, "Common7", "IDE")
|
||||
env.prepend_path("PATH", devenv_path)
|
||||
|
||||
@property
|
||||
|
@ -110,7 +110,7 @@ def url_for_version(self, version):
|
||||
|
||||
def flag_handler(self, name, flags):
|
||||
if name == "cflags" and self.spec.satisfies("+pic"):
|
||||
flags.append(self.spec["c"].package.pic_flag)
|
||||
flags.append(self["c"].pic_flag)
|
||||
flags.append("-DPIC")
|
||||
return (flags, None, None)
|
||||
|
||||
|
@ -118,8 +118,7 @@ def cmake_python_hints(self):
|
||||
"""Include the python include path to the
|
||||
CMake based on current spec
|
||||
"""
|
||||
python = self.spec["python"]
|
||||
return [self.define("Python_INCLUDE_DIR", python.package.config_vars["include"])]
|
||||
return [self.define("Python_INCLUDE_DIR", self["python"].config_vars["include"])]
|
||||
|
||||
@classmethod
|
||||
def determine_version(cls, lib):
|
||||
|
@ -106,9 +106,9 @@ def setup_build_environment(self, env):
|
||||
|
||||
def flag_handler(self, name, flags):
|
||||
if name == "cflags":
|
||||
flags.append(self.spec["c"].package.pic_flag)
|
||||
flags.append(self["c"].pic_flag)
|
||||
elif name == "cxxflags":
|
||||
flags.append(self.spec["cxx"].package.pic_flag)
|
||||
flags.append(self["cxx"].pic_flag)
|
||||
|
||||
# ncurses@:6.0 fails in definition of macro 'mouse_trafo' without -P
|
||||
if self.spec.satisfies("@:6.0 %gcc@5.0:"):
|
||||
@ -118,7 +118,7 @@ def flag_handler(self, name, flags):
|
||||
# ncurses@:6.0 uses dynamic exception specifications not allowed in c++17
|
||||
if self.spec.satisfies("@:5"):
|
||||
if name == "cxxflags":
|
||||
flags.append(self.spec["cxx"].package.standard_flag(language="cxx", standard="14"))
|
||||
flags.append(self["cxx"].standard_flag(language="cxx", standard="14"))
|
||||
|
||||
return (flags, None, None)
|
||||
|
||||
|
@ -521,11 +521,11 @@ def install(self, spec, prefix):
|
||||
|
||||
makelocalrc_args = [
|
||||
"-gcc",
|
||||
spec["gcc"].package.cc,
|
||||
self["gcc"].cc,
|
||||
"-gpp",
|
||||
spec["gcc"].package.cxx,
|
||||
self["gcc"].cxx,
|
||||
"-g77",
|
||||
spec["gcc"].package.fortran,
|
||||
self["gcc"].fortran,
|
||||
"-x",
|
||||
compilers_bin,
|
||||
]
|
||||
|
@ -156,7 +156,7 @@ def install(self, spec, prefix):
|
||||
if spec.satisfies("@1.0"):
|
||||
options.append("no-krb5")
|
||||
# clang does not support the .arch directive in assembly files.
|
||||
if "clang" in self.spec["c"].package.cc and spec.target.family == "aarch64":
|
||||
if "clang" in self["c"].cc and spec.target.family == "aarch64":
|
||||
options.append("no-asm")
|
||||
elif "%nvhpc" in spec:
|
||||
# Last tested on nvidia@22.3 for x86_64:
|
||||
|
@ -49,7 +49,7 @@ def edit(self, spec, prefix):
|
||||
vars = [
|
||||
("VERSUFF", "-%s" % gcc_version),
|
||||
("CXX", compiler.cxx),
|
||||
("GCJ", spec["eclipse-gcj-parser"].package.gcj),
|
||||
("GCJ", self["eclipse-gcj-parser"].gcj),
|
||||
("GCJH", join_path(gcc_base, "bin", "gcjh")),
|
||||
("GJAR", join_path(gcc_base, "bin", "gjar")),
|
||||
("LIBGCJ", join_path(gcc_base, "share", "java", "libgcj-{0}.jar".format(gcc_version))),
|
||||
|
@ -67,9 +67,9 @@ def build_pl_args(self):
|
||||
def setup_build_environment(self, env):
|
||||
# These variables are exected by by the Build.PL file
|
||||
# even though we override the results via PERL_MB_OPT
|
||||
kent = self.spec["kentutils"]
|
||||
env.set("KENT_SRC", kent.prefix)
|
||||
env.set("MACHTYPE", kent.package.machtype)
|
||||
kent_pkg = self["kentutils"]
|
||||
env.set("KENT_SRC", kent_pkg.prefix)
|
||||
env.set("MACHTYPE", kent_pkg.machtype)
|
||||
|
||||
# Overriding this explicitly as an environmental variable
|
||||
# as the Build.PL script doesn't honnor the command line
|
||||
|
@ -337,7 +337,7 @@ def do_stage(self, mirror_only=False):
|
||||
def nmake_arguments(self):
|
||||
args = []
|
||||
if self.spec.satisfies("%msvc"):
|
||||
args.append("CCTYPE=%s" % self.spec["msvc"].package.short_msvc_version)
|
||||
args.append("CCTYPE=%s" % self["msvc"].short_msvc_version)
|
||||
else:
|
||||
raise RuntimeError("Perl unsupported for non MSVC compilers on Windows")
|
||||
args.append("INST_TOP=%s" % windows_sfn(self.prefix.replace("/", "\\")))
|
||||
@ -384,7 +384,7 @@ def configure_args(self):
|
||||
# https://github.com/spack/spack/pull/3081 and
|
||||
# https://github.com/spack/spack/pull/4416
|
||||
if spec.satisfies("%intel"):
|
||||
config_args.append("-Accflags={0}".format(self.spec["cc"].package.pic_flag))
|
||||
config_args.append("-Accflags={0}".format(self["c"].pic_flag))
|
||||
|
||||
if "+shared" in spec:
|
||||
config_args.append("-Duseshrplib")
|
||||
@ -546,7 +546,7 @@ def filter_config_dot_pm(self):
|
||||
"-MModule::Loaded", "-MConfig", "-e", "print is_loaded(Config)", output=str
|
||||
)
|
||||
|
||||
c_compiler = self.spec["c"].package.cc
|
||||
c_compiler = self["c"].cc
|
||||
with self.make_briefly_writable(config_dot_pm):
|
||||
match = "cc *=>.*"
|
||||
substitute = "cc => '{cc}',".format(cc=c_compiler)
|
||||
|
@ -120,7 +120,7 @@ def cmake_args(self):
|
||||
options.append(self.define("{}_PROVIDER".format(lib), provider))
|
||||
if "cray-libsci" in self.spec:
|
||||
for lib in ("CBLAS", "LAPACKE"):
|
||||
libsci_prefix = self.spec["cray-libsci"].package.external_prefix
|
||||
libsci_prefix = self["cray-libsci"].external_prefix
|
||||
options.append(self.define("{}_PROVIDER".format(lib), "generic"))
|
||||
options.append(
|
||||
self.define("{}_INCLUDE_DIRS".format(lib), join_path(libsci_prefix, "include"))
|
||||
|
@ -194,7 +194,7 @@ def cmake_args(self):
|
||||
python_library = spec["python"].libs[0]
|
||||
python_include = spec["python"].headers.directories[0]
|
||||
numpy_include = join_path(
|
||||
spec["py-numpy"].package.module.python_platlib, "numpy", "core", "include"
|
||||
self["py-numpy"].module.python_platlib, "numpy", "core", "include"
|
||||
)
|
||||
cmake_args.extend(
|
||||
[
|
||||
|
@ -60,7 +60,7 @@ def patch(self):
|
||||
|
||||
python_include = spec["python"].headers.directories[0]
|
||||
numpy_include = join_path(
|
||||
spec["py-numpy"].package.module.python_platlib, "numpy", "core", "include"
|
||||
self["py-numpy"].module.python_platlib, "numpy", "core", "include"
|
||||
)
|
||||
|
||||
libs = blas.libs + lapack.libs + libxc.libs
|
||||
|
@ -264,11 +264,11 @@ def setup_build_environment(self, env):
|
||||
|
||||
# Pick up BLAS/LAPACK from numpy
|
||||
if self.spec.satisfies("@:1.8"):
|
||||
self.spec["py-numpy"].package.setup_build_environment(env)
|
||||
self["py-numpy"].setup_build_environment(env)
|
||||
|
||||
@when("@1.9:")
|
||||
def config_settings(self, spec, prefix):
|
||||
blas, lapack = self.spec["py-numpy"].package.blas_lapack_pkg_config()
|
||||
blas, lapack = self["py-numpy"].blas_lapack_pkg_config()
|
||||
|
||||
if spec.satisfies("%aocc") or spec.satisfies("%clang@18:"):
|
||||
fortran_std = "none"
|
||||
@ -286,10 +286,9 @@ def config_settings(self, spec, prefix):
|
||||
},
|
||||
}
|
||||
|
||||
@when("@:1.8")
|
||||
@run_before("install")
|
||||
@run_before("install", when="@:1.8")
|
||||
def set_blas_lapack(self):
|
||||
self.spec["py-numpy"].package.blas_lapack_site_cfg()
|
||||
self["py-numpy"].blas_lapack_site_cfg()
|
||||
|
||||
@run_after("install")
|
||||
@on_package_attributes(run_tests=True)
|
||||
|
@ -586,7 +586,7 @@ def configure_args(self):
|
||||
config_args.append("--without-ensurepip")
|
||||
|
||||
if "+pic" in spec:
|
||||
cflags.append(self.spec["c"].package.pic_flag)
|
||||
cflags.append(self["c"].pic_flag)
|
||||
|
||||
if "+ssl" in spec:
|
||||
config_args.append("--with-openssl={0}".format(spec["openssl"].prefix))
|
||||
@ -704,9 +704,9 @@ def filter_compilers(self):
|
||||
|
||||
filenames = [self.get_sysconfigdata_name(), self.config_vars["makefile_filename"]]
|
||||
|
||||
filter_file(spack_cc, self.spec["c"].package.cc, *filenames, **kwargs)
|
||||
filter_file(spack_cc, self["c"].cc, *filenames, **kwargs)
|
||||
if spack_cxx:
|
||||
filter_file(spack_cxx, self.spec["cxx"].package.cxx, *filenames, **kwargs)
|
||||
filter_file(spack_cxx, self["cxx"].cxx, *filenames, **kwargs)
|
||||
|
||||
@run_after("install")
|
||||
def symlink(self):
|
||||
|
@ -198,7 +198,7 @@ class Qgis(CMakePackage):
|
||||
@run_before("cmake", when="^py-pyqt5")
|
||||
def fix_pyqt5_cmake(self):
|
||||
cmfile = FileFilter(join_path("cmake", "FindPyQt5.cmake"))
|
||||
pyqtpath = join_path(self.spec["py-pyqt5"].package.module.python_platlib, "PyQt5")
|
||||
pyqtpath = join_path(self["py-pyqt5"].module.python_platlib, "PyQt5")
|
||||
cmfile.filter(
|
||||
'SET(PYQT5_MOD_DIR "${Python_SITEARCH}/PyQt5")',
|
||||
'SET(PYQT5_MOD_DIR "' + pyqtpath + '")',
|
||||
|
@ -77,9 +77,7 @@ def with_torch(self):
|
||||
@property
|
||||
def torch_dir(self):
|
||||
return (
|
||||
join_path(self.spec["py-torch"].package.cmake_prefix_paths[0], "Torch")
|
||||
if self.with_torch
|
||||
else None
|
||||
join_path(self["py-torch"].cmake_prefix_paths[0], "Torch") if self.with_torch else None
|
||||
)
|
||||
|
||||
@property
|
||||
|
@ -63,7 +63,7 @@ def configure_args(self):
|
||||
]
|
||||
|
||||
if self.spec.satisfies("^intel-oneapi-mpi"):
|
||||
args.append("--with-mpi=" + self.spec["intel-oneapi-mpi"].package.component_prefix)
|
||||
args.append("--with-mpi=" + self["intel-oneapi-mpi"].component_prefix)
|
||||
else:
|
||||
args.append("--with-mpi=" + self.spec["mpi"].prefix)
|
||||
|
||||
|
@ -71,7 +71,7 @@ def libs(self):
|
||||
|
||||
def flag_handler(self, name, flags):
|
||||
if name == "cflags" and self.spec.satisfies("+pic build_system=autotools"):
|
||||
flags.append(self.spec["c"].package.pic_flag)
|
||||
flags.append(self["c"].pic_flag)
|
||||
return (flags, None, None)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user