Debian Codegraph @

src/nouveau/compiler/latencies/lib_rs_gen.py

raw
1 #! /usr/bin/env python3
2 #
3 # Copyright © 2024 Collabora Ltd. and Red Hat Inc.
4 # SPDX-License-Identifier: MIT
5
6 # This script takes a list of Rust files, each of the form nvh_path_to_mod.rs
7 # and constructs a lib.rs which puts each of them in ::path::to::mod.
8
9 import argparse
10 import sys
11
12 from mako.template import Template
13
14 TEMPLATE_RS = Template("""\
15 // Copyright © 2024 Collabora Ltd. and Red Hat Inc.
16 // SPDX-License-Identifier: MIT
17
18 // This file is generated by lib_rs_gen.py. DO NOT EDIT!
19
20 % for mod in mods:
21 pub mod ${mod};
22 % endfor
23 """)
24
25 def main():
26 parser = argparse.ArgumentParser()
27 parser.add_argument('-p', '--import-path', required=True)
28 parser.add_argument('--out-rs', required=True, help='Output Rust file.')
29 parser.add_argument('mods', metavar='MOD', nargs='*',
30 action='append', help='Submodule')
31 args = parser.parse_args()
32
33 sys.path.insert(0, args.import_path)
34 import util
35
36 util.write_template_rs(args.out_rs, TEMPLATE_RS, dict(mods=args.mods[0]))
37
38 if __name__ == '__main__':
39 main()