Skip to content

Commit 8712af4

Browse files
Fix up a few issues, allow fetching from local buck-out, fix hubris paths
1 parent 140a1c2 commit 8712af4

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

tools/fpga_releaser/archive_parser.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
# the nextpnr log at that same directory called nextpnr.log
66
# all the stuff in the _maps_ directory at that same level
77

8-
def get_relevant_files_from_buck_zip(zip):
8+
def get_relevant_files_from_buck_zip(fpga_name, zip):
99
zip_names = []
1010
for item in zip.infolist():
11+
# folders use _ instead of -
12+
if fpga_name not in item.filename and fpga_name.replace('-', '_') not in item.filename:
13+
# filter out stuff without the fpga name in it
14+
# (might be other projects if local build etc)
15+
continue
1116
if item.filename.endswith(".bz2"):
1217
zip_names.append(item.filename)
1318
if "/maps/" in item.filename and (item.filename.endswith(".json") or item.filename.endswith(".html")):

tools/fpga_releaser/cli.py

+24
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
parser.add_argument("--branch", default="main", help="Quartz branch to use for the artifact")
2121
parser.add_argument("--fpga", help="Name of FPGA project to release")
2222
parser.add_argument("--hubris", default=None, help="Path to hubris git checkout as target for copying files. Will skip if None")
23+
parser.add_argument("--local", default=False, action="store_true", help="Path to local build directory. Will skip if None")
2324
parser.add_argument("--skip-gh", default=False, action="store_true", help="Skip doing GH release. Note that doing this still generates release metadata that just will be wrong")
2425
parser.add_argument("--zip", default=None, help="Path to zip file to use instead of downloading from GitHub")
2526

@@ -49,6 +50,15 @@ def main():
4950
print(f"Processing {args.fpga} with builder {project_info.builder}")
5051

5152
# Get build archive
53+
if args.local:
54+
print("Using local build directory")
55+
# make a zip file from the local build directory
56+
zip_file = make_buck2_zip()
57+
args.zip = str(zip_file)
58+
59+
if args.zip:
60+
project_info.local = True
61+
5262
zip_file = process_gh_build(args, api, project_info.job_name)
5363
project_info.add_archive(zip_file)
5464

@@ -99,11 +109,25 @@ def get_latest_artifact_info(api, fpga_name: str, branch: str = "main") -> dict:
99109
artifacts = sorted(artifacts, key=lambda x: arrow.get(x["created_at"]), reverse=True)
100110
return artifacts[0]
101111

112+
102113
def download_artifact(api: GhApi, artifact_inf: dict):
103114
print(f"Downloading artifact {artifact_inf['name']} from GH: {artifact_inf['workflow_run']['head_branch']}")
104115
r = requests.get(artifact_inf["archive_download_url"], auth=("oxidecomputer", os.getenv("GITHUB_TOKEN", None)))
105116
return zipfile.ZipFile(io.BytesIO(r.content))
106117

118+
119+
def make_buck2_zip():
120+
"""
121+
Create a zip file from the buck2 build directory.
122+
"""
123+
import shutil
124+
# Create object of ZipFile
125+
zipfile_path = Path.cwd() / Path("buck_out.zip")
126+
folder = Path.cwd() / "buck-out" / "v2" / "gen" / "root"
127+
shutil.make_archive(zipfile_path.with_suffix(''), 'zip', folder)
128+
return zipfile_path
129+
130+
107131
if __name__ == '__main__':
108132
main()
109133

tools/fpga_releaser/config.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[cosmo-hp]
22
job_name = "cosmo-hp-image"
3-
hubris_path = "drv/ice40-loader/cosmo-hp"
3+
hubris_path = "drv/cosmo-seq-server/cosmo-hp"
44
builder = "buck2"
55
toolchain = "yosys"
66

tools/fpga_releaser/project.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def __init__(self, name, job_name, hubris_path, toolchain, builder):
2828
self.gh_release_name = ""
2929
self.gh_release_url = ""
3030
self.gh_build_sha = ""
31+
self.local = False
3132

3233
@classmethod
3334
def from_dict(cls, fpga_name, data: dict):
@@ -77,7 +78,7 @@ def add_archive(self, archive: zipfile.ZipFile):
7778
"""
7879
self.archive = archive
7980
if self.builder == "buck2":
80-
self.filenames = get_relevant_files_from_buck_zip(self.archive)
81+
self.filenames = get_relevant_files_from_buck_zip(self.name, self.archive)
8182

8283
def add_build_sha(self, sha):
8384
self.gh_build_sha = sha
@@ -141,9 +142,13 @@ def _get_fit_report(self):
141142
raise NotImplementedError
142143

143144
def make_readme_contents(self):
144-
txt = ("FPGA images and collateral are generated from:\n"
145-
f"[this sha](https://github.com/oxidecomputer/quartz/commit/{self.gh_build_sha})\n"
146-
f"[release]({self.gh_release_url})")
145+
if not self.local:
146+
txt = ("FPGA images and collateral are generated from:\n"
147+
f"[this sha](https://github.com/oxidecomputer/quartz/commit/{self.gh_build_sha})\n"
148+
f"[release]({self.gh_release_url})")
149+
else:
150+
# This is some local build
151+
txt = ("FPGA images and collateral are generated from some hw guy's local build\n")
147152
return txt
148153

149154

@@ -154,11 +159,9 @@ def get_config(fpga_name):
154159
with open(config_toml, "rb") as f:
155160
config = tomli.load(f)
156161

157-
print(config.keys())
158-
159162
known_fpga = config.get(fpga_name, None)
160163
if known_fpga is None:
161164
raise ValueError(f"FPGA {fpga_name} not found in config.")
162165

163166
return FPGAImage.from_dict(fpga_name, config)
164-
167+

0 commit comments

Comments
 (0)