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. ...@@ -158,19 +158,24 @@ you'll need to add calls to your own `JNI_OnLoad` and `JNI_OnUnload` functions.
##### Includes & Build Target ##### Includes & Build Target
Generated file for Objective-C / C++ is as follows (assuming prefix is `DB`): Generated file for Objective-C / C++ is as follows (assuming prefix is `DB`):
| Type | C++ header | C++ source | Objective-C header | Objective-C source | | Type | C++ header | C++ source | Objective-C header | Objective-C source |
|----------------|------------------------|----------------------------|----------------------------------|---------------------------| |----------------|------------------------|----------------------------|--------------------------------------------|-------------------------------------|
| Enum | my\_enum.hpp | | DBMyEnum.h | DBMyEnumTranslator.mm | | Enum | my\_enum.hpp | | ` public/`DBMyEnum.h | `private/`DBMyEnumTranslator.mm |
| | | | DBMyEnumTranslator+Private.h | | | | | | `private/`DBMyEnumTranslator+Private.h | |
| Record | my\_record[\_base].hpp | my\_record[\_base].cpp (+) | DBMyRecord[Base].h | DBMyRecord[Base].mm | | Record | my\_record[\_base].hpp | my\_record[\_base].cpp (+) | ` public/`DBMyRecord[Base].h | `private/`DBMyRecord[Base].mm |
| | | | DBMyRecord[Base]+Private.h | | | | | | `private/`DBMyRecord[Base]+Private.h | |
| Interface `+c` | my\_interface.hpp | my\_interface.cpp (+) | DBMyInterface.h | DBMyInterfaceCppProxy.mm | | Interface `+c` | my\_interface.hpp | my\_interface.cpp (+) | ` public/`DBMyInterface.h | `private/`DBMyInterfaceCppProxy.mm |
| | | | DBMyInterfaceCppProxy+Private.h | | | | | | ` public/`DBMyInterfaceCppProxy.h | |
| Interface `+o` | my\_interface.hpp | my\_interface.cpp (+) | DBMyInterface.h | DBMyInterfaceObjcProxy.mm | | | | | `private/`DBMyInterfaceCppProxy+Private.h | |
| | | | DBMyInterfaceObjcProxy+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. (+) 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`. 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). Note that `+Private` headers can only be used with ObjC++ source (other headers are pure ObjC).
......
...@@ -35,7 +35,6 @@ object Main { ...@@ -35,7 +35,6 @@ object Main {
var javaPackage: Option[String] = None var javaPackage: Option[String] = None
var javaCppException: Option[String] = None var javaCppException: Option[String] = None
var javaAnnotation: Option[String] = None var javaAnnotation: Option[String] = None
var objcOutFolder: Option[File] = None
var jniOutFolder: Option[File] = None var jniOutFolder: Option[File] = None
var jniHeaderOutFolderOptional: Option[File] = None var jniHeaderOutFolderOptional: Option[File] = None
var jniNamespace: String = "djinni_generated" var jniNamespace: String = "djinni_generated"
...@@ -51,11 +50,14 @@ object Main { ...@@ -51,11 +50,14 @@ object Main {
var javaIdentStyle = IdentStyle.javaDefault var javaIdentStyle = IdentStyle.javaDefault
var cppIdentStyle = IdentStyle.cppDefault var cppIdentStyle = IdentStyle.cppDefault
var cppTypeEnumIdentStyle: IdentConverter = null var cppTypeEnumIdentStyle: IdentConverter = null
var objcOutFolder: Option[File] = None
var objcPrivateOutFolderOptional: Option[File] = None
var objcExt: String = "mm" var objcExt: String = "mm"
var objcHeaderExt: String = "h" var objcHeaderExt: String = "h"
var objcIdentStyle = IdentStyle.objcDefault var objcIdentStyle = IdentStyle.objcDefault
var objcTypePrefix: String = "" var objcTypePrefix: String = ""
var objcIncludePrefix: String = "" var objcIncludePrefix: String = ""
var objcIncludePrivatePrefixOptional: Option[String] = None
var objcIncludeCppPrefix: String = "" var objcIncludeCppPrefix: String = ""
var objcFileIdentStyleOptional: Option[IdentConverter] = None var objcFileIdentStyleOptional: Option[IdentConverter] = None
var objcppNamespace: String = "djinni_generated" var objcppNamespace: String = "djinni_generated"
...@@ -120,6 +122,8 @@ object Main { ...@@ -120,6 +122,8 @@ object Main {
note("") note("")
opt[File]("objc-out").valueName("<out-folder>").foreach(x => objcOutFolder = Some(x)) opt[File]("objc-out").valueName("<out-folder>").foreach(x => objcOutFolder = Some(x))
.text("The output folder for Objective-C files (Generator disabled if unspecified).") .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 = _) opt[String]("objc-ext").valueName("<ext>").foreach(objcExt = _)
.text("The filename extension for Objective-C files (default: \"mm\")") .text("The filename extension for Objective-C files (default: \"mm\")")
opt[String]("objc-h-ext").valueName("<ext>").foreach(objcHeaderExt = _) opt[String]("objc-h-ext").valueName("<ext>").foreach(objcHeaderExt = _)
...@@ -128,6 +132,8 @@ object Main { ...@@ -128,6 +132,8 @@ object Main {
.text("The prefix for Objective-C data types (usually two or three letters)") .text("The prefix for Objective-C data types (usually two or three letters)")
opt[String]("objc-include-prefix").valueName("<prefix>").foreach(objcIncludePrefix = _) opt[String]("objc-include-prefix").valueName("<prefix>").foreach(objcIncludePrefix = _)
.text("The prefix for #import of header files from Objective-C files.") .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 = _) opt[String]("objc-include-cpp-prefix").valueName("<prefix>").foreach(objcIncludeCppPrefix = _)
.text("The prefix for #include of the main header files from Objective-C files.") .text("The prefix for #include of the main header files from Objective-C files.")
opt[String]("objcpp-namespace").valueName("<prefix>").foreach(objcppNamespace = _) opt[String]("objcpp-namespace").valueName("<prefix>").foreach(objcppNamespace = _)
...@@ -168,6 +174,8 @@ object Main { ...@@ -168,6 +174,8 @@ object Main {
val jniBaseLibClassIdentStyle = jniBaseLibClassIdentStyleOptional.getOrElse(jniClassIdentStyle) val jniBaseLibClassIdentStyle = jniBaseLibClassIdentStyleOptional.getOrElse(jniClassIdentStyle)
val jniFileIdentStyle = jniFileIdentStyleOptional.getOrElse(cppFileIdentStyle) val jniFileIdentStyle = jniFileIdentStyleOptional.getOrElse(cppFileIdentStyle)
var objcFileIdentStyle = objcFileIdentStyleOptional.getOrElse(objcIdentStyle.ty) var objcFileIdentStyle = objcFileIdentStyleOptional.getOrElse(objcIdentStyle.ty)
val objcPrivateOutFolder = if (objcPrivateOutFolderOptional.isDefined) objcPrivateOutFolderOptional else objcOutFolder
var objcIncludePrivatePrefix = objcIncludePrivatePrefixOptional.getOrElse(objcIncludePrefix)
// Add ObjC prefix to identstyle // Add ObjC prefix to identstyle
objcIdentStyle = objcIdentStyle.copy(ty = IdentStyle.prefix(objcTypePrefix,objcIdentStyle.ty)) objcIdentStyle = objcIdentStyle.copy(ty = IdentStyle.prefix(objcTypePrefix,objcIdentStyle.ty))
...@@ -223,11 +231,13 @@ object Main { ...@@ -223,11 +231,13 @@ object Main {
cppExt, cppExt,
cppHeaderExt, cppHeaderExt,
objcOutFolder, objcOutFolder,
objcPrivateOutFolder,
objcIdentStyle, objcIdentStyle,
objcFileIdentStyle, objcFileIdentStyle,
objcExt, objcExt,
objcHeaderExt, objcHeaderExt,
objcIncludePrefix, objcIncludePrefix,
objcIncludePrivatePrefix,
objcIncludeCppPrefix, objcIncludeCppPrefix,
objcppNamespace, objcppNamespace,
objcBaseLibIncludePrefix) objcBaseLibIncludePrefix)
......
This diff is collapsed.
...@@ -53,11 +53,13 @@ package object generatorTools { ...@@ -53,11 +53,13 @@ package object generatorTools {
cppExt: String, cppExt: String,
cppHeaderExt: String, cppHeaderExt: String,
objcOutFolder: Option[File], objcOutFolder: Option[File],
objcPrivateOutFolder: Option[File],
objcIdentStyle: ObjcIdentStyle, objcIdentStyle: ObjcIdentStyle,
objcFileIdentStyle: IdentConverter, objcFileIdentStyle: IdentConverter,
objcExt: String, objcExt: String,
objcHeaderExt: String, objcHeaderExt: String,
objcIncludePrefix: String, objcIncludePrefix: String,
objcIncludePrivatePrefix: String,
objcIncludeCppPrefix: String, objcIncludeCppPrefix: String,
objcppNamespace: String, objcppNamespace: String,
objcBaseLibIncludePrefix: String) objcBaseLibIncludePrefix: String)
...@@ -165,6 +167,7 @@ package object generatorTools { ...@@ -165,6 +167,7 @@ package object generatorTools {
} }
if (spec.objcOutFolder.isDefined) { if (spec.objcOutFolder.isDefined) {
createFolder("Objective-C[++]", spec.objcOutFolder.get) createFolder("Objective-C[++]", spec.objcOutFolder.get)
createFolder("Objective-C[++] private", spec.objcPrivateOutFolder.get)
new ObjcGenerator(spec).generate(idl) new ObjcGenerator(spec).generate(idl)
} }
None 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