File Index
Files and directories
Sign in
FILE

xdrgen

File preview with syntax highlighting.

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