rustorb-idl 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rustorb_idl/__init__.py +7 -0
- rustorb_idl/__main__.py +3 -0
- rustorb_idl/cli.py +142 -0
- rustorb_idl/cxx_backend.py +2083 -0
- rustorb_idl/frontend.py +480 -0
- rustorb_idl/idl/CosNaming.idl +93 -0
- rustorb_idl/java_backend.py +1954 -0
- rustorb_idl/names.py +26 -0
- rustorb_idl/pyi.py +340 -0
- rustorb_idl/python_backend.py +952 -0
- rustorb_idl/rust_backend.py +2104 -0
- rustorb_idl-0.1.0.dist-info/METADATA +41 -0
- rustorb_idl-0.1.0.dist-info/RECORD +16 -0
- rustorb_idl-0.1.0.dist-info/WHEEL +5 -0
- rustorb_idl-0.1.0.dist-info/entry_points.txt +2 -0
- rustorb_idl-0.1.0.dist-info/top_level.txt +1 -0
rustorb_idl/__init__.py
ADDED
rustorb_idl/__main__.py
ADDED
rustorb_idl/cli.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"""Command line: ``rustorb-idl -bBACKEND [options] FILE.idl...``.
|
|
2
|
+
|
|
3
|
+
The options follow omniidl where they mean the same thing:
|
|
4
|
+
|
|
5
|
+
-bpython Python stubs and skeletons (standard Python mapping)
|
|
6
|
+
-bc++11 C++ stubs and skeletons (IDL to C++11 mapping); also
|
|
7
|
+
-bcxx11
|
|
8
|
+
-bjava Java stubs and skeletons (IDL to Java mapping)
|
|
9
|
+
-brust Rust stubs and skeletons (docs/rust-mapping.md)
|
|
10
|
+
-I DIR look for #include files in DIR
|
|
11
|
+
-D NAME[=VALUE] define a preprocessor macro
|
|
12
|
+
-C DIR write the output under DIR (default: the current directory)
|
|
13
|
+
-Wbglobal=NAME the module for definitions outside modules (_GlobalIDL)
|
|
14
|
+
-Wbpackage=PKG put the Python modules in the package PKG (python), or
|
|
15
|
+
every Java package under PKG (java)
|
|
16
|
+
-Wbno_stubs do not write the .pyi type stubs (python)
|
|
17
|
+
-Wbh=SUFFIX the header suffix (c++11, default .hh)
|
|
18
|
+
-Wbs=SUFFIX the source suffix (c++11, default .cc)
|
|
19
|
+
-Wbextern=MODULE=PATH
|
|
20
|
+
refer to the definitions of the IDL module MODULE under
|
|
21
|
+
the Rust path PATH instead of writing them (rust)
|
|
22
|
+
-Wbcore=PATH the path of rustorb-core (rust, default ::rustorb_core)
|
|
23
|
+
-Wbno_rustfmt do not pass the output through rustfmt (rust)
|
|
24
|
+
|
|
25
|
+
The standard IDL files that come with rustorb-idl (CosNaming.idl) are in the
|
|
26
|
+
directory `rustorb-idl --idl-dir` prints, which is also searched for
|
|
27
|
+
#include files after the -I directories.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
import argparse
|
|
31
|
+
import os
|
|
32
|
+
import sys
|
|
33
|
+
|
|
34
|
+
from . import __version__
|
|
35
|
+
from . import cxx_backend
|
|
36
|
+
from . import frontend
|
|
37
|
+
from . import java_backend
|
|
38
|
+
from . import python_backend
|
|
39
|
+
from . import rust_backend
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
IDL_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "idl")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def parse_args(argv):
|
|
46
|
+
ap = argparse.ArgumentParser(
|
|
47
|
+
prog="rustorb-idl",
|
|
48
|
+
description="Generate code for rustorb from IDL files.",
|
|
49
|
+
epilog=__doc__.split("\n\n", 1)[1],
|
|
50
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
51
|
+
add_help=True,
|
|
52
|
+
)
|
|
53
|
+
ap.add_argument(
|
|
54
|
+
"-b", dest="backend", required=True, metavar="BACKEND", help="the backend: python, c++11, java or rust"
|
|
55
|
+
)
|
|
56
|
+
ap.add_argument("-I", dest="include", action="append", default=[], metavar="DIR")
|
|
57
|
+
ap.add_argument("-D", dest="define", action="append", default=[], metavar="NAME[=VALUE]")
|
|
58
|
+
ap.add_argument("-C", dest="outdir", default=".", metavar="DIR")
|
|
59
|
+
ap.add_argument("-W", dest="backend_options", action="append", default=[], metavar="bOPTION")
|
|
60
|
+
ap.add_argument("--encoding", default=None, help="character encoding of the IDL files")
|
|
61
|
+
ap.add_argument("--version", action="version", version="rustorb-idl " + __version__)
|
|
62
|
+
ap.add_argument(
|
|
63
|
+
"--idl-dir",
|
|
64
|
+
action="store_true",
|
|
65
|
+
help="print the directory of the standard IDL files (CosNaming.idl) and exit",
|
|
66
|
+
)
|
|
67
|
+
ap.add_argument("files", nargs="+", metavar="FILE.idl")
|
|
68
|
+
return ap.parse_args(argv)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def main(argv=None):
|
|
72
|
+
argv = sys.argv[1:] if argv is None else argv
|
|
73
|
+
if "--idl-dir" in argv:
|
|
74
|
+
print(IDL_DIR)
|
|
75
|
+
return 0
|
|
76
|
+
args = parse_args(argv)
|
|
77
|
+
if args.backend == "python":
|
|
78
|
+
backend, options = python_backend, python_backend.Options()
|
|
79
|
+
elif args.backend in ("c++11", "cxx11"):
|
|
80
|
+
backend, options = cxx_backend, cxx_backend.Options()
|
|
81
|
+
elif args.backend == "java":
|
|
82
|
+
backend, options = java_backend, java_backend.Options()
|
|
83
|
+
elif args.backend == "rust":
|
|
84
|
+
backend, options = rust_backend, rust_backend.Options()
|
|
85
|
+
else:
|
|
86
|
+
sys.stderr.write(
|
|
87
|
+
"rustorb-idl: unknown backend %r (python, c++11, java and rust are available)\n" % args.backend
|
|
88
|
+
)
|
|
89
|
+
return 2
|
|
90
|
+
for opt in args.backend_options:
|
|
91
|
+
if backend is python_backend and opt.startswith("bglobal="):
|
|
92
|
+
options.global_module = opt[len("bglobal=") :]
|
|
93
|
+
elif backend is python_backend and opt.startswith("bpackage="):
|
|
94
|
+
options.package = opt[len("bpackage=") :].strip(".")
|
|
95
|
+
elif backend is java_backend and opt.startswith("bpackage="):
|
|
96
|
+
options.package = opt[len("bpackage=") :].strip(".")
|
|
97
|
+
elif backend is python_backend and opt == "bno_stubs":
|
|
98
|
+
options.stubs = False
|
|
99
|
+
elif backend is cxx_backend and opt.startswith("bh="):
|
|
100
|
+
options.header_suffix = opt[len("bh=") :]
|
|
101
|
+
elif backend is cxx_backend and opt.startswith("bs="):
|
|
102
|
+
options.source_suffix = opt[len("bs=") :]
|
|
103
|
+
elif backend is rust_backend and opt.startswith("bextern="):
|
|
104
|
+
module, sep, path = opt[len("bextern=") :].partition("=")
|
|
105
|
+
if not sep or not module or not path:
|
|
106
|
+
sys.stderr.write("rustorb-idl: -Wbextern needs MODULE=PATH\n")
|
|
107
|
+
return 2
|
|
108
|
+
if not path.startswith(("::", "crate::", "super::", "self::")):
|
|
109
|
+
path = "::" + path
|
|
110
|
+
options.externs[module] = path
|
|
111
|
+
elif backend is rust_backend and opt.startswith("bcore="):
|
|
112
|
+
options.core = opt[len("bcore=") :]
|
|
113
|
+
elif backend is rust_backend and opt == "bno_rustfmt":
|
|
114
|
+
options.rustfmt = False
|
|
115
|
+
else:
|
|
116
|
+
sys.stderr.write("rustorb-idl: unknown option -W%s\n" % opt)
|
|
117
|
+
return 2
|
|
118
|
+
defines = {}
|
|
119
|
+
for d in args.define:
|
|
120
|
+
name, _, value = d.partition("=")
|
|
121
|
+
defines[name] = value or "1"
|
|
122
|
+
status = 0
|
|
123
|
+
for path in args.files:
|
|
124
|
+
try:
|
|
125
|
+
spec = frontend.load(path, args.include + [IDL_DIR], defines, args.encoding)
|
|
126
|
+
if backend is python_backend:
|
|
127
|
+
generator = python_backend.PythonBackend(spec, options)
|
|
128
|
+
elif backend is java_backend:
|
|
129
|
+
generator = java_backend.JavaBackend(spec, options)
|
|
130
|
+
elif backend is rust_backend:
|
|
131
|
+
generator = rust_backend.RustBackend(spec, options)
|
|
132
|
+
else:
|
|
133
|
+
generator = cxx_backend.CxxBackend(spec, options)
|
|
134
|
+
backend.write_outputs(generator, args.outdir)
|
|
135
|
+
except frontend.GeneratorError as e:
|
|
136
|
+
sys.stderr.write("rustorb-idl: %s\n" % e)
|
|
137
|
+
status = 1
|
|
138
|
+
return status
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def main_exit():
|
|
142
|
+
sys.exit(main())
|