Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit f5aa93c

Browse files
author
amablue
committed
Updated the setup script to allow the user to use a custom Firebase SDK instead
of always downloading it. PiperOrigin-RevId: 148164526
1 parent 68bcb1e commit f5aa93c

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

setup_firebase_sample.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
FEATURE_ARGS_ARRAY = []
6969
# The Firebase features supported by this script.
7070
FIREBASE_FEATURES_ARRAY = ["AdMob", "Analytics", "Invites", "Messaging"]
71+
# The path to the Firebase SDK to use. This is optional, if left blank the most
72+
# recent release will be downloaded and used.
73+
FIREBASE_SDK_PATH = None
7174

7275

7376
def add_cocos2dx_library():
@@ -118,7 +121,26 @@ def add_cocos2dx_library():
118121
logging.info("Finished adding the cocos2d-x library to the sample project.")
119122

120123

121-
def add_firebase_sdk():
124+
def copy_firebase_sdk():
125+
"""Copies the given version of the Firebase SDK to the sample project.
126+
127+
Raises:
128+
IOError: An error occurred copying the sdk to the target directory.
129+
"""
130+
logging.info("Copying the Firebase SDK...")
131+
try:
132+
shutil.copytree(FIREBASE_SDK_PATH, os.path.join(LIBS_DIR,
133+
"firebase_cpp_sdk"))
134+
except IOError as e:
135+
logging.exception("IOError: [Errno %d] %s: in %s", e.errno, e.strerror,
136+
sys._getframe().f_code.co_name)
137+
exit()
138+
logging.info(
139+
"Finished copying the Firebase SDK to the sample project's Libs "
140+
"directory")
141+
142+
143+
def retrieve_latest_firebase_sdk():
122144
"""Adds the latest version of the Firebase SDK to the sample project.
123145
124146
Raises:
@@ -341,12 +363,23 @@ def check_valid_arguments():
341363
nargs=1,
342364
help="The Firebase feature must be one of the following: "
343365
"AdMob, Analytics, Auth, Invites, Messaging, or Remote_Config")
366+
parser.add_argument(
367+
"--firebase_sdk",
368+
action='store',
369+
const=None,
370+
metavar="FIREBASE_SDK",
371+
help="The path to the directory containing the unzipped Firebase SDK. "
372+
"If left blank, the most recent release will be downloaded and used.")
344373
args = parser.parse_args()
345374
for feature in args.feature:
346375
feature_str = str(feature)
347376
if not feature_str in FIREBASE_FEATURES_ARRAY:
348377
return False
349378
FEATURE_ARGS_ARRAY.append(feature_str)
379+
380+
global FIREBASE_SDK_PATH
381+
FIREBASE_SDK_PATH = args.firebase_sdk
382+
350383
return True
351384

352385

@@ -372,7 +405,10 @@ def main():
372405
exit()
373406

374407
add_cocos2dx_library()
375-
add_firebase_sdk()
408+
if FIREBASE_SDK_PATH:
409+
copy_firebase_sdk()
410+
else:
411+
retrieve_latest_firebase_sdk()
376412
add_cpp_default_template()
377413
add_project_template_files()
378414
update_ios_project_file()

0 commit comments

Comments
 (0)