Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug where compilers output selection wasn't updating when contract types changes compiler #2086

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading