@@ -310,18 +310,49 @@ def print_value(value):
310
310
311
311
print (json .dumps (value ))
312
312
313
+ def scan_changes_in_file (parm_key , auto_diff , path , requested_api_list ):
314
+ """Scan for changes in the given file and return APIs that were modified."""
315
+ change_lines = subprocess .check_output (['git' , 'diff' , '-U0' , auto_diff , path ]).decode ('utf-8' ).rstrip ('\n ' ).split ('\n ' )
316
+ change_lines = [l for l in change_lines if l .startswith ('-' ) or l .startswith ('+' )]
317
+ change_lines = [l for l in change_lines if not l .startswith ('---' ) and not l .startswith ('+++' )]
318
+ change_lines = [l for l in change_lines if len (l ) > 20 ]
319
+ changed_apis = set ()
320
+ for line in change_lines :
321
+ if ("Google-Mobile-Ads" in line or "GoogleUserMessagingPlatform" in line or
322
+ "play-services-ads" in line or "user-messaging-platform" in line ):
323
+ changed_apis .add ("gma" )
324
+ else :
325
+ changed_apis .update (requested_api_list )
326
+ break
327
+ changed_apis .intersection_update (requested_api_list )
328
+ return "," .join (sorted (changed_apis )) if changed_apis else None
329
+
313
330
def filter_values_on_diff (parm_key , value , auto_diff ):
314
331
"""Filter the given key based on a branch diff.
315
332
316
333
Remove entries from the list based on what we observe in the
317
334
source tree, relative to the given base branch."""
318
335
file_list = set (subprocess .check_output (['git' , 'diff' , '--name-only' , auto_diff ]).decode ('utf-8' ).rstrip ('\n ' ).split ('\n ' ))
319
336
if parm_key == 'apis' :
337
+ file_redirects = {
338
+ # Custom handling for specific files, to be treated as a different path,
339
+ # ignored completely (set to None), or scan the changes more in-depth (set
340
+ # to scan_changes function)
341
+ "cmake/external/firestore.cmake" : "firestore" ,
342
+ "cmake/external/libuv.cmake" : "database" ,
343
+ "cmake/external/uWebSockets.cmake" : "database" ,
344
+ "ios_pod/Podfile" :scan_changes_in_file ,
345
+ "Android/firebase_dependencies.gradle" :scan_changes_in_file ,
346
+ "release_build_files/Android/firebase_dependencies.gradle" :scan_changes_in_file ,
347
+ }
320
348
custom_triggers = {
321
349
# Special handling for several top-level directories.
322
350
# Any top-level directories set to None are completely ignored.
323
351
"external" : None ,
324
352
"release_build_files" : None ,
353
+ # These two handled by file_redirects above.
354
+ "ios_pod" : None ,
355
+ "Android" : None ,
325
356
# Uncomment the two below lines when debugging this script, or GitHub
326
357
# actions related to auto-diff mode.
327
358
# ".github": None,
@@ -331,23 +362,21 @@ def filter_values_on_diff(parm_key, value, auto_diff):
331
362
# database, firestore, and storage.
332
363
"auth" : "auth,functions,database,firestore,storage" ,
333
364
}
334
- file_redirects = {
335
- # Custom handling for specific files, to be treated as a different path or
336
- # ignored completely (set to None).
337
- "cmake/external/firestore.cmake" : "firestore" ,
338
- "cmake/external/libuv.cmake" : "database" ,
339
- "cmake/external/uWebSockets.cmake" : "database" ,
340
- }
341
365
requested_api_list = set (value .split (',' ))
342
366
filtered_api_list = set ()
343
-
344
- for path in file_list :
367
+ file_list_array = list ( file_list )
368
+ for path in file_list_array :
345
369
if len (path ) == 0 : continue
346
370
if path in file_redirects :
347
371
if file_redirects [path ] is None :
348
372
continue
349
373
else :
350
- path = os .path .join (file_redirects [path ], path )
374
+ if callable (file_redirects [path ]):
375
+ add_paths = file_redirects [path ](parm_key , auto_diff , path , requested_api_list )
376
+ if add_paths : file_list_array .extend (add_paths .split ("," ))
377
+ continue
378
+ else :
379
+ path = os .path .join (file_redirects [path ], path )
351
380
topdir = path .split (os .path .sep )[0 ]
352
381
if topdir in custom_triggers :
353
382
if not custom_triggers [topdir ]: continue # Skip ones set to None.
@@ -361,7 +390,7 @@ def filter_values_on_diff(parm_key, value, auto_diff):
361
390
sys .stderr .write ("Path '%s' is outside known directories, defaulting to all APIs: %s\n " % (path , value ))
362
391
return value
363
392
sys .stderr .write ("::warning::Autodetected APIs: %s\n " % ',' .join (sorted (filtered_api_list )))
364
- return ',' .join (sorted (filtered_api_list ))
393
+ return ',' .join (sorted (filtered_api_list if filtered_api_list else requested_api_list ))
365
394
elif parm_key == 'platform' :
366
395
# Quick and dirty check:
367
396
# For each file:
0 commit comments