Commit f4064e72 authored by Miro Knejp's avatar Miro Knejp Committed by Jacob Potter

Allow the separation of public and private Objective-C files

The new options --objc-private-out and --objc-include-private-prefix control where the private Objective-C[++] files (i.e. +Private.h and .mm) are placed and which prefix is used to #import or #include them. This allows a clean separation of the public interface and the hidden private parts.

As a bonus this fixes the bug where the Objective-C generator was completely ignoring the --objc-include-prefix and --objc-include-cpp-prefix options.
parent 86e6e0d3
......@@ -158,19 +158,24 @@ you'll need to add calls to your own `JNI_OnLoad` and `JNI_OnUnload` functions.
##### Includes & Build Target
Generated file for Objective-C / C++ is as follows (assuming prefix is `DB`):
| Type | C++ header | C++ source | Objective-C header | Objective-C source |
|----------------|------------------------|----------------------------|----------------------------------|---------------------------|
| Enum | my\_enum.hpp | | DBMyEnum.h | DBMyEnumTranslator.mm |
| | | | DBMyEnumTranslator+Private.h | |
| Record | my\_record[\_base].hpp | my\_record[\_base].cpp (+) | DBMyRecord[Base].h | DBMyRecord[Base].mm |
| | | | DBMyRecord[Base]+Private.h | |
| Interface `+c` | my\_interface.hpp | my\_interface.cpp (+) | DBMyInterface.h | DBMyInterfaceCppProxy.mm |
| | | | DBMyInterfaceCppProxy+Private.h | |
| Interface `+o` | my\_interface.hpp | my\_interface.cpp (+) | DBMyInterface.h | DBMyInterfaceObjcProxy.mm |
| | | | DBMyInterfaceObjcProxy+Private.h | |
| Type | C++ header | C++ source | Objective-C header | Objective-C source |
|----------------|------------------------|----------------------------|--------------------------------------------|-------------------------------------|
| Enum | my\_enum.hpp | | ` public/`DBMyEnum.h | `private/`DBMyEnumTranslator.mm |
| | | | `private/`DBMyEnumTranslator+Private.h | |
| Record | my\_record[\_base].hpp | my\_record[\_base].cpp (+) | ` public/`DBMyRecord[Base].h | `private/`DBMyRecord[Base].mm |
| | | | `private/`DBMyRecord[Base]+Private.h | |
| Interface `+c` | my\_interface.hpp | my\_interface.cpp (+) | ` public/`DBMyInterface.h | `private/`DBMyInterfaceCppProxy.mm |
| | | | ` public/`DBMyInterfaceCppProxy.h | |
| | | | `private/`DBMyInterfaceCppProxy+Private.h | |
| Interface `+o` | my\_interface.hpp | my\_interface.cpp (+) | ` public/`DBMyInterface.h | `private/`DBMyInterfaceObjcProxy.mm |
| | | | `private/`DBMyInterfaceObjcProxy+Private.h | |
(+) Generated only for types that contain constants.
The folders `public` and `private` correspond to the options `--objc-out` and `--objc-private-out`
respecitvely, allowing you to isolate implementation headers and sources from the public files
exposed to Objective-C clients.
Add all generated files to your build target, as well as the contents of `support-lib/objc`.
Note that `+Private` headers can only be used with ObjC++ source (other headers are pure ObjC).
......
......@@ -35,7 +35,6 @@ object Main {
var javaPackage: Option[String] = None
var javaCppException: Option[String] = None
var javaAnnotation: Option[String] = None
var objcOutFolder: Option[File] = None
var jniOutFolder: Option[File] = None
var jniHeaderOutFolderOptional: Option[File] = None
var jniNamespace: String = "djinni_generated"
......@@ -51,11 +50,14 @@ object Main {
var javaIdentStyle = IdentStyle.javaDefault
var cppIdentStyle = IdentStyle.cppDefault
var cppTypeEnumIdentStyle: IdentConverter = null
var objcOutFolder: Option[File] = None
var objcPrivateOutFolderOptional: Option[File] = None
var objcExt: String = "mm"
var objcHeaderExt: String = "h"
var objcIdentStyle = IdentStyle.objcDefault
var objcTypePrefix: String = ""
var objcIncludePrefix: String = ""
var objcIncludePrivatePrefixOptional: Option[String] = None
var objcIncludeCppPrefix: String = ""
var objcFileIdentStyleOptional: Option[IdentConverter] = None
var objcppNamespace: String = "djinni_generated"
......@@ -120,6 +122,8 @@ object Main {
note("")
opt[File]("objc-out").valueName("<out-folder>").foreach(x => objcOutFolder = Some(x))
.text("The output folder for Objective-C files (Generator disabled if unspecified).")
opt[File]("objc-private-out").valueName("<out-folder>").foreach(x => objcPrivateOutFolderOptional = Some(x))
.text("The output folder for private Objective-C header and implementation files (default: the same as --objc-out)")
opt[String]("objc-ext").valueName("<ext>").foreach(objcExt = _)
.text("The filename extension for Objective-C files (default: \"mm\")")
opt[String]("objc-h-ext").valueName("<ext>").foreach(objcHeaderExt = _)
......@@ -128,6 +132,8 @@ object Main {
.text("The prefix for Objective-C data types (usually two or three letters)")
opt[String]("objc-include-prefix").valueName("<prefix>").foreach(objcIncludePrefix = _)
.text("The prefix for #import of header files from Objective-C files.")
opt[String]("objc-include-private-prefix").valueName("<prefix>").foreach(x => objcIncludePrivatePrefixOptional = Some(x))
.text("The prefix for #import and #include of private header files from Objective-C files (default: the same as --objc-include-prefix)")
opt[String]("objc-include-cpp-prefix").valueName("<prefix>").foreach(objcIncludeCppPrefix = _)
.text("The prefix for #include of the main header files from Objective-C files.")
opt[String]("objcpp-namespace").valueName("<prefix>").foreach(objcppNamespace = _)
......@@ -168,6 +174,8 @@ object Main {
val jniBaseLibClassIdentStyle = jniBaseLibClassIdentStyleOptional.getOrElse(jniClassIdentStyle)
val jniFileIdentStyle = jniFileIdentStyleOptional.getOrElse(cppFileIdentStyle)
var objcFileIdentStyle = objcFileIdentStyleOptional.getOrElse(objcIdentStyle.ty)
val objcPrivateOutFolder = if (objcPrivateOutFolderOptional.isDefined) objcPrivateOutFolderOptional else objcOutFolder
var objcIncludePrivatePrefix = objcIncludePrivatePrefixOptional.getOrElse(objcIncludePrefix)
// Add ObjC prefix to identstyle
objcIdentStyle = objcIdentStyle.copy(ty = IdentStyle.prefix(objcTypePrefix,objcIdentStyle.ty))
......@@ -223,11 +231,13 @@ object Main {
cppExt,
cppHeaderExt,
objcOutFolder,
objcPrivateOutFolder,
objcIdentStyle,
objcFileIdentStyle,
objcExt,
objcHeaderExt,
objcIncludePrefix,
objcIncludePrivatePrefix,
objcIncludeCppPrefix,
objcppNamespace,
objcBaseLibIncludePrefix)
......
This diff is collapsed.
......@@ -53,11 +53,13 @@ package object generatorTools {
cppExt: String,
cppHeaderExt: String,
objcOutFolder: Option[File],
objcPrivateOutFolder: Option[File],
objcIdentStyle: ObjcIdentStyle,
objcFileIdentStyle: IdentConverter,
objcExt: String,
objcHeaderExt: String,
objcIncludePrefix: String,
objcIncludePrivatePrefix: String,
objcIncludeCppPrefix: String,
objcppNamespace: String,
objcBaseLibIncludePrefix: String)
......@@ -165,6 +167,7 @@ package object generatorTools {
}
if (spec.objcOutFolder.isDefined) {
createFolder("Objective-C[++]", spec.objcOutFolder.get)
createFolder("Objective-C[++] private", spec.objcPrivateOutFolder.get)
new ObjcGenerator(spec).generate(idl)
}
None
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment