Move proto generation template into separate file

This commit is contained in:
Justin C. Miller
2020-05-25 02:28:52 -07:00
parent 9064567e4a
commit 51dce15465
2 changed files with 24 additions and 22 deletions

23
generate.py Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
import os
from os.path import join, dirname
from jinja2 import Environment, FileSystemLoader, Template
template_path = join(dirname(__file__), "templates")
env = Environment(loader=FileSystemLoader(template_path))
protos_dir = join("include", "uefi", "protos")
os.makedirs(protos_dir, exist_ok=True)
proto_template = env.get_template("proto.j2")
import yaml
protos = yaml.load(open("protos.yaml"))
for proto in protos:
with open(os.path.join(protos_dir, proto["name"] + ".h"), 'w') as header:
header.write(template.render(proto_template))

23
generate_protos.py → templates/proto.j2 Executable file → Normal file
View File

@@ -1,14 +1,4 @@
#!/usr/bin/env python3 #pragma once
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import os.path
from jinja2 import Template
template = Template('''#pragma once
#ifndef _uefi_protos_{{ name }}_h_ #ifndef _uefi_protos_{{ name }}_h_
#define _uefi_protos_{{ name }}_h_ #define _uefi_protos_{{ name }}_h_
@@ -62,14 +52,3 @@ public:
} // namespace uefi } // namespace uefi
#endif // _uefi_protos_{{ name }}_h_ #endif // _uefi_protos_{{ name }}_h_
''')
protos_dir = os.path.join("include", "uefi", "protos")
os.makedirs(protos_dir, exist_ok=True)
import yaml
protos = yaml.load(open("protos.yaml"))
for proto in protos:
with open(os.path.join(protos_dir, proto["name"] + ".h"), 'w') as header:
header.write(template.render(proto))