Skip to content

Commit b10a5b1

Browse files
committed
use target-architecture from package YAML definition
Signed-off-by: Azimjon Ulmasov <azimjon.ulmasov@chainguard.dev>
1 parent cdaf3eb commit b10a5b1

File tree

1 file changed

+19
-40
lines changed

1 file changed

+19
-40
lines changed

pre_commit_hooks/shellcheck_run_steps.py

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -109,47 +109,26 @@ def main(argv: Sequence[str] | None = None) -> int:
109109
"w",
110110
delete_on_close=False,
111111
) as compiled_out:
112-
# Try multiple architectures
113-
architectures = list(
114-
dict.fromkeys([os.uname().machine, "x86_64", "aarch64"]),
112+
with open(filename) as precompiled_in:
113+
melange_cfg = yaml.load(precompiled_in)
114+
architectures = melange_cfg["package"].get("target-architecture", [])
115+
if not architectures:
116+
architectures = ["x86_64"]
117+
arch = architectures[0]
118+
subprocess.check_call(
119+
[
120+
"docker",
121+
"run",
122+
f"--volume={os.getcwd()}:/work",
123+
"--rm",
124+
MelangeImage,
125+
"compile",
126+
f"--arch={arch}",
127+
"--pipeline-dir=./pipelines",
128+
filename,
129+
],
130+
stdout=compiled_out,
115131
)
116-
compilation_succeeded = False
117-
118-
for i, arch in enumerate(architectures):
119-
try:
120-
subprocess.run(
121-
[
122-
"docker",
123-
"run",
124-
f"--volume={os.getcwd()}:/work",
125-
"--rm",
126-
MelangeImage,
127-
"compile",
128-
f"--arch={arch}",
129-
"--pipeline-dir=./pipelines",
130-
filename,
131-
],
132-
stdout=compiled_out,
133-
stderr=subprocess.PIPE,
134-
check=True,
135-
text=True,
136-
)
137-
compilation_succeeded = True
138-
break # Success, exit the architecture loop
139-
except subprocess.CalledProcessError:
140-
if i < len(architectures) - 1:
141-
# Reset the file for the next attempt
142-
compiled_out.seek(0)
143-
compiled_out.truncate()
144-
continue
145-
else:
146-
# Last architecture failed, propagate the error
147-
raise
148-
149-
if not compilation_succeeded:
150-
fail_cnt += 1
151-
continue
152-
153132
compiled_out.close()
154133
try:
155134
with open(compiled_out.name) as compiled_in:

0 commit comments

Comments
 (0)