Move the version check just before the usage

Signed-off-by: Cindy Liu <hcindyl@google.com>
This commit is contained in:
Cindy Liu
2023-12-14 18:08:47 -08:00
committed by Gerwin Klein
parent 04dc9675f3
commit 807a42e91e
2 changed files with 17 additions and 25 deletions

View File

@@ -156,6 +156,14 @@ def parse_xml(xml_file):
def generate(args, invocations):
# We require jinja2 to be at least version 2.10,
# In the past we used the 'namespace' feature from that version.
# other versions of jinja, particularly `minijinja`, don't support
# namespaces. However in case `namespace` is needed in the future require a
# version which supports it.
jinja2_version = version("jinja2")
if jinja2_version < "2.10":
sys.exit("Jinja2 should be >= 2.10")
header_title = "API"
if args.libsel4:
@@ -177,15 +185,6 @@ def generate(args, invocations):
if __name__ == "__main__":
# We require jinja2 to be at least version 2.10,
# In the past we used the 'namespace' feature from that version.
# other versions of jinja, particularly `minijinja`, don't support
# namespaces. However in case `namespace` is needed in the future require a
# version which supports it.
jinja2_version = version("jinja2")
if jinja2_version < "2.10":
sys.exit("Jinja2 should be >= 2.10")
args = parse_args()
invocations = parse_xml(args.xml)

View File

@@ -18,13 +18,6 @@ import sys
import xml.dom.minidom
from condition import condition_to_cpp
# We require jinja2 to be at least version 2.10,
# In the past we used the 'namespace' feature from that version.
# other versions of jinja, particularly `minijinja`, don't support namespaces.
# However in case `namespace` is needed in the future require a
# version which supports it.
pkg_resources.require("jinja2>=2.10")
COMMON_HEADER = """
/* This header was generated by kernel/tools/syscall_header_gen.py.
@@ -210,6 +203,15 @@ def map_syscalls_neg(syscalls):
def generate_kernel_file(kernel_header, api, debug):
# We require jinja2 to be at least version 2.10,
# In the past we used the 'namespace' feature from that version.
# other versions of jinja, particularly `minijinja`, don't support
# namespaces. However in case `namespace` is needed in the future require a
# version which supports it.
jinja2_version = version("jinja2")
if jinja2_version < "2.10":
sys.exit("Jinja2 should be >= 2.10")
template = Environment(loader=BaseLoader, trim_blocks=False,
lstrip_blocks=False).from_string(KERNEL_HEADER_TEMPLATE)
data = template.render({'assembler': map_syscalls_neg(api),
@@ -227,15 +229,6 @@ def generate_libsel4_file(libsel4_header, syscalls):
if __name__ == "__main__":
# We require jinja2 to be at least version 2.10,
# In the past we used the 'namespace' feature from that version.
# other versions of jinja, particularly `minijinja`, don't support
# namespaces. However in case `namespace` is needed in the future require a
# version which supports it.
jinja2_version = version("jinja2")
if jinja2_version < "2.10":
sys.exit("Jinja2 should be >= 2.10")
args = parse_args()
(api, debug) = parse_xml(args.xml, args.mcs)