Skip to content

Commit 533682d

Browse files
feat[tool]: add settings dict to combined_json output (#4541)
this commit adds the compiler settings used for this compilation run as a dict entry in the `combined_json` output. this is useful for explorers and tooling, which then have a reliable way of knowing which settings were used for the compilation, instead of having to rely on heuristics.
1 parent fdc312e commit 533682d

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

tests/unit/cli/vyper_compile/test_compile_files.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from vyper.compiler.input_bundle import FilesystemInputBundle
1515
from vyper.compiler.output_bundle import OutputBundle
1616
from vyper.compiler.phases import CompilerData
17+
from vyper.compiler.settings import Settings
1718
from vyper.utils import sha256sum
1819

1920
TAMPERED_INTEGRITY_SUM = sha256sum("tampered integrity sum")
@@ -37,13 +38,26 @@ def test_combined_json_keys(chdir_tmp_path, make_file):
3738
"method_identifiers",
3839
"userdoc",
3940
"devdoc",
41+
"settings_dict",
4042
}
4143
compile_data = compile_files(["bar.vy"], ["combined_json"])
4244

4345
assert set(compile_data.keys()) == {Path("bar.vy"), "version"}
4446
assert set(compile_data[Path("bar.vy")].keys()) == combined_keys
4547

4648

49+
def test_combined_json_settings_output(chdir_tmp_path, make_file, compiler_settings):
50+
make_file("bar.vy", "")
51+
52+
compile_data = compile_files(["bar.vy"], ["combined_json"])
53+
output_settings = compile_data[Path("bar.vy")]["settings_dict"]
54+
55+
# test output settings == expected settings
56+
assert output_settings == compiler_settings.as_dict()
57+
# test round-trip
58+
assert Settings.from_dict(output_settings) == compiler_settings
59+
60+
4761
def test_invalid_root_path():
4862
with pytest.raises(FileNotFoundError):
4963
compile_files([], [], paths=["path/that/does/not/exist"])

vyper/cli/vyper_compile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
integrity - Output the integrity hash of the source code
5151
archive - Output the build as an archive file
5252
solc_json - Output the build in solc json format
53+
settings - Output the settings for a given build in json format
5354
"""
5455

5556
combined_json_outputs = [
@@ -63,6 +64,7 @@
6364
"method_identifiers",
6465
"userdoc",
6566
"devdoc",
67+
"settings_dict",
6668
]
6769

6870

@@ -343,6 +345,7 @@ def compile_files(
343345
"ast": "ast_dict",
344346
"annotated_ast": "annotated_ast_dict",
345347
"ir_json": "ir_dict",
348+
"settings": "settings_dict",
346349
}
347350
final_formats = [translate_map.get(i, i) for i in output_formats]
348351

vyper/compiler/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"ir_runtime_dict": output.build_ir_runtime_dict_output,
3434
"method_identifiers": output.build_method_identifiers_output,
3535
"metadata": output.build_metadata_output,
36+
"settings_dict": output.build_settings_output,
3637
# requires assembly
3738
"abi": output.build_abi_output,
3839
"asm": output.build_asm_output,

vyper/compiler/output.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ def build_ir_runtime_dict_output(compiler_data: CompilerData) -> dict:
211211
return _ir_to_dict(compiler_data.ir_runtime)
212212

213213

214+
def build_settings_output(compiler_data: CompilerData) -> dict:
215+
return compiler_data.settings.as_dict()
216+
217+
214218
def build_metadata_output(compiler_data: CompilerData) -> dict:
215219
# need ir info to be computed
216220
_ = compiler_data.function_signatures

0 commit comments

Comments
 (0)