1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
#!/usr/bin/env python3
# ex: set filetype=python:
"""Translate an XDR specification into executable code that
can be compiled for the Linux kernel."""
__author__ = "Chuck Lever"
__copyright__ = "Copyright (c) 2024 Oracle and/or its affiliates."
__license__ = "GPL-2.0 only"
__version__ = "0.2"
import sys
import argparse
from subcmds import definitions
from subcmds import declarations
from subcmds import lint
from subcmds import source
sys.path.insert(1, "@pythondir@")
def main() -> int:
"""Parse command-line options"""
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="Convert an XDR specification to Linux kernel source code",
epilog="""\
Copyright (c) 2024 Oracle and/or its affiliates.
License GPLv2: <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
This is free software. You are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.""",
)
parser.add_argument(
"--version",
help="Display the version of this tool",
action="version",
version=__version__,
)
subcommands = parser.add_subparsers(title="Subcommands", required=True)
definitions_parser = subcommands.add_parser(
"definitions", help="Generate XDR definitions"
)
definitions_parser.add_argument(
"--annotate",
action="store_true",
default=False,
help="Add annotation comments",
)
definitions_parser.add_argument(
"--language",
action="store_true",
default="C",
help="Output language",
)
definitions_parser.add_argument(
"--peer",
choices=["server", "client",],
default="server",
help="Generate header code for client or server side",
type=str,
)
definitions_parser.add_argument("filename", help="File containing an XDR specification")
definitions_parser.set_defaults(func=definitions.subcmd)
declarations_parser = subcommands.add_parser(
"declarations", help="Generate function declarations"
)
declarations_parser.add_argument(
"--annotate",
action="store_true",
default=False,
help="Add annotation comments",
)
declarations_parser.add_argument(
"--language",
action="store_true",
default="C",
help="Output language",
)
declarations_parser.add_argument(
"--peer",
choices=["server", "client",],
default="server",
help="Generate code for client or server side",
type=str,
)
declarations_parser.add_argument("filename", help="File containing an XDR specification")
declarations_parser.set_defaults(func=declarations.subcmd)
linter_parser = subcommands.add_parser("lint", help="Check an XDR specification")
linter_parser.add_argument("filename", help="File containing an XDR specification")
linter_parser.set_defaults(func=lint.subcmd)
source_parser = subcommands.add_parser(
"source", help="Generate XDR encoder and decoder source code"
)
source_parser.add_argument(
"--annotate",
action="store_true",
default=False,
help="Add annotation comments",
)
source_parser.add_argument(
"--language",
action="store_true",
default="C",
help="Output language",
)
source_parser.add_argument(
"--peer",
choices=["server", "client",],
default="server",
help="Generate code for client or server side",
type=str,
)
source_parser.add_argument("filename", help="File containing an XDR specification")
source_parser.set_defaults(func=source.subcmd)
args = parser.parse_args()
return args.func(args)
try:
if __name__ == "__main__":
sys.exit(main())
except (SystemExit, KeyboardInterrupt, BrokenPipeError):
sys.exit(1)
|