39
39
from absl import flags
40
40
from absl import logging
41
41
42
+
43
+ SUPPORT_TARGETS = [
44
+ "analytics" , "auth" , "crashlytics" , "database" , "dynamic_links" ,
45
+ "firestore" , "functions" , "installations" , "messaging" , "remote_config" ,
46
+ "storage"
47
+ ]
48
+
42
49
FLAGS = flags .FLAGS
43
50
flags .DEFINE_string ('zip_dir' , None ,
44
51
'Directory of zip files from build output to package' )
45
52
flags .DEFINE_string ("config_file" , "exports.json" ,
46
- ("Config file that describes how to "
47
- "pack the unity assets." ))
53
+ ("Config file that describes how to pack the unity assets." ))
48
54
flags .DEFINE_string ("guids_file" , "guids.json" ,
49
55
"Json file with stable guids cache." )
50
56
55
61
"Output folder for unitypackage." )
56
62
57
63
flags .DEFINE_boolean ("output_upm" , False , "Whether output packages as tgz for"
58
- "Unity Package Manager." )
64
+ "Unity Package Manager." )
65
+
66
+ flags .DEFINE_string ("apis" , None , "which firebase products to pack, if not"
67
+ "set means package all. Value should be items in [{}],"
68
+ "connected with ',', eg 'auth,firestore'" .format (
69
+ "," .join (SUPPORT_TARGETS )))
70
+
59
71
60
72
def get_zip_files ():
61
73
"""Get all zip files from FLAGS.zip_dir.
@@ -75,12 +87,14 @@ def get_zip_files():
75
87
76
88
return zip_file_paths
77
89
90
+
78
91
def get_last_version ():
79
92
"""Get the last version number in guids file if exists.
80
93
Returns:
81
94
version number.
82
95
"""
83
- version_cmake_path = os .path .join (os .getcwd (), "cmake" , "firebase_unity_version.cmake" )
96
+ version_cmake_path = os .path .join (
97
+ os .getcwd (), "cmake" , "firebase_unity_version.cmake" )
84
98
with open (version_cmake_path , "r" ) as f :
85
99
datafile = f .readlines ()
86
100
for line in datafile :
@@ -89,45 +103,68 @@ def get_last_version():
89
103
return result [- 1 ].strip ("\" " )
90
104
return None
91
105
106
+
92
107
def find_pack_script ():
93
108
"""Get the pack script either from intermediate build folder or download from unity-jar-resolver.
94
109
95
110
Returns:
96
111
path of the pack script. None if not found.
97
112
"""
98
113
built_folder_ext = "_unity"
99
- built_folder_postion = os .path .join ("external" , "src" , "google_unity_jar_resolver" )
114
+ built_folder_postion = os .path .join (
115
+ "external" , "src" , "google_unity_jar_resolver" )
100
116
built_folder = None
101
117
resolver_root_folder = "unity-jar-resolver"
102
118
for folder in os .listdir ("." ):
103
119
if folder .endswith (built_folder_ext ):
104
120
built_folder = folder
105
121
break
106
-
122
+
107
123
if built_folder != None :
108
124
resolver_root_folder = os .path .join (built_folder , built_folder_postion )
109
125
elif not os .path .exists (resolver_root_folder ):
110
126
git_clone_script = ["git" , "clone" ,
111
- "--depth" , "1" ,
112
- "https://github.com/googlesamples/unity-jar-resolver.git" ]
127
+ "--depth" , "1" ,
128
+ "https://github.com/googlesamples/unity-jar-resolver.git" ]
113
129
subprocess .call (git_clone_script )
114
130
115
131
if resolver_root_folder != None :
116
- script_path = os .path .join (resolver_root_folder , "source" , "ExportUnityPackage" , "export_unity_package.py" )
132
+ script_path = os .path .join (
133
+ resolver_root_folder , "source" , "ExportUnityPackage" , "export_unity_package.py" )
117
134
return script_path
118
135
return None
119
136
137
+
138
+ def _debug_create_target_package (target , packer_script_path , guids_file_path , output_folder , zip_file_list , last_version ):
139
+ debug_config_path = os .path .join (os .getcwd (), FLAGS .script_folder , "debug_single_export_json" ,
140
+ target + ".json" )
141
+ debug_cmd_args = [
142
+ sys .executable ,
143
+ packer_script_path ,
144
+ "--assets_dir=" + FLAGS .zip_dir ,
145
+ "--config_file=" + debug_config_path ,
146
+ "--guids_file=" + guids_file_path ,
147
+ "--output_dir=" + output_folder ,
148
+ "--output_upm=False" ,
149
+ ]
150
+ debug_cmd_args .extend (
151
+ ["--assets_zip=" + zip_file for zip_file in zip_file_list ])
152
+ debug_cmd_args .append ("--enabled_sections=build_dotnet4 asset_package_only" )
153
+ debug_cmd_args .append ("--plugins_version=" + last_version )
154
+ subprocess .call (debug_cmd_args )
155
+ logging .info ("Debug Packaging done for target %s" , target )
156
+
157
+
120
158
def main (argv ):
121
159
if len (argv ) > 1 :
122
160
raise app .UsageError ('Too many command-line arguments.' )
123
161
124
162
packer_script_path = find_pack_script ()
125
163
if packer_script_path == None :
126
- raise app .UsageError ('Cannot find pack script. Please build the project first.' )
127
-
164
+ raise app .UsageError (
165
+ 'Cannot find pack script. Please build the project first.' )
166
+
128
167
packer_script_path = os .path .join (os .getcwd (), packer_script_path )
129
- config_file_path = os .path .join (os .getcwd (), FLAGS .script_folder ,
130
- FLAGS .config_file )
131
168
guids_file_path = os .path .join (os .getcwd (), FLAGS .script_folder ,
132
169
FLAGS .guids_file )
133
170
@@ -141,6 +178,21 @@ def main(argv):
141
178
if os .path .exists (output_folder ):
142
179
shutil .rmtree (output_folder )
143
180
181
+ if FLAGS .apis :
182
+ # If told to only build a subset, package just those products and exit early.
183
+ api_list = FLAGS .apis .split ("," )
184
+ if not set (api_list ).issubset (set (SUPPORT_TARGETS )):
185
+ raise app .UsageError ("apis parameter error, Value should be items in [{}],"
186
+ "connected with ',', eg 'auth,firestore'" .format (
187
+ "," .join (SUPPORT_TARGETS )))
188
+
189
+ for target in api_list :
190
+ _debug_create_target_package (
191
+ target , packer_script_path , guids_file_path , output_folder , zip_file_list , last_version )
192
+ return
193
+
194
+ config_file_path = os .path .join (os .getcwd (), FLAGS .script_folder ,
195
+ FLAGS .config_file )
144
196
cmd_args = [
145
197
sys .executable ,
146
198
packer_script_path ,
@@ -151,16 +203,17 @@ def main(argv):
151
203
"--output_upm=" + str (FLAGS .output_upm ),
152
204
]
153
205
cmd_args .extend (["--assets_zip=" + zip_file for zip_file in zip_file_list ])
154
-
206
+
155
207
if last_version :
156
208
cmd_args .append ("--plugins_version=" + last_version )
157
209
158
210
if FLAGS .output_upm :
159
211
cmd_args .append ("--enabled_sections=build_dotnet4" )
160
212
cmd_args .append ("--output_unitypackage=False" )
161
213
else :
162
- cmd_args .append ("--enabled_sections=build_dotnet3 build_dotnet4 asset_package_only" )
163
-
214
+ cmd_args .append (
215
+ "--enabled_sections=build_dotnet3 build_dotnet4 asset_package_only" )
216
+
164
217
# Check if need to gen new guids
165
218
p = subprocess .Popen (cmd_args , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
166
219
output , error = p .communicate ()
@@ -170,28 +223,30 @@ def main(argv):
170
223
error_str = error_str .split ("assets:" )[- 1 ]
171
224
error_str = error_str .rstrip ("\\ n\' " )
172
225
split_string = error_str .split (" " )
173
- split_string = split_string [3 :] # exclude first 3 lines
174
- gen_guids_script_path = os .path .join (os .getcwd (), "scripts" , "build_scripts" , "gen_guids.py" )
226
+ split_string = split_string [3 :] # exclude first 3 lines
227
+ gen_guids_script_path = os .path .join (
228
+ os .getcwd (), "scripts" , "build_scripts" , "gen_guids.py" )
175
229
gen_cmd_args = [
176
- sys .executable ,
177
- gen_guids_script_path ,
178
- "--guids_file=" + guids_file_path ,
179
- "--version=" + last_version ,
180
- "--generate_new_guids=True" ,
230
+ sys .executable ,
231
+ gen_guids_script_path ,
232
+ "--guids_file=" + guids_file_path ,
233
+ "--version=" + last_version ,
234
+ "--generate_new_guids=True" ,
181
235
]
182
236
for file in split_string :
183
- file = file .strip ("\" " )
237
+ file = file .strip ("\" " )
184
238
print (file )
185
239
gen_cmd_args .append (file )
186
240
subprocess .call (gen_cmd_args )
187
241
188
242
# Need to package again if has that error
189
- subprocess .call (cmd_args )
243
+ subprocess .call (cmd_args )
190
244
else :
191
245
logging .info ("No new guid generated." )
192
246
error_list = str (error ).split ("\\ n" )
193
247
logging .info ("\n " .join (error_list ))
194
248
logging .info ("Packaging done for version %s" , last_version )
195
249
250
+
196
251
if __name__ == '__main__' :
197
252
app .run (main )
0 commit comments