diff options
author | Peter Scheibel <scheibel1@llnl.gov> | 2023-05-17 00:27:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-17 09:27:05 +0200 |
commit | 7a3da0f606223659458e0811c00c0514ae8d9d31 (patch) | |
tree | a3d2549645f9df267d836f460e950ecd9f6c690a /var | |
parent | d96406a161c035792729d29c03a3ff66e4cd0e67 (diff) | |
download | spack-7a3da0f606223659458e0811c00c0514ae8d9d31.tar.gz spack-7a3da0f606223659458e0811c00c0514ae8d9d31.tar.bz2 spack-7a3da0f606223659458e0811c00c0514ae8d9d31.tar.xz spack-7a3da0f606223659458e0811c00c0514ae8d9d31.zip |
Tk/Tcl packages: speed up file search (#35902)
Diffstat (limited to 'var')
-rw-r--r-- | var/spack/repos/builtin/packages/tcl/package.py | 18 | ||||
-rw-r--r-- | var/spack/repos/builtin/packages/tk/package.py | 18 |
2 files changed, 32 insertions, 4 deletions
diff --git a/var/spack/repos/builtin/packages/tcl/package.py b/var/spack/repos/builtin/packages/tcl/package.py index 9bd54ce247..951c9b8811 100644 --- a/var/spack/repos/builtin/packages/tcl/package.py +++ b/var/spack/repos/builtin/packages/tcl/package.py @@ -5,6 +5,8 @@ import os +from llnl.util.filesystem import find_first + from spack.package import * from spack.util.environment import is_system_path @@ -93,6 +95,18 @@ class Tcl(AutotoolsPackage, SourceforgePackage): os.path.realpath(self.prefix.bin.join("tclsh{0}".format(self.version.up_to(2)))) ) + def _find_script_dir(self): + # Put more-specific prefixes first + check_prefixes = [ + join_path(self.prefix, "share", "tcl{0}".format(self.version.up_to(2))), + self.prefix, + ] + for prefix in check_prefixes: + result = find_first(prefix, "init.tcl") + if result: + return os.path.dirname(result) + raise RuntimeError("Cannot locate init.tcl") + def setup_run_environment(self, env): """Set TCL_LIBRARY to the directory containing init.tcl. @@ -102,7 +116,7 @@ class Tcl(AutotoolsPackage, SourceforgePackage): """ # When using tkinter from within spack provided python+tkinter, # python will not be able to find Tcl unless TCL_LIBRARY is set. - env.set("TCL_LIBRARY", os.path.dirname(sorted(find(self.prefix, "init.tcl"))[0])) + env.set("TCL_LIBRARY", self._find_script_dir()) def setup_dependent_build_environment(self, env, dependent_spec): """Set TCL_LIBRARY to the directory containing init.tcl. @@ -114,7 +128,7 @@ class Tcl(AutotoolsPackage, SourceforgePackage): * https://wiki.tcl-lang.org/page/TCL_LIBRARY * https://wiki.tcl-lang.org/page/TCLLIBPATH """ - env.set("TCL_LIBRARY", os.path.dirname(sorted(find(self.prefix, "init.tcl"))[0])) + env.set("TCL_LIBRARY", self._find_script_dir()) # If we set TCLLIBPATH, we must also ensure that the corresponding # tcl is found in the build environment. This to prevent cases diff --git a/var/spack/repos/builtin/packages/tk/package.py b/var/spack/repos/builtin/packages/tk/package.py index 557a57cce8..316005caa5 100644 --- a/var/spack/repos/builtin/packages/tk/package.py +++ b/var/spack/repos/builtin/packages/tk/package.py @@ -5,6 +5,8 @@ import os +from llnl.util.filesystem import find_first + from spack.package import * @@ -118,6 +120,18 @@ class Tk(AutotoolsPackage, SourceforgePackage): ["libtk{0}".format(self.version.up_to(2))], root=self.prefix, recursive=True ) + def _find_script_dir(self): + # Put more-specific prefixes first + check_prefixes = [ + join_path(self.prefix, "share", "tk{0}".format(self.version.up_to(2))), + self.prefix, + ] + for prefix in check_prefixes: + result = find_first(prefix, "tk.tcl") + if result: + return os.path.dirname(result) + raise RuntimeError("Cannot locate tk.tcl") + def setup_run_environment(self, env): """Set TK_LIBRARY to the directory containing tk.tcl. @@ -127,7 +141,7 @@ class Tk(AutotoolsPackage, SourceforgePackage): """ # When using tkinter from within spack provided python+tkinter, # python will not be able to find Tk unless TK_LIBRARY is set. - env.set("TK_LIBRARY", os.path.dirname(sorted(find(self.prefix, "tk.tcl"))[0])) + env.set("TK_LIBRARY", self._find_script_dir()) def setup_dependent_build_environment(self, env, dependent_spec): """Set TK_LIBRARY to the directory containing tk.tcl. @@ -136,4 +150,4 @@ class Tk(AutotoolsPackage, SourceforgePackage): * https://www.tcl-lang.org/man/tcl/TkCmd/tkvars.htm """ - env.set("TK_LIBRARY", os.path.dirname(sorted(find(self.prefix, "tk.tcl"))[0])) + env.set("TK_LIBRARY", self._find_script_dir()) |