Skip to content

Commit ba74fee

Browse files
committed
tpl-manager improvements
1 parent 505258a commit ba74fee

File tree

1 file changed

+42
-34
lines changed

1 file changed

+42
-34
lines changed

scripts/devtools/tpl-manager.py

+42-34
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ def parse_args(self):
5353
help="Directory to install Spack instance and a build directory.")
5454
parser.add_argument("--spack-url", type=str, default=default_spack_url,
5555
help="URL to download spack.")
56-
parser.add_argument("--debug", action="store_true",
57-
help="Set this flag if seeing odd Spack issues with tpl-manager.")
56+
parser.add_argument("--clean", action="store_true",
57+
help="Set this flag to ensure concretizations/installs are fresh. "+\
58+
"If issues arise, try using this flag.")
5859
parser.add_argument("--no-upstream", action="store_true",
5960
help="Ignore upstream by temporarily modifying environment.")
6061
parser.add_argument("--init-only", action="store_true",
@@ -119,14 +120,14 @@ def clone_spack(self):
119120
sexe(f"git -C {spack_dir} fetch --depth=2 origin {spack_commit}")
120121
sexe(f"git -C {spack_dir} checkout FETCH_HEAD")
121122
self.add_spack_paths(spack_dir)
122-
if self.args.debug:
123+
if (self.args.clean):
123124
sexe(f"git -C {spack_dir} clean -df")
124125

125126
def find_spack_package(self, package_names):
126127
"""
127128
Find if the package name/s is already in the environment.
128-
If any one of them are found, return the name of that package
129-
If not, run spack external find and raise an error if none are found
129+
If any one of them are found, return the name of that package.
130+
If not, run spack external find and raise an error if none are found.
130131
"""
131132
cur_packages = spack.config.get("packages")
132133
if (type(package_names) is not list):
@@ -185,7 +186,8 @@ def custom_spack_env(self, env_dir, env_name):
185186
dev_cmd("-p", dev_path, f"{package}@=develop") # spack develop <package>@=develop
186187

187188
comp_cmd("find") # spack compiler find
188-
ext_cmd("find")
189+
ext_cmd("find") # spack external find
190+
189191
# req_packages are packages we refuse to let spack build
190192
# If they aren't found, an error will be thrown telling the user
191193
# to install the package or ensure an install is in $PATH
@@ -245,21 +247,33 @@ def activate_spack_env(self):
245247
env_dir = os.path.join(config_env_dir, env_name)
246248
self.custom_spack_env(env_dir, env_name)
247249

248-
def concretize_spec(self):
250+
def concretize_spec(self, check_spec):
249251
"Concretize the spec"
250-
self.spack_spec = spack.spec.Spec(self.args.spec)
251-
if (self.args.add_spec):
252-
add_cmd = SpackCommand("add")
253-
add_cmd(self.args.spec)
252+
if (check_spec):
253+
self.spack_spec = spack.spec.Spec(self.args.spec)
254+
if (self.args.add_spec):
255+
add_cmd = SpackCommand("add")
256+
add_cmd(self.args.spec)
254257
print("Concretizing environment")
255258
conc_cmd = SpackCommand("concretize")
256-
conc_cmd("-U")
257-
matches = self.spack_env.matching_spec(self.spack_spec)
258-
if (not matches):
259-
raise Exception(f"{self.args.spec} not found in current "+\
260-
"environment. Rerun with --add-spec to add it.")
261-
self.spack_spec = matches
262-
print(f"Found matching root spec for {self.args.spec}")
259+
if (self.args.clean):
260+
conc_cmd("-U", "-f")
261+
else:
262+
conc_cmd("-U")
263+
if (check_spec):
264+
matches = self.spack_env.matching_spec(self.spack_spec)
265+
if (not matches):
266+
raise Exception(f"{self.args.spec} not found in current "+\
267+
"environment. Rerun with --add-spec to add it.")
268+
self.spack_spec = matches
269+
print(f"Found matching root spec for {self.args.spec}")
270+
271+
def do_install(self, install_args, spec):
272+
install_cmd = SpackCommand("install")
273+
if (self.args.dry_run):
274+
install_args.append("--fake")
275+
print(f"Running spack {' '.join(install_args)} {spec}")
276+
install_cmd(*install_args, spec)
263277

264278
def install_and_config(self):
265279
"Install TPLs and create host config file for given spec"
@@ -285,15 +299,12 @@ def install_and_config(self):
285299
spec_cmd = SpackCommand("spec")
286300
print(f"Running spack spec -IL {spec}")
287301
spec_cmd("-IL", spec)
288-
if (not self.args.dry_run):
289-
install_cmd = SpackCommand("install")
290-
install_args = ["-u", "initconfig"]
291-
if (self.args.dev_pkg):
292-
# Spec is provided so assumes we are building from a buildcache
293-
install_args.extend(["--use-buildcache", "package:never,dependencies:only", "--no-check-signature"])
294-
print(f"Running spack {' '.join(install_args)} {spec}")
295-
install_cmd(*install_args, spec)
296-
print(f"Created {host_config_file}")
302+
install_args = ["-u", "initconfig"]
303+
if (self.args.dev_pkg):
304+
# Spec is provided so assumes we are building from a buildcache
305+
install_args.extend(["--use-buildcache", "package:never,dependencies:only", "--no-check-signature"])
306+
self.do_install(install_args, spec)
307+
print(f"Created {host_config_file}")
297308

298309
if (self.args.ci_run):
299310
shutil.copyfile(host_config_file, "gitlab.cmake")
@@ -312,17 +323,14 @@ def __init__(self):
312323
self.activate_spack_env()
313324
if (self.args.spec):
314325
# If --spec is given, install TPLs and create host config file
315-
self.concretize_spec()
326+
self.concretize_spec(check_spec=True)
316327
self.install_and_config()
317328
else:
318329
# Concretize the current environment
319-
print("Concretizing environment")
320-
conc_cmd = SpackCommand("concretize")
321-
conc_cmd("-U")
330+
self.concretize_spec(check_spec=False)
322331
# No spec is given, install TPLs for all env specs
323-
install_cmd = SpackCommand("install")
324-
print(f"Running spack install --only dependencies {package_name}")
325-
install_cmd("--only", "dependencies", package_name)
332+
install_args = ["--only", "dependencies"]
333+
self.do_install(install_args, package_name)
326334

327335
# Undo any file changes we made to spack.yaml
328336
orig_file = os.path.join(self.spack_env.path, "origspack.yaml")

0 commit comments

Comments
 (0)