build.plat: restrict design names to alphanumeric to avoid quoting issues.
This commit is contained in:
parent
3d62dac1cb
commit
ee1ad2daf1
|
@ -257,6 +257,17 @@ class TemplatedPlatform(Platform):
|
||||||
}
|
}
|
||||||
|
|
||||||
def toolchain_prepare(self, fragment, name, **kwargs):
|
def toolchain_prepare(self, fragment, name, **kwargs):
|
||||||
|
# Restrict the name of the design to a strict alphanumeric character set. Platforms will
|
||||||
|
# interpolate the name of the design in many different contexts: filesystem paths, Python
|
||||||
|
# scripts, Tcl scripts, ad-hoc constraint files, and so on. It is not practical to add
|
||||||
|
# escaping code that handles every one of their edge cases, so make sure we never hit them
|
||||||
|
# in the first place.
|
||||||
|
invalid_char = re.match(r"[^A-Za-z0-9_]", name)
|
||||||
|
if invalid_char:
|
||||||
|
raise ValueError("Design name {!r} contains invalid character {!r}; only alphanumeric "
|
||||||
|
"characters are valid in design names"
|
||||||
|
.format(name, invalid_char.group(0)))
|
||||||
|
|
||||||
# This notice serves a dual purpose: to explain that the file is autogenerated,
|
# This notice serves a dual purpose: to explain that the file is autogenerated,
|
||||||
# and to incorporate the nMigen version into generated code.
|
# and to incorporate the nMigen version into generated code.
|
||||||
autogenerated = "Automatically generated by nMigen {}. Do not edit.".format(__version__)
|
autogenerated = "Automatically generated by nMigen {}. Do not edit.".format(__version__)
|
||||||
|
|
Loading…
Reference in a new issue