From 01f61a2eba972f216ccb5b8cf815c0eab39557c7 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Tue, 23 Apr 2024 12:47:33 +0200 Subject: [PATCH] Remove import distro from packages and docs (#43772) --- lib/spack/docs/developer_guide.rst | 8 +++---- lib/spack/spack/build_systems/rocm.py | 24 +++++++------------ .../builtin/packages/hip-tensor/package.py | 2 +- .../repos/builtin/packages/hipblas/package.py | 2 +- .../repos/builtin/packages/hipcub/package.py | 2 +- .../repos/builtin/packages/hipfft/package.py | 2 +- .../repos/builtin/packages/hiprand/package.py | 2 +- .../builtin/packages/hipsolver/package.py | 2 +- .../builtin/packages/hipsparse/package.py | 2 +- .../builtin/packages/roctracer-dev/package.py | 2 +- 10 files changed, 21 insertions(+), 27 deletions(-) diff --git a/lib/spack/docs/developer_guide.rst b/lib/spack/docs/developer_guide.rst index a87ed5f576..91550f795f 100644 --- a/lib/spack/docs/developer_guide.rst +++ b/lib/spack/docs/developer_guide.rst @@ -552,11 +552,11 @@ With either interpreter you can run a single command: .. code-block:: console - $ spack python -c 'import distro; distro.linux_distribution()' - ('Ubuntu', '18.04', 'Bionic Beaver') + $ spack python -c 'from spack.spec import Spec; Spec("python").concretized()' + ... - $ spack python -i ipython -c 'import distro; distro.linux_distribution()' - Out[1]: ('Ubuntu', '18.04', 'Bionic Beaver') + $ spack python -i ipython -c 'from spack.spec import Spec; Spec("python").concretized()' + Out[1]: ... or a file: diff --git a/lib/spack/spack/build_systems/rocm.py b/lib/spack/spack/build_systems/rocm.py index 440cab7fde..8094c90c2e 100644 --- a/lib/spack/spack/build_systems/rocm.py +++ b/lib/spack/spack/build_systems/rocm.py @@ -80,6 +80,7 @@ import spack.variant from spack.directives import conflicts, depends_on, variant from spack.package_base import PackageBase +from spack.util.environment import EnvironmentModifications class ROCmPackage(PackageBase): @@ -156,30 +157,23 @@ def hip_flags(amdgpu_target): archs = ",".join(amdgpu_target) return "--amdgpu-target={0}".format(archs) - # ASAN - @staticmethod - def asan_on(env, llvm_path): + def asan_on(self, env: EnvironmentModifications): + llvm_path = self.spec["llvm-amdgpu"].prefix env.set("CC", llvm_path + "/bin/clang") env.set("CXX", llvm_path + "/bin/clang++") env.set("ASAN_OPTIONS", "detect_leaks=0") - for root, dirs, files in os.walk(llvm_path): + for root, _, files in os.walk(llvm_path): if "libclang_rt.asan-x86_64.so" in files: asan_lib_path = root env.prepend_path("LD_LIBRARY_PATH", asan_lib_path) - SET_DWARF_VERSION_4 = "" - try: - # This will throw an error if imported on a non-Linux platform. - import distro - - distname = distro.id() - except ImportError: - distname = "unknown" - if "rhel" in distname or "sles" in distname: + if "rhel" in self.spec.os or "sles" in self.spec.os: SET_DWARF_VERSION_4 = "-gdwarf-5" + else: + SET_DWARF_VERSION_4 = "" - env.set("CFLAGS", "-fsanitize=address -shared-libasan -g " + SET_DWARF_VERSION_4) - env.set("CXXFLAGS", "-fsanitize=address -shared-libasan -g " + SET_DWARF_VERSION_4) + env.set("CFLAGS", f"-fsanitize=address -shared-libasan -g {SET_DWARF_VERSION_4}") + env.set("CXXFLAGS", f"-fsanitize=address -shared-libasan -g {SET_DWARF_VERSION_4}") env.set("LDFLAGS", "-Wl,--enable-new-dtags -fuse-ld=lld -fsanitize=address -g -Wl,") # HIP version vs Architecture diff --git a/var/spack/repos/builtin/packages/hip-tensor/package.py b/var/spack/repos/builtin/packages/hip-tensor/package.py index a8d1a03f5e..fd7ed68d36 100644 --- a/var/spack/repos/builtin/packages/hip-tensor/package.py +++ b/var/spack/repos/builtin/packages/hip-tensor/package.py @@ -31,4 +31,4 @@ class HipTensor(CMakePackage, ROCmPackage): def setup_build_environment(self, env): env.set("CXX", self.spec["hip"].hipcc) if self.spec.satisfies("+asan"): - self.asan_on(env, self.spec["llvm-amdgpu"].prefix) + self.asan_on(env) diff --git a/var/spack/repos/builtin/packages/hipblas/package.py b/var/spack/repos/builtin/packages/hipblas/package.py index 3115b52bb1..7a50ee5b46 100644 --- a/var/spack/repos/builtin/packages/hipblas/package.py +++ b/var/spack/repos/builtin/packages/hipblas/package.py @@ -117,7 +117,7 @@ def determine_version(cls, lib): def setup_build_environment(self, env): if self.spec.satisfies("+asan"): - self.asan_on(env, self.spec["llvm-amdgpu"].prefix) + self.asan_on(env) def cmake_args(self): args = [ diff --git a/var/spack/repos/builtin/packages/hipcub/package.py b/var/spack/repos/builtin/packages/hipcub/package.py index 30dd6b5c50..4f75d0476e 100644 --- a/var/spack/repos/builtin/packages/hipcub/package.py +++ b/var/spack/repos/builtin/packages/hipcub/package.py @@ -89,7 +89,7 @@ def setup_build_environment(self, env): if self.spec.satisfies("+rocm"): env.set("CXX", self.spec["hip"].hipcc) if self.spec.satisfies("+asan"): - self.asan_on(env, self.spec["llvm-amdgpu"].prefix) + self.asan_on(env) def cmake_args(self): args = [self.define("BUILD_TEST", self.run_tests)] diff --git a/var/spack/repos/builtin/packages/hipfft/package.py b/var/spack/repos/builtin/packages/hipfft/package.py index 818327b4fb..e1dfcb48b4 100644 --- a/var/spack/repos/builtin/packages/hipfft/package.py +++ b/var/spack/repos/builtin/packages/hipfft/package.py @@ -94,7 +94,7 @@ class Hipfft(CMakePackage, CudaPackage, ROCmPackage): def setup_build_environment(self, env): if self.spec.satisfies("+asan"): - self.asan_on(env, self.spec["llvm-amdgpu"].prefix) + self.asan_on(env) def cmake_args(self): args = [self.define("BUILD_CLIENTS_SAMPLES", "OFF")] diff --git a/var/spack/repos/builtin/packages/hiprand/package.py b/var/spack/repos/builtin/packages/hiprand/package.py index 4152dddc0a..75b0f921d0 100644 --- a/var/spack/repos/builtin/packages/hiprand/package.py +++ b/var/spack/repos/builtin/packages/hiprand/package.py @@ -108,7 +108,7 @@ class Hiprand(CMakePackage, CudaPackage, ROCmPackage): def setup_build_environment(self, env): env.set("CXX", self.spec["hip"].hipcc) if self.spec.satisfies("+asan"): - self.asan_on(env, self.spec["llvm-amdgpu"].prefix) + self.asan_on(env) @classmethod def determine_version(cls, lib): diff --git a/var/spack/repos/builtin/packages/hipsolver/package.py b/var/spack/repos/builtin/packages/hipsolver/package.py index 9d07038f0d..22355a74b9 100644 --- a/var/spack/repos/builtin/packages/hipsolver/package.py +++ b/var/spack/repos/builtin/packages/hipsolver/package.py @@ -127,7 +127,7 @@ def determine_version(cls, lib): def setup_build_environment(self, env): if self.spec.satisfies("+asan"): - self.asan_on(env, self.spec["llvm-amdgpu"].prefix) + self.asan_on(env) def cmake_args(self): args = [ diff --git a/var/spack/repos/builtin/packages/hipsparse/package.py b/var/spack/repos/builtin/packages/hipsparse/package.py index 4efec56801..004f88b4e0 100644 --- a/var/spack/repos/builtin/packages/hipsparse/package.py +++ b/var/spack/repos/builtin/packages/hipsparse/package.py @@ -103,7 +103,7 @@ def determine_version(cls, lib): def setup_build_environment(self, env): if self.spec.satisfies("+asan"): - self.asan_on(env, self.spec["llvm-amdgpu"].prefix) + self.asan_on(env) def cmake_args(self): args = [ diff --git a/var/spack/repos/builtin/packages/roctracer-dev/package.py b/var/spack/repos/builtin/packages/roctracer-dev/package.py index 662ca46a9b..ea1d0c9263 100644 --- a/var/spack/repos/builtin/packages/roctracer-dev/package.py +++ b/var/spack/repos/builtin/packages/roctracer-dev/package.py @@ -105,7 +105,7 @@ def patch(self): def setup_build_environment(self, env): if self.spec.satisfies("+asan"): - self.asan_on(env, self.spec["llvm-amdgpu"].prefix) + self.asan_on(env) def cmake_args(self): args = [