Copyright (C) 2000-2012 |
Whole document tree Chapter 5 The IDL compileromniORBpy uses a new IDL compiler, named omniidl, which is also used by omniORB 3. It consists of a generic front-end parser written in C++, and a number of back-ends written in Python. omniidl is very strict about IDL validity, so you may find that it reports errors in IDL which compiles fine with earlier versions of omniORB, and with other ORBs.The general form of an omniidl command line is: omniidl [options] -b<back-end> [back-end options] <file 1> <file 2> ... 5.1 Common optionsThe following options are common to all back-ends:
Most of these options are self explanatory, but some are not so obvious. 5.1.1 Preprocessor interactionsIDL is processed by the C preprocessor before omniidl parses it. Unlike the old IDL compiler, which used different C preprocessors on different platforms, omniidl always uses the GNU C preprocessor (which it builds with the name omnicpp). The -D, -U, and -I options are just sent to the preprocessor. Note that the current directory is not on the include search path by default---use `-I.' for that. The -Y option can be used to specify a different preprocessor to omnicpp. Beware that line directives inserted by other preprocessors are likely to confuse omniidl.Windows 9xThe output from the C preprocessor is normally fed to the omniidl parser through a pipe. On some Windows 98 machines (but not all!) the pipe does not work, and the preprocessor output is echoed to the screen. When this happens, the omniidl parser sees an empty file, and produces useless stub files with strange long names. To avoid the problem, use the `-T' option to create a temporary file between the two stages.5.1.2 Forward-declared interfacesIf you have an IDL file like:interface I; interface J { attribute I the_I; };then omniidl will normally issue a warning: test.idl:1: Warning: Forward declared interface `::I' was never fully definedIt is illegal to declare such IDL in isolation, but it is valid to define interface I in a separate file. If you have a lot of IDL with this sort of construct, you will drown under the warning messages. Use the -nf option to suppress them. 5.1.3 CommentsBy default, omniidl discards comments in the input IDL. However, with the -k and -K options, it preserves the comments for use by the back-ends. The C++ back-end ignores this information, but it is relatively easy to write new back-ends which do make use of comments.The two different options relate to how comments are attached to declarations within the IDL. Given IDL like: interface I { void op1(); // A comment void op2(); };the -k flag will attach the comment to op1(); the -K flag will attach it to op2(). 5.2 Python back-end optionsWhen you specify the Python back-end (with -bpython), the following -Wb options are available. Note that the -Wb options must be specified after the -bpython option, so omniidl knows which back-end to give the arguments to.
The -Wbstdout option is not really useful if you are invoking omniidl yourself. It is used by omniORB.importIDL(), described in section 6.12. When you compile an IDL file which #includes other IDL files, omniidl normally only generates code for the main file, assuming that code for the included files will be generated separately. Instead, you can use the -Wbinline option to generate code for the main IDL file and all included files in a single stub file. Definitions declared at IDL global scope are normally placed in a Python module named `_GlobalIDL'. The -Wbglobal allows you to change that. As explained in section 2.2, when you compile an IDL file like: // echo_example.idl module Example { interface Echo { string echoString(in string mesg); }; };omniidl generates directories named Example and Example__POA, which provide the standard Python mapping modules, and also the file example_echo_idl.py which contains the actual definitions. The latter file contains code which inserts the definitions in the standard modules. This arrangement means that it is not possible to move all of the generated code into a Python package by simply placing the files in a suitably named directory. You may wish to do this to avoid clashes with names in use elsewhere in your software. You can place all generated code in a package using the -Wbpackage command line option. For example, omniidl -bpython -Wbpackage=generated echo_example.idlcreates a directory named `generated', containing the generated code. The stub module is now called `generated.Example', and the actual stub definitions are in `generated.example_echo_idl'. If you wish to split the modules and the stub definitions into different Python packages, you can use the -Wbmodules and -Wbstubs options. Note that if you use these options to change the module package, the interface to the generated code is not strictly-speaking CORBA compliant. You may have to change your code if you ever use a Python ORB other than omniORBpy. 5.3 ExamplesGenerate the Python stubs for a file a.idl:omniidl -bpython a.idlAs above, but put the stubs in a package called `stubs': omniidl -bpython -Wbstubs=stubs a.idlGenerate both Python and C++ stubs for two IDL files (requires omniORB 3): omniidl -bpython -bcxx a.idl b.idlJust check the IDL files for validity, generating no output: omniidl a.idl b.idl |