Skip to content
Snippets Groups Projects
Commit 64751f1b authored by Raphaël Gomès's avatar Raphaël Gomès
Browse files

bin-env-setup: let the suite compute its own unique ID

There is no way for poulpe itself to determine all the parameters that
actually *uniquely* define a bin-env, because it has no knowledge of how to
gather its dependencies, for example.

We have to assume that bin-envs in general wouldn't survive being
moved/renamed, because any hardcoding of the path that would happen in its
setup would get broken. Thus, we setup this contract with the suite setup
that the unique ID is indeed unique to all relevant parameters for this
particular bin-env.
parent 5dc622c6
No related branches found
No related tags found
1 merge request!44Suite agnostic tooling, improvements to simple-command, SWH suite
class BinEnvSetupFailure(RuntimeError):
pass
class BenchmarkFailure(RuntimeError):
pass
......
......@@ -5,6 +5,7 @@
import shutil
import subprocess
import sys
import tempfile
import time
from pathlib import Path
......@@ -420,5 +421,28 @@
def ensure_bin_env(den: den_mod.PoulpeDen, spec: BinEnvSpec):
bin_env_dir = den.bin_env_dir
target = bin_env_dir / spec.to_string_id()
# TODO parametrize which script somehow
suite_name = spec.suite_name
setup_script = (
den.suites_dir
/ suite_name
/ "bin-env-setup"
/ "default.poulpe-bin-env-setup"
)
bin_env_setup = bin_env_mod.BinEnvSetup(setup_script)
parameters = bin_env_setup.get_parameters()
cli_args = {}
env_args = {}
for name, value in spec.arguments.items():
if name not in parameters:
raise bin_env_mod.ParametersError(
f"unexpected parameter '{name}' for '{setup_script}'"
)
arg_mode = parameters[name]["arg-mode"]
assert arg_mode in ("CLI", "ENV"), arg_mode
if arg_mode == "CLI":
cli_args[name] = value
else:
env_args[name] = value
......@@ -424,4 +448,35 @@
env = os.environ.copy()
env.update(env_args)
cli_args_list = []
if cli_args:
for name, value in cli_args.items():
cli_args_list.append(f"--{name}")
cli_args_list.append(value)
if suite_name == "hg":
# Backwards compatibility for hg suite
# XXX make the mercurial script do this, I can't be bothered to
# XXX edit a giant shell script right now
target = bin_env_dir / spec.to_string_id()
else:
tmp_target = tempfile.mkdtemp()
# TODO make a "poulpe resolve-bin-env-spec"?
cmd = [setup_script.resolve(), "--get-unique-id"] + cli_args_list
try:
# Get the actual unique bin-env ID that only the suite can resolve
# (because of its dependencies, etc.)
res = subprocess.run(
cmd, cwd=tmp_target, env=env, check=True, capture_output=True
)
match = re.match("UNIQUE_ID: (.*)", res.stdout.decode())
unique_id = match.group(1)
finally:
shutil.rmtree(tmp_target, ignore_errors=True)
target = bin_env_dir / unique_id
# check the already available bin-env
all_existing = [p for p in bin_env_dir.iterdir()]
all_existing.sort(key=lambda x: x.stat().st_mtime)
......@@ -439,28 +494,5 @@
if target.exists() and not is_ready(target):
shutil.rmtree(target)
if not target.exists():
# TODO parametrize which script somehow
setup_script = (
den.suites_dir
/ spec.suite_name
/ "bin-env-setup"
/ "default.poulpe-bin-env-setup"
)
bin_env_setup = bin_env_mod.BinEnvSetup(setup_script)
parameters = bin_env_setup.get_parameters()
cli_args = {}
env_args = {}
for name, value in spec.arguments.items():
if name not in parameters:
raise bin_env_mod.ParametersError(
f"unexpected parameter '{name}' for '{setup_script}'"
)
arg_mode = parameters[name]["arg-mode"]
assert arg_mode in ("CLI", "ENV"), arg_mode
if arg_mode == "CLI":
cli_args[name] = value
else:
env_args[name] = value
os.makedirs(target, exist_ok=True)
......@@ -465,17 +497,8 @@
os.makedirs(target, exist_ok=True)
env = os.environ.copy()
env.update(env_args)
cli_args_list = []
if cli_args:
cli_args_list.append("--")
for name, value in cli_args.items():
cli_args_list.append(f"--{name}")
cli_args_list.append(value)
cmd = ["poulpe", "bin-env-util"]
cmd.extend(
[
"setup-one",
target,
setup_script,
......@@ -476,9 +499,10 @@
cmd = ["poulpe", "bin-env-util"]
cmd.extend(
[
"setup-one",
target,
setup_script,
"--" if cli_args_list else "",
]
+ cli_args_list
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment