-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
130 lines (115 loc) · 4.31 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import org.gradle.internal.impldep.org.apache.commons.io.FileUtils.copyDirectory
allprojects {
repositories {
google()
mavenCentral()
mavenLocal()
}
}
subprojects {
group = project.properties["group"].toString()
version = project.properties["version"].toString()
afterEvaluate {
if (plugins.any { it is MavenPublishPlugin }) {
tasks.register("publishAndroid") { dependsOn("publishAndroidDebugPublicationToMavenLocal") }
}
}
afterEvaluate {
val copyXCFramework = tasks.register<Copy>("copyXCFramework") {
from("build/cocoapods/publish/release")
into("$rootDir/frameworks")
}
tasks.findByName("podPublishReleaseXCFramework")?.finalizedBy(copyXCFramework)
}
}
val appleSDKTempDirPath = "${project.rootDir.absolutePath}/.sdks/apple-testing"
if (File(appleSDKTempDirPath).exists()) {
project.exec {
commandLine = "rm -rf $appleSDKTempDirPath".split(" ")
}
}
project.exec {
commandLine = "cp -r ${project.rootDir.absolutePath}/.sdks/apple $appleSDKTempDirPath".split(" ")
}
val addTestingHeadersToAppleSDK by tasks.creating {
doLast {
File("${project.rootDir.absolutePath}/.sdks/apple-testing/mParticle-Apple-SDK.xcodeproj/project.pbxproj")
.let { file ->
file.readLines()
.let { makeTestingHeadersPublicInXcodeProject(it) }
.let { file.writeText(it.joinToString("\n")) }
}
File("${project.rootDir.absolutePath}/.sdks/apple-testing/mParticle-Apple-SDK.podspec")
.let { file ->
file.readLines()
.let { makeTestingHeadersPublicInCocoapodsPodspec(it) }
.let { file.writeText(it.joinToString("\n")) }
}
}
}
subprojects {
afterEvaluate {
tasks.findByName("podGenIOS")?.dependsOn(addTestingHeadersToAppleSDK)
}
}
allprojects {
afterEvaluate {
tasks.register("publishLocal") {
if (tasks.findByName("publish") != null) {
dependsOn("publishAndroidReleasePublicationToMavenLocal")
}
}
}
}
val additionalHeaders = listOf(
"MPConnectorProtocol.h",
"MPConnectorResponseProtocol.h",
"MPConnectorFactoryProtocol.h",
"MPNetworkCommunication.h",
"MPURL.h"
)
fun String.containsIgnoreWhitespace(other: String) = this.replace(" ", "").contains(other.replace(" ", ""))
fun makeTestingHeadersPublicInXcodeProject(appleSDKProjectFileLines: List<String>): List<String> {
println("Adding Attribute: Public to missing file headers")
return additionalHeaders
.map { additionalHeader ->
println("Locating PBX file reference for: $additionalHeader")
appleSDKProjectFileLines
.firstOrNull { it.contains("= $additionalHeader") }
?.split(" ")
?.first()
?.replace(" ", "")
?.replace("\t", "")
?.also {
println("Found PBX file reference of: $it for: $additionalHeader")
}
?: null.apply {println("Project File is missing the additionalHeader: $additionalHeader")}
}
.fold(appleSDKProjectFileLines) { projectFileLines, fileKey ->
projectFileLines.map {
val itNoWhitespace = it.replace(" ", "")
if (
it.contains("= $fileKey") &&
!itNoWhitespace.contains(" settings = {ATTRIBUTES = (Public, ); };".replace(" ", ""))
) {
println("Adding ATTRIBUTE:Public for: $fileKey")
"${it.subSequence(0, it.indexOfLast { it == '}' })} settings = {ATTRIBUTES = (Public, ); }; };"
} else {
it
}
}
}
}
fun makeTestingHeadersPublicInCocoapodsPodspec(appleSDKProjectFileLines: List<String>): List<String> {
println("Adding missing file headers to Cocoapods public_header_files")
val headerPathString = additionalHeaders
.map { ", 'mParticle-Apple-SDK/Network/$it'" }
.joinToString(separator = "")
return appleSDKProjectFileLines.map {
if (it.contains("ss.public_header_files")) {
"$it$headerPathString"
} else {
it
}
}
}