Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
Generate an XCode like bridging header. (#342)
Browse files Browse the repository at this point in the history
* Generate an XCode like bridging header.

Generates also the version number and name variable.

* Add new generated headers.

* Changes naming accorging to comments.

* Update generated variable names.
  • Loading branch information
yageek authored and Xianwen Chen committed Mar 2, 2018
1 parent 0001a3e commit 9463fa9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
11 changes: 11 additions & 0 deletions example/generated-src/objc/TextSort-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni

// TextSort_Bridging_Header.h
// TextSort_Bridging_Header

#import <Foundation/Foundation.h>

//! Project version number for TextSortBridgingHeader.
FOUNDATION_EXPORT double TextSortBridgingHeaderVersionNumber;

//! Project version string for TextSortBridgingHeader.
FOUNDATION_EXPORT const unsigned char TextSortBridgingHeaderVersionString[];

#import "TXSItemList.h"
#import "TXSSortOrder.h"
#import "TXSSortItems.h"
Expand Down
9 changes: 5 additions & 4 deletions src/source/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object Main {
var objcTypePrefix: String = ""
var objcIncludePrefix: String = ""
var objcExtendedRecordIncludePrefix: String = ""
var objcSwiftBridgingHeader: Option[String] = None
var objcSwiftBridgingHeaderName: Option[String] = None
var objcppIncludePrefix: String = ""
var objcppIncludeCppPrefix: String = ""
var objcppIncludeObjcPrefixOptional: Option[String] = None
Expand Down Expand Up @@ -168,7 +168,7 @@ 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-swift-bridging-header").valueName("<name>").foreach(x => objcSwiftBridgingHeader = Some(x))
opt[String]("objc-swift-bridging-header").valueName("<name>").foreach(x => objcSwiftBridgingHeaderName = Some(x))
.text("The name of Objective-C Bridging Header used in XCode's Swift projects.")
note("")
opt[File]("objcpp-out").valueName("<out-folder>").foreach(x => objcppOutFolder = Some(x))
Expand Down Expand Up @@ -288,8 +288,8 @@ object Main {
} else {
None
}
val objcSwiftBridgingHeaderWriter = if (objcSwiftBridgingHeader.isDefined && objcOutFolder.isDefined) {
val objcSwiftBridgingHeaderFile = new File(objcOutFolder.get.getPath, objcSwiftBridgingHeader.get + ".h")
val objcSwiftBridgingHeaderWriter = if (objcSwiftBridgingHeaderName.isDefined && objcOutFolder.isDefined) {
val objcSwiftBridgingHeaderFile = new File(objcOutFolder.get.getPath, objcSwiftBridgingHeaderName.get + ".h")
if (objcSwiftBridgingHeaderFile.getParentFile != null)
createFolder("output file list", objcSwiftBridgingHeaderFile.getParentFile)
Some(new BufferedWriter(new FileWriter(objcSwiftBridgingHeaderFile)))
Expand Down Expand Up @@ -346,6 +346,7 @@ object Main {
objcppNamespace,
objcBaseLibIncludePrefix,
objcSwiftBridgingHeaderWriter,
objcSwiftBridgingHeaderName,
outFileListWriter,
skipGeneration,
yamlOutFolder,
Expand Down
18 changes: 17 additions & 1 deletion src/source/SwiftBridgingHeaderGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,24 @@ class SwiftBridgingHeaderGenerator(spec: Spec) extends Generator(spec) {
}

object SwiftBridgingHeaderGenerator {
def writeAutogenerationWarning(writer: Writer) {

val bridgingHeaderName = (s: String) => s.split('-').mkString("_")
val bridgingHeaderVariables = (s: String) => s.split('-').mkString("")

def writeAutogenerationWarning(name: String, writer: Writer) {
val bridgingHeaderVarName = bridgingHeaderName(name)
writer.write("// AUTOGENERATED FILE - DO NOT MODIFY!\n")
writer.write("// This file generated by Djinni\n\n")
writer.write("// " + bridgingHeaderVarName + ".h\n")
writer.write("// " + bridgingHeaderVarName + "\n\n")
}

def writeBridgingVars(name: String, writer: Writer) {
val bridgingHeaderVarName = bridgingHeaderVariables(name)
writer.write("#import <Foundation/Foundation.h>\n\n")
writer.write("//! Project version number for " + bridgingHeaderVarName +".\n")
writer.write("FOUNDATION_EXPORT double " + bridgingHeaderVarName + "VersionNumber;\n\n")
writer.write("//! Project version string for " + bridgingHeaderVarName +".\n")
writer.write("FOUNDATION_EXPORT const unsigned char " + bridgingHeaderVarName + "VersionString[];\n\n")
}
}
4 changes: 3 additions & 1 deletion src/source/generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ package object generatorTools {
objcppNamespace: String,
objcBaseLibIncludePrefix: String,
objcSwiftBridgingHeaderWriter: Option[Writer],
objcSwiftBridgingHeaderName: Option[String],
outFileListWriter: Option[Writer],
skipGeneration: Boolean,
yamlOutFolder: Option[File],
Expand Down Expand Up @@ -217,7 +218,8 @@ package object generatorTools {
new ObjcppGenerator(spec).generate(idl)
}
if (spec.objcSwiftBridgingHeaderWriter.isDefined) {
SwiftBridgingHeaderGenerator.writeAutogenerationWarning(spec.objcSwiftBridgingHeaderWriter.get)
SwiftBridgingHeaderGenerator.writeAutogenerationWarning(spec.objcSwiftBridgingHeaderName.get, spec.objcSwiftBridgingHeaderWriter.get)
SwiftBridgingHeaderGenerator.writeBridgingVars(spec.objcSwiftBridgingHeaderName.get, spec.objcSwiftBridgingHeaderWriter.get)
new SwiftBridgingHeaderGenerator(spec).generate(idl)
}
if (spec.yamlOutFolder.isDefined) {
Expand Down

0 comments on commit 9463fa9

Please sign in to comment.