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

Generate an XCode like bridging header. #342

Merged
merged 4 commits into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 TextSort_Bridging_Header.
FOUNDATION_EXPORT double TextSort_Bridging_HeaderVersionNumber;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to have a _ separating TextSort_Bridging_Header and VersionNumber so that it's TextSort_Bridging_Header_VersionNumber.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I choosed the Xcode Convention. By calling a framework MyLib, the two variables are named MyLibVersionNumber and MyLibVersionString

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for the explanation.
In that case, would it make sense to name it TextSortBridgingHeaderVersionNumber?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess yes 🤔


//! Project version string forTextSort_Bridging_Header.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space between "for" and "TextSort_Bridging_Header" here.

FOUNDATION_EXPORT const unsigned char TextSort_Bridging_HeaderVersionString[];

#import "TXSItemList.h"
#import "TXSSortOrder.h"
#import "TXSSortItems.h"
Expand Down
1 change: 1 addition & 0 deletions src/source/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ object Main {
objcppNamespace,
objcBaseLibIncludePrefix,
objcSwiftBridgingHeaderWriter,
objcSwiftBridgingHeader,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be objcSwiftBridgingHeaderName as you're using spec.objcSwiftBridgingHeaderName.get below.

Actually, I'd love to see this config used in Unit Test for verification.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable is declared as objcSwiftBridgingHeader inside main.scala.
Do you want me to change the name of the property in generator.scala from objcSwiftBridgingHeaderName to objcSwiftBridgingHeader instead?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, it's just the variable name here while objcSwiftBridgingHeaderName is the parameter, sorry I got confused.
Yes, I'd prefer to have the same name since this is the case for all the other parameters.

outFileListWriter,
skipGeneration,
yamlOutFolder,
Expand Down
17 changes: 16 additions & 1 deletion src/source/SwiftBridgingHeaderGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,23 @@ class SwiftBridgingHeaderGenerator(spec: Spec) extends Generator(spec) {
}

object SwiftBridgingHeaderGenerator {
def writeAutogenerationWarning(writer: Writer) {

val bridgingVarPrefix = (s: String) => s.split('-').mkString("_")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to my comment below, I'd prefer to remove the Prefix here, to make it something like bridgingHeaderName, since it doesn't have to be used as a prefix. (Although it's not a great name either, as - is replaced by _ and this method name I suggest wouldn't make it obvious.)


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

def writeBridgingVars(name: String, writer: Writer) {
val varPrefix = bridgingVarPrefix(name)
writer.write("#import <Foundation/Foundation.h>\n\n")
writer.write("//! Project version number for " + varPrefix +".\n")
writer.write("FOUNDATION_EXPORT double " + varPrefix + "VersionNumber;\n\n")
writer.write("//! Project version string for" + varPrefix +".\n")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add a space after for.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the way this variable is named. In this case: "..." + varPrefix +"...", it's not used as a prefix.

Although it happens to be a prefix in the case of VersionNumber, I'd still prefer to remove the prefix in the var name, to make it something like bridgingHeaderVarName.

writer.write("FOUNDATION_EXPORT const unsigned char " + varPrefix + "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 @@ -76,6 +76,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 @@ -216,7 +217,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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent with the declaration objcSwiftBridgingHeader above.

SwiftBridgingHeaderGenerator.writeBridgingVars(spec.objcSwiftBridgingHeaderName.get, spec.objcSwiftBridgingHeaderWriter.get)
new SwiftBridgingHeaderGenerator(spec).generate(idl)
}
if (spec.yamlOutFolder.isDefined) {
Expand Down