Skip to content

Commit 87109ac

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 0f8454f commit 87109ac

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
@@ -116,13 +116,31 @@ def is_yosys_step(script):
116116
return YOSYS_SCRIPT.search(f.read()) is not None
117117

118118

119+
def archive_root_from_run_me(work_home, vars_basename):
120+
"""Where run-me changes to, relative to its own directory, and the vars
121+
file's path from there: the archive's root, where the vars' paths
122+
start. run-me is at the root when WORK_HOME is absolute (its path is
123+
stripped from the members) or the flow directory; a relative WORK_HOME
124+
keeps its place under the root, and run-me climbs back from it."""
125+
here = os.path.realpath(".")
126+
if work_home.startswith("/") or os.path.realpath(work_home) == here:
127+
return None, f"./{os.path.basename(vars_basename)}.sh"
128+
root = os.path.relpath(here, os.path.realpath(work_home))
129+
vars_path = os.path.relpath(os.path.realpath(vars_basename), here)
130+
return root, f"./{vars_path}.sh"
131+
132+
119133
def run_me_text(env, issue_target, vars_basename, yosys):
120-
"""The run-me script: it changes to its own directory, sources the vars
121-
file from there and runs the step's script."""
134+
"""The run-me script: it changes to the archive's root, sources the
135+
vars file from there and runs the step's script."""
136+
root, vars_path = archive_root_from_run_me(
137+
env.get("WORK_HOME") or ".", vars_basename
138+
)
139+
run_me_dir = '"$(dirname "$0")"' if root is None else f'"$(dirname "$0")/{root}"'
122140
lines = [
123141
"#!/usr/bin/env bash",
124-
'cd "$(dirname "$0")"',
125-
f"source ./{os.path.basename(vars_basename)}.sh",
142+
f"cd {run_me_dir}",
143+
f"source {vars_path}",
126144
]
127145
script = "${SCRIPTS_DIR}/" + issue_target + ".tcl"
128146
if yosys:

0 commit comments

Comments
 (0)