Skip to content

Commit 834fe3c

Browse files
author
whitequark
committed
build.plat: in Platform.add_file(), allow adding exact duplicates.
1 parent fe400b5 commit 834fe3c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

nmigen/build/plat.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,17 @@ def add_file(self, filename, content):
5050
if not isinstance(filename, str):
5151
raise TypeError("File name must be a string, not {!r}"
5252
.format(filename))
53-
if filename in self.extra_files:
54-
raise ValueError("File {!r} already exists"
55-
.format(filename))
5653
if hasattr(content, "read"):
5754
content = content.read()
5855
elif not isinstance(content, (str, bytes)):
5956
raise TypeError("File contents must be str, bytes, or a file-like object, not {!r}"
6057
.format(content))
61-
self.extra_files[filename] = content
58+
if filename in self.extra_files:
59+
if self.extra_files[filename] != content:
60+
raise ValueError("File {!r} already exists"
61+
.format(filename))
62+
else:
63+
self.extra_files[filename] = content
6264

6365
@property
6466
def _toolchain_env_var(self):

nmigen/test/test_build_plat.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ def test_add_file_bytes(self):
2525
self.platform.add_file("x.txt", b"foo")
2626
self.assertEqual(self.platform.extra_files["x.txt"], b"foo")
2727

28+
def test_add_file_exact_duplicate(self):
29+
self.platform.add_file("x.txt", b"foo")
30+
self.platform.add_file("x.txt", b"foo")
31+
2832
def test_add_file_io(self):
2933
with open(__file__) as f:
3034
self.platform.add_file("x.txt", f)

0 commit comments

Comments
 (0)