fix(builder): keep project script config in makefile
This commit is contained in:
@@ -492,13 +492,44 @@ def env_file_values(project: Path) -> dict[str, str]:
|
||||
return values
|
||||
|
||||
|
||||
def key_present(key: str, env_keys: set[str]) -> bool:
|
||||
return bool(os.environ.get(key)) or key in env_keys
|
||||
MAKE_ASSIGNMENT = re.compile(
|
||||
r"^([A-Za-z_][A-Za-z0-9_]*)\s*(?:\?=|:=|=)\s*(.*?)\s*$"
|
||||
)
|
||||
|
||||
|
||||
def configured_value(key: str, env_values: dict[str, str]) -> str:
|
||||
def makefile_values(project: Path) -> dict[str, str]:
|
||||
"""Return nonempty top-level make variable values for contract checks."""
|
||||
path = project / BUILDER_MAKEFILE
|
||||
values: dict[str, str] = {}
|
||||
if not path.is_file():
|
||||
return values
|
||||
try:
|
||||
text = path.read_text(encoding="utf-8")
|
||||
except OSError:
|
||||
return values
|
||||
for raw in text.splitlines():
|
||||
match = MAKE_ASSIGNMENT.match(raw)
|
||||
if not match:
|
||||
continue
|
||||
value = re.split(r"\s+#", match.group(2), maxsplit=1)[0].strip()
|
||||
if value:
|
||||
values[match.group(1)] = value
|
||||
return values
|
||||
|
||||
|
||||
def key_present(
|
||||
key: str, env_keys: set[str], make_values: dict[str, str] | None = None
|
||||
) -> bool:
|
||||
return bool(os.environ.get(key)) or key in env_keys or bool((make_values or {}).get(key))
|
||||
|
||||
|
||||
def configured_value(
|
||||
key: str,
|
||||
env_values: dict[str, str],
|
||||
make_values: dict[str, str] | None = None,
|
||||
) -> str:
|
||||
"""Read a configured value without ever printing it."""
|
||||
return os.environ.get(key, "") or env_values.get(key, "")
|
||||
return os.environ.get(key, "") or env_values.get(key, "") or (make_values or {}).get(key, "")
|
||||
|
||||
|
||||
def resolve_copy_script(project: Path, script: str) -> tuple[Path | None, str | None]:
|
||||
@@ -515,8 +546,13 @@ def resolve_copy_script(project: Path, script: str) -> tuple[Path | None, str |
|
||||
return resolved, None
|
||||
|
||||
|
||||
def check_copy_script(report: Report, project: Path, env_values: dict[str, str]) -> None:
|
||||
script = configured_value("COPY_SCRIPT", env_values)
|
||||
def check_copy_script(
|
||||
report: Report,
|
||||
project: Path,
|
||||
env_values: dict[str, str],
|
||||
make_values: dict[str, str],
|
||||
) -> None:
|
||||
script = configured_value("COPY_SCRIPT", env_values, make_values)
|
||||
if not script:
|
||||
return
|
||||
path, resolve_error = resolve_copy_script(project, script)
|
||||
@@ -579,6 +615,7 @@ def check_ready_env_keys(
|
||||
) -> None:
|
||||
env_keys = env_file_keys(project)
|
||||
env_values = env_file_values(project)
|
||||
make_values = makefile_values(project)
|
||||
lines = []
|
||||
missing: list[str] = []
|
||||
if not deb_project and not docker_project and not copy_project:
|
||||
@@ -594,7 +631,7 @@ def check_ready_env_keys(
|
||||
lines.append("DEB_*: skipped (no deb track)")
|
||||
if docker_project:
|
||||
for key in DOCKER_ENV_KEYS:
|
||||
found = key_present(key, env_keys)
|
||||
found = key_present(key, env_keys, make_values)
|
||||
lines.append(f"{key}: {'present' if found else 'MISSING'}")
|
||||
if not found:
|
||||
missing.append(key)
|
||||
@@ -602,11 +639,13 @@ def check_ready_env_keys(
|
||||
lines.append("DOCKER_*: skipped (no docker track)")
|
||||
if copy_project:
|
||||
for key in COPY_ENV_KEYS:
|
||||
found = key_present(key, env_keys)
|
||||
found = key_present(key, env_keys, make_values)
|
||||
lines.append(f"{key}: {'present' if found else 'MISSING'}")
|
||||
if not any(key_present(key, env_keys) for key in COPY_ENV_KEYS):
|
||||
if "COPY_SCRIPT" in make_values and "COPY_SCRIPT" not in env_keys and not os.environ.get("COPY_SCRIPT"):
|
||||
lines[-1] += " (makefile.builder)"
|
||||
if not any(key_present(key, env_keys, make_values) for key in COPY_ENV_KEYS):
|
||||
missing.append("COPY_DEST or COPY_SCRIPT")
|
||||
check_copy_script(report, project, env_values)
|
||||
check_copy_script(report, project, env_values, make_values)
|
||||
else:
|
||||
lines.append("COPY_*: skipped (no copy track)")
|
||||
if missing:
|
||||
|
||||
Reference in New Issue
Block a user