Skip to content

Commit ba028ea

Browse files
oharboeclaude
andcommitted
makeIssue: run-me finds the archive's root from a relative WORK_HOME
The run-me script changes to its own directory and sources the vars file from there, and the vars' paths are relative to the archive's root. An absolute WORK_HOME is stripped from the archive's member names and WORK_HOME=. is the root, so run-me is at the root in both. A relative WORK_HOME such as work/gcd keeps its place under the root, and run-me then failed: couldn't read file "./scripts/detail_place.tcl" run-me now climbs from its directory back to the archive's root and sources the vars file by its path from there. An absolute WORK_HOME and WORK_HOME=. give the same run-me as before. TestRunMe runs the run-me of an archive made with a relative WORK_HOME from elsewhere; it failed before this change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 4c7395d commit ba028ea

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎flow/test/test_make_issue.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ def test_work_home_default(self):
201201
def test_work_home_absolute(self):
202202
self.assert_runs(os.path.join(self.stub.tmp, "work"))
203203

204+
def test_work_home_relative(self):
205+
self.assert_runs("work/stub")
206+
204207

205208
class TestOptions(StubFlowTestCase):
206209
def test_copy_issue_copies_the_archive(self):

‎flow/util/makeIssue.py‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,31 @@ def is_yosys_step(script):
9999
return YOSYS_SCRIPT.search(f.read()) is not None
100100

101101

102+
def archive_root_from_run_me(work_home, vars_basename):
103+
"""Where run-me changes to, relative to its own directory, and the vars
104+
file's path from there: the archive's root, where the vars' paths
105+
start. run-me is at the root when WORK_HOME is absolute (its path is
106+
stripped from the members) or the flow directory; a relative WORK_HOME
107+
keeps its place under the root, and run-me climbs back from it."""
108+
here = os.path.realpath(".")
109+
if work_home.startswith("/") or os.path.realpath(work_home) == here:
110+
return None, f"./{os.path.basename(vars_basename)}.sh"
111+
root = os.path.relpath(here, os.path.realpath(work_home))
112+
vars_path = os.path.relpath(os.path.realpath(vars_basename), here)
113+
return root, f"./{vars_path}.sh"
114+
115+
102116
def run_me_text(env, issue_target, vars_basename, yosys):
103-
"""The run-me script: it changes to its own directory, sources the vars
104-
file from there and runs the step's script."""
117+
"""The run-me script: it changes to the archive's root, sources the
118+
vars file from there and runs the step's script."""
119+
root, vars_path = archive_root_from_run_me(
120+
env.get("WORK_HOME") or ".", vars_basename
121+
)
122+
run_me_dir = '"$(dirname "$0")"' if root is None else f'"$(dirname "$0")/{root}"'
105123
lines = [
106124
"#!/usr/bin/env bash",
107-
'cd "$(dirname "$0")"',
108-
f"source ./{os.path.basename(vars_basename)}.sh",
125+
f"cd {run_me_dir}",
126+
f"source {vars_path}",
109127
]
110128
script = "${SCRIPTS_DIR}/" + issue_target + ".tcl"
111129
if yosys:

0 commit comments

Comments
 (0)