Skip to content

Commit e956c57

Browse files
committed
Change APP_BINARY_DIR to instead scan for the directory.
1 parent 4fafe16 commit e956c57

File tree

9 files changed

+46
-14
lines changed

9 files changed

+46
-14
lines changed

CMakeLists.txt

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ endif()
180180
# Set directories needed by the Firebase subprojects
181181
# Directory to store generated files.
182182
set(FIREBASE_GEN_FILE_DIR ${CMAKE_BINARY_DIR}/generated)
183+
183184
# Directory for any shared scripts.
184185
set(FIREBASE_SCRIPT_DIR ${CMAKE_CURRENT_LIST_DIR})
185186

@@ -227,20 +228,34 @@ set(FIRESTORE_INCLUDE_OBJC OFF CACHE BOOL "Disabled for the CPP SDK")
227228
set(RE2_BUILD_TESTING OFF CACHE BOOL "")
228229

229230
if(FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD)
230-
# Quote meta characters in ${CMAKE_CURRENT_LIST_DIR} so we can
231-
# match it in a regex.
232-
# For example, '/path/with/+meta/char.acters' will become
233-
# '/path/with/\+meta/char\.acters'.
234-
string(REGEX REPLACE
235-
"([][+.*()^])" "\\\\\\1" # Yes, this many \'s is correct.
236-
current_list_dir_regex
237-
"${CMAKE_CURRENT_LIST_DIR}")
238-
# Figure out where app's binary_dir was.
239-
string(REGEX REPLACE
240-
"${current_list_dir_regex}/[^/]+/(.*)"
241-
"${CMAKE_CURRENT_LIST_DIR}/app/\\1"
242-
APP_BINARY_DIR "${FIREBASE_BINARY_DIR}")
243-
231+
# Gradle now adds a random hash to each separate NDK cmake build.
232+
# Scan the previously built directories to find the one containing app's header.
233+
set(header_to_scan_for "generated/app/src/include/firebase/version.h")
234+
set(prev_build_path "${CMAKE_BINARY_DIR}/../../../../../app/.cxx/${CMAKE_BUILD_TYPE}/*/${CMAKE_ANDROID_ARCH_ABI}")
235+
file(GLOB possible_prev_build_dirs "${prev_build_path}")
236+
# In case there are multiple matches, take the one with the newest timestamp.
237+
set(newest_timestamp 0)
238+
foreach(possible_prev_build_dir IN LISTS possible_prev_build_dirs)
239+
message("CONSIDERING ${possible_prev_build_dir}")
240+
if(IS_DIRECTORY ${possible_prev_build_dir})
241+
if(EXISTS "${possible_prev_build_dir}/${header_to_scan_for}")
242+
# Check if it's newer than any other files.
243+
message("FOUND ${possible_prev_build_dir}/${header_to_scan_for}")
244+
file(TIMESTAMP "${possible_prev_build_dir}/${header_to_scan_for}" timestamp "%s")
245+
message("GOT TIMESTAMP: ${timestamp}")
246+
if(${timestamp} GREATER ${newest_timestamp})
247+
message("USING ${possible_prev_build_dir}")
248+
set(APP_BINARY_DIR ${possible_prev_build_dir})
249+
set(newest_timestamp ${timestamp})
250+
endif()
251+
endif()
252+
endif()
253+
endforeach()
254+
if (IS_DIRECTORY "${APP_BINARY_DIR}")
255+
message("Found previous Firebase App build in ${APP_BINARY_DIR}")
256+
else()
257+
message(FATAL_ERROR "Could not find previous Firebase App build under ${prev_build_path}")
258+
endif()
244259
set(FIRESTORE_SOURCE_DIR ${APP_BINARY_DIR}/external/src/firestore)
245260
else()
246261
# Run the CMake build logic that will download all the external dependencies.
@@ -579,6 +594,7 @@ if(NOT FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD)
579594
else()
580595
# Add firebase_app as a target on the previously built app.
581596
add_library(firebase_app STATIC IMPORTED GLOBAL)
597+
582598
file(MAKE_DIRECTORY "${APP_BINARY_DIR}/generated")
583599
file(MAKE_DIRECTORY "${FIREBASE_BINARY_DIR}/generated")
584600
set(app_include_dirs

analytics/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
# Analytics generates header files for default events, parameters, and
1818
# properties based on the iOS SDK, that are used across all platforms.
19+
1920
set(analytics_generated_headers_dir
2021
"${FIREBASE_GEN_FILE_DIR}/analytics/src/include/firebase/analytics")
2122
set(event_names_header "${analytics_generated_headers_dir}/event_names.h")

analytics/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,5 @@ apply from: "$rootDir/android_build_files/extract_and_dex.gradle"
8585
apply from: "$rootDir/android_build_files/generate_proguard.gradle"
8686
project.afterEvaluate {
8787
generateProguardFile('analytics')
88+
preBuild.dependsOn(':app:build')
8889
}

functions/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,6 @@ apply from: "$rootDir/android_build_files/android_abis.gradle"
8484
apply from: "$rootDir/android_build_files/generate_proguard.gradle"
8585
project.afterEvaluate {
8686
generateProguardFile('functions')
87+
preDebugBuild.dependsOn(':app:externalNativeBuildDebug')
88+
preReleaseBuild.dependsOn(':app:externalNativeBuildRelease')
8789
}

gma/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,6 @@ apply from: "$rootDir/android_build_files/generate_proguard.gradle"
8686
project.afterEvaluate {
8787
generateProguardFile('gma')
8888
setupDexDependencies(':gma:gma_resources')
89+
preDebugBuild.dependsOn(':app:externalNativeBuildDebug')
90+
preReleaseBuild.dependsOn(':app:externalNativeBuildRelease')
8991
}

installations/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,6 @@ apply from: "$rootDir/android_build_files/android_abis.gradle"
8484
apply from: "$rootDir/android_build_files/generate_proguard.gradle"
8585
project.afterEvaluate {
8686
generateProguardFile('installations')
87+
preDebugBuild.dependsOn(':app:externalNativeBuildDebug')
88+
preReleaseBuild.dependsOn(':app:externalNativeBuildRelease')
8789
}

messaging/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,6 @@ apply from: "$rootDir/android_build_files/extract_and_dex.gradle"
8686
apply from: "$rootDir/android_build_files/generate_proguard.gradle"
8787
project.afterEvaluate {
8888
generateProguardFile('messaging')
89+
preDebugBuild.dependsOn(':app:externalNativeBuildDebug')
90+
preReleaseBuild.dependsOn(':app:externalNativeBuildRelease')
8991
}

remote_config/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,6 @@ apply from: "$rootDir/android_build_files/generate_proguard.gradle"
8686
project.afterEvaluate {
8787
generateProguardFile('remote_config')
8888
setupDexDependencies(':remote_config:remote_config_resources')
89+
preDebugBuild.dependsOn(':app:externalNativeBuildDebug')
90+
preReleaseBuild.dependsOn(':app:externalNativeBuildRelease')
8991
}

storage/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,8 @@ apply from: "$rootDir/android_build_files/generate_proguard.gradle"
8686
project.afterEvaluate {
8787
generateProguardFile('storage')
8888
setupDexDependencies(':storage:storage_resources')
89+
preDebugBuild.dependsOn(':app:externalNativeBuildDebug')
90+
preReleaseBuild.dependsOn(':app:externalNativeBuildRelease')
91+
preDebugBuild.dependsOn(':auth:externalNativeBuildDebug')
92+
preReleaseBuild.dependsOn(':auth:externalNativeBuildRelease')
8993
}

0 commit comments

Comments
 (0)