Tk/Tcl packages: speed up file search (#35902)

This commit is contained in:
Peter Scheibel 2023-05-17 00:27:05 -07:00 committed by GitHub
parent d96406a161
commit 7a3da0f606
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 4 deletions

View file

@ -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 @@ def command(self):
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 @@ def setup_run_environment(self, env):
"""
# 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 @@ def setup_dependent_build_environment(self, env, dependent_spec):
* 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

View file

@ -5,6 +5,8 @@
import os
from llnl.util.filesystem import find_first
from spack.package import *
@ -118,6 +120,18 @@ def libs(self):
["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 @@ def setup_run_environment(self, env):
"""
# 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 @@ def setup_dependent_build_environment(self, env, dependent_spec):
* 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())