5
5
// This hook automates this:
6
6
// https://github.com/eface2face/cordova-plugin-iosrtc/blob/master/docs/Building.md
7
7
8
- var fs = require ( "fs" ) ,
8
+ var
9
+ fs = require ( "fs" ) ,
9
10
path = require ( "path" ) ,
10
11
xcode = require ( 'xcode' ) ,
11
12
12
- BUILD_VERSION = '8.2 ' ,
13
+ BUILD_VERSION = '7.0 ' ,
13
14
BUILD_VERSION_XCODE = '"' + BUILD_VERSION + '"' ,
14
15
RUNPATH_SEARCH_PATHS = '@executable_path/Frameworks' ,
15
16
RUNPATH_SEARCH_PATHS_XCODE = '"' + RUNPATH_SEARCH_PATHS + '"' ,
16
-
17
+ ENABLE_BITCODE = 'NO' ,
18
+ ENABLE_BITCODE_XCODE = '"' + ENABLE_BITCODE + '"' ,
17
19
BRIDGING_HEADER_END = '/Plugins/cordova-plugin-iosrtc/cordova-plugin-iosrtc-Bridging-Header.h' ,
18
20
COMMENT_KEY = / _ c o m m e n t $ / ;
19
21
@@ -22,15 +24,17 @@ var fs = require("fs"),
22
24
23
25
// Returns the project name
24
26
function getProjectName ( protoPath ) {
25
- var cordovaConfigPath = path . join ( protoPath , 'config.xml' ) ,
27
+ var
28
+ cordovaConfigPath = path . join ( protoPath , 'config.xml' ) ,
26
29
content = fs . readFileSync ( cordovaConfigPath , 'utf-8' ) ;
27
30
28
31
return / < n a m e > ( [ \s \S ] * ) < \/ n a m e > / mi. exec ( content ) [ 1 ] . trim ( ) ;
29
32
}
30
33
31
34
// Drops the comments
32
35
function nonComments ( obj ) {
33
- var keys = Object . keys ( obj ) ,
36
+ var
37
+ keys = Object . keys ( obj ) ,
34
38
newObj = { } ,
35
39
i = 0 ;
36
40
@@ -47,7 +51,8 @@ function nonComments(obj) {
47
51
// Starting here
48
52
49
53
module . exports = function ( context ) {
50
- var projectRoot = context . opts . projectRoot ,
54
+ var
55
+ projectRoot = context . opts . projectRoot ,
51
56
projectName = getProjectName ( projectRoot ) ,
52
57
xcconfigPath = path . join ( projectRoot , '/platforms/ios/cordova/build.xcconfig' ) ,
53
58
xcodeProjectName = projectName + '.xcodeproj' ,
@@ -59,24 +64,27 @@ module.exports = function (context) {
59
64
60
65
// Checking if the project files are in the right place
61
66
if ( ! fs . existsSync ( xcodeProjectPath ) ) {
62
- console . error ( 'ERROR: An error occured searching the project file at: "' + xcodeProjectPath + '"' ) ;
67
+ debugerror ( 'an error occurred searching the project file at: "' + xcodeProjectPath + '"' ) ;
63
68
64
69
return ;
65
70
}
66
- console . log ( '".pbxproj" project file found: ' + xcodeProjectPath ) ;
71
+ debug ( '".pbxproj" project file found: ' + xcodeProjectPath ) ;
72
+
67
73
if ( ! fs . existsSync ( xcconfigPath ) ) {
68
- console . error ( 'ERROR: An error occured searching the project file at: "' + xcconfigPath + '"' ) ;
74
+ debugerror ( 'an error occurred searching the project file at: "' + xcconfigPath + '"' ) ;
69
75
70
76
return ;
71
77
}
72
- console . log ( '".xcconfig" project file found: ' + xcconfigPath ) ;
78
+ debug ( '".xcconfig" project file found: ' + xcconfigPath ) ;
79
+
73
80
xcodeProject = xcode . project ( xcodeProjectPath ) ;
74
81
75
82
// Showing info about the tasks to do
76
- console . log ( 'Fixing issues in the generated project files:' ) ;
77
- console . log ( '- "iOS Deployment Target" and "Deployment Target" to: ' + BUILD_VERSION_XCODE ) ;
78
- console . log ( '- "Runpath Search Paths" to: ' + RUNPATH_SEARCH_PATHS_XCODE ) ;
79
- console . log ( '- "Objective-C Bridging Header" to: ' + swiftBridgingHeadXcode ) ;
83
+ debug ( 'fixing issues in the generated project files:' ) ;
84
+ debug ( '- "iOS Deployment Target" and "Deployment Target" to: ' + BUILD_VERSION_XCODE ) ;
85
+ debug ( '- "Runpath Search Paths" to: ' + RUNPATH_SEARCH_PATHS_XCODE ) ;
86
+ debug ( '- "Objective-C Bridging Header" to: ' + swiftBridgingHeadXcode ) ;
87
+ debug ( '- "ENABLE_BITCODE" set to: ' + ENABLE_BITCODE_XCODE ) ;
80
88
81
89
82
90
// Massaging the files
@@ -85,32 +93,46 @@ module.exports = function (context) {
85
93
swiftOptions . push ( 'LD_RUNPATH_SEARCH_PATHS = ' + RUNPATH_SEARCH_PATHS ) ;
86
94
swiftOptions . push ( 'SWIFT_OBJC_BRIDGING_HEADER = ' + swiftBridgingHead ) ;
87
95
swiftOptions . push ( 'IPHONEOS_DEPLOYMENT_TARGET = ' + BUILD_VERSION ) ;
96
+ swiftOptions . push ( 'ENABLE_BITCODE = ' + ENABLE_BITCODE ) ;
88
97
// NOTE: Not needed
89
98
// swiftOptions.push('EMBEDDED_CONTENT_CONTAINS_SWIFT = YES');
90
99
fs . appendFileSync ( xcconfigPath , swiftOptions . join ( '\n' ) ) ;
91
- console . log ( 'File correctly fixed: ' + xcconfigPath ) ;
100
+ debug ( 'file correctly fixed: ' + xcconfigPath ) ;
92
101
93
102
// "project.pbxproj"
94
103
// Parsing it
95
104
xcodeProject . parse ( function ( error ) {
96
105
var configurations , buildSettings ;
97
106
98
107
if ( error ) {
99
- console . error ( 'ERROR: An error occured during the parse of the project file' ) ;
100
- } else {
101
- configurations = nonComments ( xcodeProject . pbxXCBuildConfigurationSection ( ) ) ;
102
- // Adding or changing the parameters we need
103
- Object . keys ( configurations ) . forEach ( function ( config ) {
104
- buildSettings = configurations [ config ] . buildSettings ;
105
- buildSettings . LD_RUNPATH_SEARCH_PATHS = RUNPATH_SEARCH_PATHS_XCODE ;
106
- buildSettings . SWIFT_OBJC_BRIDGING_HEADER = swiftBridgingHeadXcode ;
107
- buildSettings . IPHONEOS_DEPLOYMENT_TARGET = BUILD_VERSION_XCODE ;
108
- } ) ;
109
-
110
- // Writing the file again
111
- fs . writeFileSync ( xcodeProjectPath , xcodeProject . writeSync ( ) , 'utf-8' ) ;
112
- console . log ( 'File correctly fixed: ' + xcodeProjectPath ) ;
108
+ debugerror ( 'an error occurred during the parsing of the project file' ) ;
109
+
110
+ return ;
113
111
}
114
- } ) ;
115
112
113
+
114
+ configurations = nonComments ( xcodeProject . pbxXCBuildConfigurationSection ( ) ) ;
115
+ // Adding or changing the parameters we need
116
+ Object . keys ( configurations ) . forEach ( function ( config ) {
117
+ buildSettings = configurations [ config ] . buildSettings ;
118
+ buildSettings . LD_RUNPATH_SEARCH_PATHS = RUNPATH_SEARCH_PATHS_XCODE ;
119
+ buildSettings . SWIFT_OBJC_BRIDGING_HEADER = swiftBridgingHeadXcode ;
120
+ buildSettings . IPHONEOS_DEPLOYMENT_TARGET = BUILD_VERSION_XCODE ;
121
+ buildSettings . ENABLE_BITCODE = ENABLE_BITCODE_XCODE ;
122
+ } ) ;
123
+
124
+ // Writing the file again
125
+ fs . writeFileSync ( xcodeProjectPath , xcodeProject . writeSync ( ) , 'utf-8' ) ;
126
+ debug ( 'file correctly fixed: ' + xcodeProjectPath ) ;
127
+ } ) ;
116
128
} ;
129
+
130
+
131
+ function debug ( msg ) {
132
+ console . log ( 'iosrtc-swift-support.js [INFO] ' + msg ) ;
133
+ }
134
+
135
+
136
+ function debugerror ( msg ) {
137
+ console . error ( 'iosrtc-swift-support.js [ERROR] ' + msg ) ;
138
+ }
0 commit comments