69
69
import datetime
70
70
from distutils import dir_util
71
71
import os
72
- import pathlib
73
72
import platform
74
73
import shutil
75
74
import subprocess
81
80
import attr
82
81
83
82
from integration_testing import config_reader
84
- from integration_testing import provisioning
83
+ from integration_testing import test_validation
85
84
from integration_testing import xcodebuild
86
85
87
86
# Environment variables
145
144
" the local spec repos available on this machine. Must also include iOS"
146
145
" in platforms flag." )
147
146
148
- flags .DEFINE_bool (
149
- "execute_desktop_testapp" , True ,
150
- "(Desktop only) Run the testapp after building it. Will return non-zero"
151
- " code if any tests fail inside the testapp." )
152
-
153
147
flags .DEFINE_string (
154
148
"compiler" , None ,
155
149
"(Desktop only) Specify the compiler with CMake during the testapps build."
@@ -187,6 +181,7 @@ def main(argv):
187
181
timestamp = datetime .datetime .now ().strftime ("%Y_%m_%d-%H_%M_%S" )
188
182
else :
189
183
timestamp = ""
184
+ output_dir = os .path .join (output_dir , "testapps" + timestamp )
190
185
191
186
ios_framework_dir = os .path .join (sdk_dir , "frameworks" )
192
187
ios_framework_exist = os .path .isdir (ios_framework_dir )
@@ -195,7 +190,7 @@ def main(argv):
195
190
196
191
if update_pod_repo and _IOS in platforms :
197
192
_run (["pod" , "repo" , "update" ])
198
-
193
+
199
194
config = config_reader .read_config ()
200
195
cmake_flags = _get_desktop_compiler_flags (FLAGS .compiler , config .compilers )
201
196
if _DESKTOP in platforms and FLAGS .use_vcpkg :
@@ -214,25 +209,22 @@ def main(argv):
214
209
output_dir = output_dir ,
215
210
sdk_dir = sdk_dir ,
216
211
ios_framework_exist = ios_framework_exist ,
217
- timestamp = timestamp ,
218
212
root_dir = root_dir ,
219
213
ios_sdk = FLAGS .ios_sdk ,
220
- cmake_flags = cmake_flags ,
221
- execute_desktop_testapp = FLAGS .execute_desktop_testapp )
214
+ cmake_flags = cmake_flags )
222
215
logging .info ("END building for %s" , testapp )
223
216
224
- _summarize_results (testapps , platforms , failures )
217
+ _summarize_results (testapps , platforms , failures , output_dir )
225
218
return 1 if failures else 0
226
219
227
220
228
221
def _build (
229
- testapp , platforms , api_config , output_dir , sdk_dir , ios_framework_exist ,
230
- timestamp , root_dir , ios_sdk , cmake_flags , execute_desktop_testapp ):
222
+ testapp , platforms , api_config , output_dir , sdk_dir , ios_framework_exist ,
223
+ root_dir , ios_sdk , cmake_flags ):
231
224
"""Builds one testapp on each of the specified platforms."""
232
225
testapp_dir = os .path .join (root_dir , api_config .testapp_path )
233
226
project_dir = os .path .join (
234
- output_dir , "testapps" + timestamp , api_config .full_name ,
235
- os .path .basename (testapp_dir ))
227
+ output_dir , api_config .full_name , os .path .basename (testapp_dir ))
236
228
237
229
logging .info ("Copying testapp project to %s" , project_dir )
238
230
os .makedirs (project_dir )
@@ -249,8 +241,6 @@ def _build(
249
241
logging .info ("BEGIN %s, %s" , testapp , _DESKTOP )
250
242
try :
251
243
_build_desktop (sdk_dir , cmake_flags )
252
- if execute_desktop_testapp :
253
- _execute_desktop_testapp (project_dir )
254
244
except subprocess .SubprocessError as e :
255
245
failures .append (
256
246
Failure (testapp = testapp , platform = _DESKTOP , error_message = str (e )))
@@ -287,36 +277,30 @@ def _build(
287
277
return failures
288
278
289
279
290
- def _summarize_results (testapps , platforms , failures ):
280
+ def _summarize_results (testapps , platforms , failures , output_dir ):
291
281
"""Logs a readable summary of the results of the build."""
292
- logging . info (
293
- "FINISHED BUILDING TESTAPPS. \n \n \n "
294
- "Tried to build these testapps: %s \n "
295
- "On these platforms: %s" ,
296
- ", " . join ( testapps ), ", " . join ( platforms ))
282
+ summary = []
283
+ summary . append ( "BUILD SUMMARY:" )
284
+ summary . append ( "TRIED TO BUILD: " + "," . join ( testapps ))
285
+ summary . append ( "ON PLATFORMS: " + "," . join ( platforms ))
286
+
297
287
if not failures :
298
- logging . info ( "No failures occurred " )
288
+ summary . append ( "ALL BUILDS SUCCEEDED " )
299
289
else :
300
- # Collect lines, then log once, to reduce logging noise from timestamps etc.
301
- lines = ["Some failures occurred:" ]
290
+ summary .append ("SOME FAILURES OCCURRED:" )
302
291
for i , failure in enumerate (failures , start = 1 ):
303
- lines .append ("%d: %s" % (i , failure .describe ()))
304
- logging .info ("\n " .join (lines ))
292
+ summary .append ("%d: %s" % (i , failure .describe ()))
293
+ summary = "\n " .join (summary )
294
+
295
+ logging .info (summary )
296
+ test_validation .write_summary (output_dir , summary )
305
297
306
298
307
299
def _build_desktop (sdk_dir , cmake_flags ):
308
300
_run (["cmake" , "." , "-DFIREBASE_CPP_SDK_DIR=" + sdk_dir ] + cmake_flags )
309
301
_run (["cmake" , "--build" , "." ])
310
302
311
303
312
- def _execute_desktop_testapp (project_dir ):
313
- if platform .system () == "Windows" :
314
- testapp_path = os .path .join (project_dir , "Debug" , "integration_test.exe" )
315
- else :
316
- testapp_path = os .path .join (project_dir , "integration_test" )
317
- _run ([testapp_path ], timeout = 300 )
318
-
319
-
320
304
def _get_desktop_compiler_flags (compiler , compiler_table ):
321
305
"""Returns the command line flags for this compiler."""
322
306
if not compiler : # None is an acceptable default value
@@ -362,31 +346,45 @@ def _validate_android_environment_variables():
362
346
"""Checks environment variables that may be required for Android."""
363
347
# Ultimately we let the gradle build be the source of truth on what env vars
364
348
# are required, but try to repair holes and log warnings if we can't.
365
- logging .info ("Checking environment variables for the Android build" )
366
- if not os .environ .get (_ANDROID_NDK_HOME ):
367
- ndk_root = os .environ .get (_NDK_ROOT )
368
- if ndk_root : # Use NDK_ROOT as a backup for ANDROID_NDK_HOME
369
- os .environ [_ANDROID_NDK_HOME ] = ndk_root
370
- logging .info ("%s not found, using %s" , _ANDROID_NDK_HOME , _NDK_ROOT )
371
- else :
372
- logging .warning ("Neither %s nor %s is set." , _ANDROID_NDK_HOME , _NDK_ROOT )
349
+ android_home = os .environ .get (_ANDROID_HOME )
373
350
if not os .environ .get (_JAVA_HOME ):
374
351
logging .warning ("%s not set" , _JAVA_HOME )
375
352
if not os .environ .get (_ANDROID_SDK_HOME ):
376
- android_home = os .environ .get (_ANDROID_HOME )
377
353
if android_home : # Use ANDROID_HOME as backup for ANDROID_SDK_HOME
378
354
os .environ [_ANDROID_SDK_HOME ] = android_home
379
355
logging .info ("%s not found, using %s" , _ANDROID_SDK_HOME , _ANDROID_HOME )
380
356
else :
381
- logging .warning (
382
- "Neither %s nor %s is set" , _ANDROID_SDK_HOME , _ANDROID_HOME )
357
+ logging .warning ("Missing: %s and %s" , _ANDROID_SDK_HOME , _ANDROID_HOME )
358
+ # Different environments may have different NDK env vars specified. We look
359
+ # for these, in this order, and set the others to the first found.
360
+ # If none are set, we check the default location for the ndk.
361
+ ndk_path = None
362
+ ndk_vars = [_NDK_ROOT , _ANDROID_NDK_HOME ]
363
+ for env_var in ndk_vars :
364
+ val = os .environ .get (env_var )
365
+ if val :
366
+ ndk_path = val
367
+ break
368
+ if not ndk_path :
369
+ if android_home :
370
+ default_ndk_path = os .path .join (android_home , "ndk-bundle" )
371
+ if os .path .isdir (default_ndk_path ):
372
+ ndk_path = default_ndk_path
373
+ if ndk_path :
374
+ logging .info ("Found ndk: %s" , ndk_path )
375
+ for env_var in ndk_vars :
376
+ if os .environ .get (env_var ) != ndk_path :
377
+ logging .info ("Setting %s to %s" , env_var , ndk_path )
378
+ os .environ [env_var ] = ndk_path
379
+ else :
380
+ logging .warning ("No NDK env var set. Set one of %s" , ", " .join (ndk_vars ))
383
381
384
382
385
- # If sdk_dir contains no framework, consider it is Github repo, then
383
+ # If sdk_dir contains no framework, consider it is Github repo, then
386
384
# generate makefiles for ios frameworks
387
385
def _generate_makefiles_from_repo (sdk_dir ):
388
386
ios_framework_builder = os .path .join (
389
- sdk_dir , "build_scripts" , "ios" , "build.sh" )
387
+ sdk_dir , "build_scripts" , "ios" , "build.sh" )
390
388
391
389
framework_builder_args = [
392
390
ios_framework_builder ,
@@ -400,15 +398,15 @@ def _generate_makefiles_from_repo(sdk_dir):
400
398
# build required ios frameworks based on makefiles
401
399
def _build_ios_framework_from_repo (sdk_dir , api_config ):
402
400
ios_framework_builder = os .path .join (
403
- sdk_dir , "build_scripts" , "ios" , "build.sh" )
404
-
401
+ sdk_dir , "build_scripts" , "ios" , "build.sh" )
402
+
405
403
# build only required targets to save time
406
404
target = set ()
407
405
for framework in api_config .frameworks :
408
406
target .add (os .path .splitext (framework )[0 ])
409
407
# firebase is not a target in CMake, firebase_app is the target
410
- # firebase_app will be built by other target as well
411
- target .remove ("firebase" )
408
+ # firebase_app will be built by other target as well
409
+ target .remove ("firebase" )
412
410
413
411
framework_builder_args = [
414
412
ios_framework_builder ,
@@ -421,10 +419,10 @@ def _build_ios_framework_from_repo(sdk_dir, api_config):
421
419
422
420
def _build_ios (
423
421
sdk_dir , ios_framework_exist , project_dir , root_dir , api_config , ios_sdk ):
422
+ """Builds an iOS application (.app, .ipa or both)."""
424
423
if not ios_framework_exist :
425
424
_build_ios_framework_from_repo (sdk_dir , api_config )
426
425
427
- """Builds an iOS application (.app, .ipa or both)."""
428
426
build_dir = os .path .join (project_dir , "ios_build" )
429
427
os .makedirs (build_dir )
430
428
@@ -439,14 +437,10 @@ def _build_ios(
439
437
440
438
podfile_tool_path = os .path .join (
441
439
root_dir , "scripts" , "gha" , "integration_testing" , "update_podfile.py" )
442
- sdk_podfile_path = os .path .join (
443
- root_dir , "ios_pod" , "Podfile" )
444
- app_podfile_path = os .path .join (
445
- project_dir , "Podfile" )
446
440
podfile_patcher_args = [
447
441
"python" , podfile_tool_path ,
448
- "--sdk_podfile" , sdk_podfile_path ,
449
- "--app_podfile" , app_podfile_path
442
+ "--sdk_podfile" , os . path . join ( root_dir , "ios_pod" , "Podfile" ) ,
443
+ "--app_podfile" , os . path . join ( project_dir , "Podfile" )
450
444
]
451
445
_run (podfile_patcher_args )
452
446
_run (["pod" , "install" ])
@@ -487,7 +481,8 @@ def _build_ios(
487
481
ios_sdk = _IOS_SDK_DEVICE ,
488
482
configuration = "Debug" ))
489
483
490
- xcodebuild .generate_unsigned_ipa (output_dir = build_dir , configuration = "Debug" )
484
+ xcodebuild .generate_unsigned_ipa (
485
+ output_dir = build_dir , configuration = "Debug" )
491
486
492
487
493
488
# This script is responsible for copying shared files into the integration
0 commit comments