Skip to content

Commit 7add8ce

Browse files
redo storage layout format in archives
1 parent dd5a3d9 commit 7add8ce

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

vyper/cli/compile_archive.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,18 @@ def compiler_data_from_zip(file_name, settings, no_bytecode_metadata):
4545
fcontents = archive.read("MANIFEST/compilation_targets").decode("utf-8")
4646
compilation_targets = fcontents.splitlines()
4747

48-
storage_layout_path = "MANIFEST/storage_layout.json"
48+
if len(compilation_targets) != 1:
49+
raise BadArchive("Multiple compilation targets not supported!")
50+
51+
mainpath = PurePath(compilation_targets[0])
52+
53+
storage_layout_path = f"storage_layouts/{mainpath}.json"
4954
storage_layout = None
5055
if storage_layout_path in archive.namelist():
5156
storage_layout = json.loads(archive.read(storage_layout_path).decode("utf-8"))
5257

53-
if len(compilation_targets) != 1:
54-
raise BadArchive("Multiple compilation targets not supported!")
55-
5658
input_bundle = ZipInputBundle(archive)
5759

58-
mainpath = PurePath(compilation_targets[0])
5960
file = input_bundle.load_file(mainpath)
6061
assert isinstance(file, FileInput) # mypy hint
6162

vyper/compiler/input_bundle.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ def _load_from_path(self, resolved_path: PurePath, original_path: PurePath) -> C
259259
# zipfile.BadZipFile: File is not a zip file
260260

261261
try:
262-
value = self.archive.read(resolved_path.as_posix()).decode("utf-8")
262+
p = PurePath("sources") / resolved_path
263+
value = self.archive.read(p.as_posix()).decode("utf-8")
263264
except KeyError:
264265
# zipfile literally raises KeyError if the file is not there
265266
raise _NotFound(resolved_path)

vyper/compiler/output_bundle.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# information.
2323

2424

25-
def _anonymize(p: str):
25+
def _anonymize(p: str) -> str:
2626
segments = []
2727
# replace ../../../a/b with 0/1/2/a/b
2828
for i, s in enumerate(PurePath(p).parts):
@@ -252,12 +252,14 @@ def __del__(self):
252252

253253
def write_sources(self, sources: dict[str, CompilerInput]):
254254
for path, c in sources.items():
255-
self.archive.writestr(_anonymize(path), c.contents)
255+
path = f"sources/{_anonymize(path)}"
256+
self.archive.writestr(path, c.contents)
256257

257258
def write_storage_layout_overrides(
258259
self, compilation_target_path: str, storage_layout_override: StorageLayout
259260
):
260-
self.archive.writestr("MANIFEST/storage_layout.json", json.dumps(storage_layout_override))
261+
path = f"storage_layouts/{compilation_target_path}.json"
262+
self.archive.writestr(path, json.dumps(storage_layout_override))
261263

262264
def write_search_paths(self, search_paths: list[str]):
263265
self.archive.writestr("MANIFEST/searchpaths", "\n".join(search_paths))

0 commit comments

Comments
 (0)