Skip to content

Commit

Permalink
fix: bug where compilers output sel wasnt updating (#2086)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored May 10, 2024
1 parent 69e04c2 commit 26bec8b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/ape/api/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ def add_compiler_data(self, compiler_data: Sequence[Compiler]) -> List[Compiler]
c for c in (existing_compiler.contractTypes or []) if c not in new_types
]

# Clear output selection for new types, since they are present in the new compiler.
if existing_compiler.settings and "outputSelection" in existing_compiler.settings:
existing_compiler.settings["outputSelection"] = {
k: v
for k, v in existing_compiler.settings["outputSelection"].items()
if k not in new_types
}

# Remove compilers without contract types.
if existing_compiler.contractTypes:
remaining_existing_compilers.append(existing_compiler)
Expand Down
26 changes: 23 additions & 3 deletions tests/functional/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,26 @@ def test_add_compiler_data(project_with_dependency_config):
start_compilers = project.local_project.manifest.compilers or []

# NOTE: Pre-defining things to lessen chance of race condition.
compiler = Compiler(name="comp", version="1.0.0", contractTypes=["foo"])
compiler_2 = Compiler(name="test", version="2.0.0", contractTypes=["bar", "stay"])
compiler = Compiler(
name="comp",
version="1.0.0",
contractTypes=["foo"],
settings={"outputSelection": {"foo": "*"}},
)
compiler_2 = Compiler(
name="test",
version="2.0.0",
contractTypes=["bar", "stay"],
settings={"outputSelection": {"bar": "*", "stay": "*"}},
)

# NOTE: Has same contract as compiler 2 and thus replaces the contract.
compiler_3 = Compiler(name="test", version="3.0.0", contractTypes=["bar"])
compiler_3 = Compiler(
name="test",
version="3.0.0",
contractTypes=["bar"],
settings={"outputSelection": {"bar": "*"}},
)

proj = project.local_project
argument = [compiler]
Expand All @@ -670,9 +685,14 @@ def test_add_compiler_data(project_with_dependency_config):
proj.add_compiler_data(second_arg)
assert proj.manifest.compilers == final_exp

# `bar` has moved to a new compiler.
proj.add_compiler_data(third_arg)
comp = [c for c in proj.manifest.compilers if c.name == "test" and c.version == "2.0.0"][0]
assert "bar" not in comp.contractTypes
assert "bar" not in comp.settings["outputSelection"]
new_comp = [c for c in proj.manifest.compilers if c.name == "test" and c.version == "3.0.0"][0]
assert "bar" in new_comp.contractTypes
assert "bar" in new_comp.settings["outputSelection"]

# Show that compilers without contract types go away.
(compiler_3.contractTypes or []).append("stay")
Expand Down

0 comments on commit 26bec8b

Please sign in to comment.