|
9 | 9 | from typing import Any, List, Dict |
10 | 10 |
|
11 | 11 | import spack.environment |
| 12 | +import spack.error |
12 | 13 | import spack.cmd |
| 14 | +import spack.config |
| 15 | +import spack.paths |
13 | 16 | import spack.spec |
14 | 17 | import spack.repo |
| 18 | +import spack.main |
15 | 19 |
|
16 | 20 |
|
17 | 21 | def main(): |
18 | 22 | args = parse_args(sys.argv[1:]) |
19 | 23 | packages: List[str] = args.packages.split(",") |
| 24 | + config_scopes: List[str] = args.config_scopes.split(",") if args.config_scopes else [] |
20 | 25 | output_path = Path(args.output) |
21 | 26 |
|
| 27 | + # Custom scopes added via spack --config-scope for install need to be added back here |
| 28 | + # so we can find those packages! |
| 29 | + add_custom_spack_config_scopes(config_scopes) |
| 30 | + |
22 | 31 | # Activate the spack environment so we can get relevant specs for this deployment |
23 | 32 | spack_env = activate_spack_environment(args.environment) |
24 | 33 |
|
@@ -50,6 +59,26 @@ def main(): |
50 | 59 | with open(output_path / "build-db-pkgs.json", 'w') as f: |
51 | 60 | json.dump(packages_metadata, f) |
52 | 61 |
|
| 62 | +def add_custom_spack_config_scopes(config_scopes: List[str]) -> None: |
| 63 | + """ |
| 64 | + Adds paths to custom spack config scopes to the command_line scope so we can find binaries for |
| 65 | + certain environments that use custom installation directories. |
| 66 | +
|
| 67 | + :param config_scopes: Names of custom scopes from spack-configs custom/cd directory. |
| 68 | + :type config_scopes: List[str] |
| 69 | + """ |
| 70 | + spack_config_custom_scopes_path: Path = Path(spack.paths.spack_root).parent / "spack-config" / "custom" / "cd" |
| 71 | + |
| 72 | + config_scope_paths: List[str] = [str(spack_config_custom_scopes_path / s) for s in config_scopes] |
| 73 | + |
| 74 | + print(f"Attempting to load custom scopes: {config_scope_paths}") |
| 75 | + |
| 76 | + try: |
| 77 | + spack.main.add_command_line_scopes(spack.config.CONFIG, config_scope_paths) |
| 78 | + except spack.error.ConfigError: |
| 79 | + print(f"Failed to find valid config scope in paths {config_scope_paths}.") |
| 80 | + raise |
| 81 | + |
53 | 82 | def activate_spack_environment(spack_env_path: str) -> spack.environment.Environment: |
54 | 83 | spack_env = spack.environment.Environment(spack_env_path) |
55 | 84 |
|
@@ -144,6 +173,13 @@ def parse_args(args: List[str]) -> argparse.Namespace: |
144 | 173 | help="Comma-separated list of packages to extract build metadata for", |
145 | 174 | ) |
146 | 175 |
|
| 176 | + parser.add_argument( |
| 177 | + "--config-scopes", |
| 178 | + type=str, |
| 179 | + required=False, |
| 180 | + help="Comma-separated list of custom spack config scopes defined in spack-configs custom/cd directory" |
| 181 | + ) |
| 182 | + |
147 | 183 | ## Args dealing with outputs |
148 | 184 | parser.add_argument( |
149 | 185 | "--output", |
|
0 commit comments