Skip to content

Commit fbb3ee2

Browse files
committed
fix: leftover files from previous builds in openssl android tree sometimes mixing artifacts archs
1 parent 5869e9f commit fbb3ee2

File tree

1 file changed

+62
-60
lines changed

1 file changed

+62
-60
lines changed

packages/interop-otel/android/build.gradle

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -198,84 +198,91 @@ def prepareOttreliteInteropHeadersTask = tasks.register('prepareOttreliteInterop
198198

199199
preBuild.dependsOn(prepareOttreliteInteropHeadersTask)
200200

201-
tasks.register("buildOpenSSL") {
201+
tasks.register("buildAndInstallOpenSSL") {
202202
def openSSLSourceDirFile = new File(openSSLForAndroidSourceDir, "openssl-${opensslVersion}")
203203
def openSSLSourceDir = openSSLSourceDirFile.path
204204

205205
def opensslTarName = "openssl-${opensslVersion}.tar.gz"
206206
def opensslUrl = "https://github.com/openssl/openssl/releases/download/openssl-${opensslVersion}/${opensslTarName}"
207207

208-
doFirst {
209-
def tarFile = file("${temporaryDir}/${opensslTarName}")
208+
def openSSLTarFile = file("${temporaryDir}/${opensslTarName}")
209+
210+
reactNativeArchitectures().each { abi ->
211+
def cmakeInstallDir = getCmakeInstallDir(abi)
212+
if (new File(cmakeInstallDir, "lib/libssl.a").exists()) {
213+
println("[@ottrelite/interop-otel] OpenSSL already built, skipping build.")
214+
} else {
215+
println("[@ottrelite/interop-otel] Building OpenSSL using openssl_for_android for ABI $abi from ${openSSLForAndroidSourceDir} and writing to source dir...")
210216

211-
def openSSLForAndroidSourceDirFile = file(openSSLForAndroidSourceDir)
212-
if (!openSSLForAndroidSourceDirFile.exists()) {
213-
println("[@ottrelite/interop-otel] Cloning openssl_for_android to ${openSSLForAndroidSourceDir}...")
217+
// 1. Clean Git repo
218+
exec {
219+
workingDir openSSLForAndroidSourceDir
220+
commandLine "git", "reset", "--hard", "HEAD"
221+
}
222+
exec {
223+
workingDir openSSLForAndroidSourceDir
224+
commandLine "git", "clean", "-fd"
225+
}
214226

227+
// 2. Download & extract OpenSSL
228+
def openSSLForAndroidSourceDirFile = file(openSSLForAndroidSourceDir)
215229
if (!openSSLForAndroidSourceDirFile.exists()) {
216-
openSSLForAndroidSourceDirFile.mkdirs()
230+
println("[@ottrelite/interop-otel] Cloning openssl_for_android to ${openSSLForAndroidSourceDir}...")
217231

218-
exec {
219-
commandLine "git", "clone", "--depth", "1", "https://github.com/217heidai/openssl_for_android.git", openSSLForAndroidSourceDir
232+
if (!openSSLForAndroidSourceDirFile.exists()) {
233+
openSSLForAndroidSourceDirFile.mkdirs()
234+
235+
exec {
236+
commandLine "git", "clone", "--depth", "1", "https://github.com/217heidai/openssl_for_android.git", openSSLForAndroidSourceDir
237+
}
238+
} else {
239+
println("[@ottrelite/interop-otel] openssl_for_android already cloned in ${openSSLForAndroidSourceDir}")
220240
}
221-
} else {
222-
println("[@ottrelite/interop-otel] openssl_for_android already cloned in ${openSSLForAndroidSourceDir}")
223241
}
224-
}
225242

226-
if (!openSSLSourceDirFile.exists()) {
227-
openSSLSourceDirFile.mkdirs()
243+
if (!openSSLSourceDirFile.exists()) {
244+
openSSLSourceDirFile.mkdirs()
228245

229-
println("[@ottrelite/interop-otel] Downloading OpenSSL ${opensslVersion} to ${tarFile.path}...")
230-
new URL(opensslUrl).withInputStream { i ->
231-
tarFile.withOutputStream { it << i }
232-
}
246+
if (openSSLTarFile.exists()) {
247+
println("[@ottrelite/interop-otel] OpenSSL tarball already downloaded to ${openSSLTarFile.path}, skipping download.")
248+
}else{
249+
println("[@ottrelite/interop-otel] Downloading OpenSSL ${opensslVersion} to ${openSSLTarFile.path}...")
250+
new URL(opensslUrl).withInputStream { i ->
251+
openSSLTarFile.withOutputStream { it << i }
252+
}
253+
}
233254

234-
println("[@ottrelite/interop-otel] Extracting OpenSSL from ${tarFile.path} to ${openSSLSourceDir}...")
255+
println("[@ottrelite/interop-otel] Extracting OpenSSL from ${openSSLTarFile.path} to ${openSSLSourceDir}...")
235256

236-
copy {
237-
from tarTree(tarFile.path)
257+
copy {
258+
from tarTree(openSSLTarFile.path)
238259

239-
// below: actually, the script appends the openssl-${opensslVersion} directory by itself
240-
into openSSLSourceDirFile.parent
260+
// below: actually, the script appends the openssl-${opensslVersion} directory by itself
261+
into openSSLSourceDirFile.parent
262+
}
263+
} else {
264+
println("[@ottrelite/interop-otel] OpenSSL already extracted to ${openSSLSourceDir}")
241265
}
242-
} else {
243-
println("[@ottrelite/interop-otel] OpenSSL already extracted to ${openSSLSourceDir}")
244-
}
245-
246-
def symlinkTarget = new File(openSSLSourceDirFile.parent, "android-ndk-${android.ndkVersion}")
247-
if (!symlinkTarget.exists()) {
248-
println("[@ottrelite/interop-otel] Symlinking the Android NDK for openssl_for_android to ${openSSLSourceDirFile.parent}...")
249-
Files.createSymbolicLink(symlinkTarget.toPath(), android.ndkDirectory.toPath())
250-
} else {
251-
println("[@ottrelite/interop-otel] Symlink target ${symlinkTarget} already exists.")
252-
}
253-
}
254266

255-
doLast {
256-
reactNativeArchitectures().each { abi ->
257-
if (new File(getCmakeInstallDir(abi), "lib/libssl.a").exists()) {
258-
println("[@ottrelite/interop-otel] OpenSSL already built, skipping build.")
267+
def symlinkTarget = new File(openSSLSourceDirFile.parent, "android-ndk-${android.ndkVersion}")
268+
if (!symlinkTarget.exists()) {
269+
println("[@ottrelite/interop-otel] Symlinking the Android NDK for openssl_for_android to ${openSSLSourceDirFile.parent}...")
270+
Files.createSymbolicLink(symlinkTarget.toPath(), android.ndkDirectory.toPath())
259271
} else {
260-
exec {
261-
println("[@ottrelite/interop-otel] Building OpenSSL using openssl_for_android for ABI $abi from ${openSSLForAndroidSourceDir} and writing to source dir...")
272+
println("[@ottrelite/interop-otel] Symlink target ${symlinkTarget} already exists.")
273+
}
262274

263-
commandLine "bash", new File(openSSLForAndroidSourceDir, "openssl_build_new.sh").path,
264-
"${android.defaultConfig.minSdkVersion.apiLevel}",
265-
"$abi",
266-
"$opensslVersion",
267-
"$android.ndkVersion"
268-
}
275+
// 3. Build OpenSSL
276+
exec {
277+
commandLine "bash", new File(openSSLForAndroidSourceDir, "openssl_build_new.sh").path,
278+
"${android.defaultConfig.minSdkVersion.apiLevel}",
279+
"$abi",
280+
"$opensslVersion",
281+
"$android.ndkVersion"
269282
}
270-
}
271-
}
272-
}
273283

274-
tasks.register("copyOpenSSL") {
275-
doLast {
276-
reactNativeArchitectures().each { abi ->
284+
// 4. Copy built files to cmake install dir
277285
def openSSLForAndroidBuildDir = getOpenSSLForAndroidBuildDir(abi)
278-
def cmakeInstallDir = getCmakeInstallDir(abi)
279286

280287
println("[@ottrelite/interop-otel] Copying OpenSSL build artifacts for ABI $abi from ${openSSLForAndroidBuildDir} to ${cmakeInstallDir}...")
281288

@@ -291,9 +298,6 @@ tasks.register("copyOpenSSL") {
291298
}
292299
}
293300

294-
copyOpenSSL.mustRunAfter(buildOpenSSL)
295-
copyOpenSSL.dependsOn(buildOpenSSL)
296-
297301
tasks.register("buildAndInstallBrotli") {
298302
doFirst {
299303
if (!new File(brotliSourceDir, "CMakeLists.txt").exists()) {
@@ -508,8 +512,6 @@ tasks.register("buildAndInstallCURL") {
508512
}
509513
}
510514

511-
buildAndInstallCURL.dependsOn(copyOpenSSL)
512-
513515
// CPP wrapper + OTEL CPP SDK
514516
tasks.register("buildAndInstallCppWrapper") {
515517
doFirst {
@@ -573,7 +575,7 @@ tasks.register("buildAndInstallCppWrapper") {
573575
}
574576
}
575577

576-
buildAndInstallCppWrapper.dependsOn(copyOpenSSL)
578+
buildAndInstallCppWrapper.dependsOn(buildAndInstallOpenSSL)
577579
buildAndInstallCppWrapper.dependsOn(buildAndInstallBrotli)
578580
buildAndInstallCppWrapper.dependsOn(buildAndInstallZlib)
579581
buildAndInstallCppWrapper.dependsOn(buildAndInstallCURL)

0 commit comments

Comments
 (0)