1212
1313
1414def main ():
15- parser = argparse .ArgumentParser (
16- description = "Build and check the API compatibility."
17- )
15+ parser = argparse .ArgumentParser (description = "Build and check the API compatibility." )
1816
1917 subparsers = parser .add_subparsers (dest = "command" )
2018
@@ -38,9 +36,7 @@ def main():
3836 help = "Path to the Maps SDK release zip archive." ,
3937 )
4038 dumpSDKParser .add_argument ("--module" , help = "Name of the module to dump." )
41- dumpSDKParser .add_argument (
42- "--triplet-target" , help = "Clang target triplet like 'arm64-apple-ios11.0'"
43- )
39+ dumpSDKParser .add_argument ("--triplet-target" , help = "Clang target triplet like 'arm64-apple-ios11.0'" )
4440 dumpSDKParser .add_argument (
4541 "--abi" ,
4642 default = False ,
@@ -88,9 +84,7 @@ def main():
8884 args = parser .parse_args ()
8985
9086 if args .command == "dump" :
91- dump_sdk (
92- args .sdk_path , args .output_path , args .abi , args .module , args .triplet_target
93- )
87+ dump_sdk (args .sdk_path , args .output_path , args .abi , args .module , args .triplet_target )
9488 elif args .command == "check-api" :
9589 check_api_breaking_changes (
9690 args .base_dump ,
@@ -129,25 +123,19 @@ def dittoSDK(sdk_path, destination):
129123 # Support raw folder of swiftmodule files like the one in DerivedData.
130124 return sdk_path
131125 else :
132- raise Exception (
133- "SDK path must contain a zip archive, XCFrameworks or a folder of swiftmodule files"
134- )
126+ raise Exception ("SDK path must contain a zip archive, XCFrameworks or a folder of swiftmodule files" )
135127
136128 def detect_module_name (sdk_path : str , frameworks_root : str ) -> str :
137129 if os .path .splitext (sdk_path )[1 ] == ".zip" :
138- modules = [
139- f for f in os .listdir (frameworks_root ) if f .endswith (".xcframework" )
140- ]
130+ modules = [f for f in os .listdir (frameworks_root ) if f .endswith (".xcframework" )]
141131 if len (modules ) != 1 :
142132 raise Exception (f"Could not detect module name from { sdk_path } " )
143133 else :
144134 return modules [0 ].split ("." )[0 ]
145135 elif os .path .splitext (sdk_path )[1 ] == ".xcframework" :
146136 return os .path .splitext (os .path .basename (sdk_path ))[0 ]
147137 else :
148- raise Exception (
149- "Cannot detect module name from SDK path. Please specify the module name with --module"
150- )
138+ raise Exception ("Cannot detect module name from SDK path. Please specify the module name with --module" )
151139
152140 frameworks_root = dittoSDK (sdk_path , tempDir )
153141 if module_name is None :
@@ -164,18 +152,14 @@ def detect_module_name(sdk_path: str, frameworks_root: str) -> str:
164152 if os .path .exists (xcframework_path ):
165153 current_xcframework = XCFramework (xcframework_path )
166154
167- digester .dump_sdk_xcframework (
168- current_xcframework , frameworks_root , output_path , abi
169- )
155+ digester .dump_sdk_xcframework (current_xcframework , frameworks_root , output_path , abi )
170156 else :
171157 # We are in the DerivedData folder.
172158 if triplet_target is None :
173159 raise Exception (
174160 "Please specify the triplet target with --triplet-target. That option is required when dumping from modules folder."
175161 )
176- digester .dump_sdk (
177- frameworks_root , module_name , triplet_target , output_path , abi
178- )
162+ digester .dump_sdk (frameworks_root , module_name , triplet_target , output_path , abi )
179163
180164
181165def check_api_breaking_changes (
@@ -187,9 +171,7 @@ def check_api_breaking_changes(
187171):
188172 tool = APIDigester ()
189173
190- report = tool .compare (
191- baseline_dump_path , latest_dump_path , report_path , breakage_allow_list_path
192- )
174+ report = tool .compare (baseline_dump_path , latest_dump_path , report_path , breakage_allow_list_path )
193175
194176 if should_comment_pr :
195177 add_comment_to_pr (report )
@@ -218,7 +200,11 @@ def findApiReportComment(comments):
218200 if comments is None :
219201 return None
220202 for comment in comments :
221- if "API compatibility report" in comment ["body" ] and comment ["performed_via_github_app" ] is not None and comment ["performed_via_github_app" ]["owner" ]["login" ] == "mapbox" :
203+ if (
204+ "API compatibility report" in comment ["body" ]
205+ and comment ["performed_via_github_app" ] is not None
206+ and comment ["performed_via_github_app" ]["owner" ]["login" ] == "mapbox"
207+ ):
222208 return comment
223209 return None
224210
@@ -233,6 +219,7 @@ def findApiReportComment(comments):
233219 else :
234220 helper .updateCommentToPR (apiReportComment ["id" ], report .reportComment ())
235221
222+
236223class GHHelper :
237224 def __init__ (self ):
238225 pass
@@ -246,28 +233,38 @@ def findPRNumber(self):
246233 return proc .stdout .rstrip ()
247234
248235 def findPRComments (self , prNumber ):
249- proc = subprocess .run (["gh" , "api" , "repos/{owner}/{repo}/issues" + f"/{ prNumber } /comments" ], capture_output = True , text = True )
236+ proc = subprocess .run (
237+ ["gh" , "api" , "repos/{owner}/{repo}/issues" + f"/{ prNumber } /comments" ], capture_output = True , text = True
238+ )
250239 if proc .returncode != 0 :
251240 print (f"Failed to find PR comments. Error: { proc .stderr } " )
252241 return None
253242 return json .loads (proc .stdout )
254243
255244 def addCommentToPR (self , prNumber , body ):
256- proc = subprocess .run (["gh" , "api" , "repos/{owner}/{repo}/issues" + f"/{ prNumber } /comments" , "-f" , f"body={ body } " ], capture_output = True , text = True )
245+ proc = subprocess .run (
246+ ["gh" , "api" , "repos/{owner}/{repo}/issues" + f"/{ prNumber } /comments" , "-f" , f"body={ body } " ],
247+ capture_output = True ,
248+ text = True ,
249+ )
257250 if proc .returncode != 0 :
258251 print (f"Failed to add comment. Error: { proc .stderr } " )
259252 return None
260253 return json .loads (proc .stdout )
261254
262255 def updateCommentToPR (self , commentId , body ):
263- proc = subprocess .run (["gh" , "api" , "repos/{owner}/{repo}/issues" + f"/comments/{ commentId } " , "-f" , f"body={ body } " ], capture_output = True , text = True )
256+ proc = subprocess .run (
257+ ["gh" , "api" , "repos/{owner}/{repo}/issues" + f"/comments/{ commentId } " , "-f" , f"body={ body } " ],
258+ capture_output = True ,
259+ text = True ,
260+ )
264261 if proc .returncode != 0 :
265262 print (f"Failed to update comment. Error: { proc .stderr } " )
266263 return None
267264 return json .loads (proc .stdout )
268265
269- class APIDigester :
270266
267+ class APIDigester :
271268 def compare (
272269 self ,
273270 baseline_path ,
@@ -300,9 +297,7 @@ def compare(
300297 raise Exception ("swift-api-digester failed" )
301298
302299 if breakage_allow_list_path :
303- self .apply_breakage_allow_list_workaround (
304- breakage_allow_list_path , output_path
305- )
300+ self .apply_breakage_allow_list_workaround (breakage_allow_list_path , output_path )
306301
307302 return APIDigester .BreakageReport (output_path )
308303
@@ -314,11 +309,7 @@ def apply_breakage_allow_list_workaround(self, allowlist_path, report_path):
314309 with open (allowlist_path , "r" ) as f :
315310 allow_list = [line .strip () for line in f .readlines () if line .strip () != "" ]
316311
317- report_list = [
318- line
319- for line in report_list
320- if line .strip () not in allow_list or line .startswith ("/* " )
321- ]
312+ report_list = [line for line in report_list if line .strip () not in allow_list or line .startswith ("/* " )]
322313 with open (report_path , "w" ) as f :
323314 f .write ("" .join (report_list ))
324315
@@ -352,9 +343,7 @@ def dump_sdk(
352343 if abi :
353344 arguments .append ("-abi" )
354345
355- proc = subprocess .run (
356- arguments , capture_output = True , text = True , cwd = modules_path
357- )
346+ proc = subprocess .run (arguments , capture_output = True , text = True , cwd = modules_path )
358347 if proc .returncode != 0 :
359348 print (proc .stderr )
360349 raise Exception ("swift-api-digester failed" )
@@ -386,15 +375,13 @@ def dump_sdk_xcframework(
386375
387376 def append_dependencies (arguments : list ):
388377 deps = module .list_dependencies ()
389- deps_names = map (lambda dep : os .path .basename (dep ), deps )
390378 xcDeps = list (
391379 map (
392380 lambda dep : XCFramework (os .path .join (dependencies_path , dep )),
393381 [
394382 d
395383 for d in os .listdir (dependencies_path )
396- if os .path .isdir (os .path .join (dependencies_path , d ))
397- and d .endswith (".xcframework" )
384+ if os .path .isdir (os .path .join (dependencies_path , d )) and d .endswith (".xcframework" )
398385 ],
399386 )
400387 )
@@ -475,9 +462,7 @@ def __init__(self, path):
475462 self .path = path
476463
477464 def parse_load_commands (self ):
478- otool_proc = subprocess .run (
479- ["otool" , "-l" , self .path ], capture_output = True , text = True
480- )
465+ otool_proc = subprocess .run (["otool" , "-l" , self .path ], capture_output = True , text = True )
481466 if otool_proc .returncode != 0 :
482467 print (otool_proc .stderr )
483468 raise Exception (f"Failed to run otool -l { self .path } " )
@@ -509,9 +494,7 @@ def parse_load_commands(self):
509494
510495 def list_all_dependencies (self ):
511496 dynamic_dependencies = (
512- subprocess .run (
513- ["xcrun" , "otool" , "-L" , self .path ], capture_output = True , text = True
514- )
497+ subprocess .run (["xcrun" , "otool" , "-L" , self .path ], capture_output = True , text = True )
515498 .stdout .strip ()
516499 .split ("\n \t " )
517500 )
@@ -558,9 +541,7 @@ def list_all_dependencies(self):
558541 return list (map (lambda x : x .split ()[0 ], dynamic_dependencies [1 :]))
559542
560543 def list_dependencies (self ):
561- module_path = os .path .join (
562- self .library .library ["LibraryPath" ], self .executable_path ()
563- )
544+ module_path = os .path .join (self .library .library ["LibraryPath" ], self .executable_path ())
564545
565546 def filter_system_dependencies (dependency ):
566547 return (
@@ -570,11 +551,7 @@ def filter_system_dependencies(dependency):
570551 and not dependency .endswith (module_path )
571552 )
572553
573- return list (
574- filter (
575- filter_system_dependencies , self .executable ().list_all_dependencies ()
576- )
577- )
554+ return list (filter (filter_system_dependencies , self .executable ().list_all_dependencies ()))
578555
579556
580557class XCFramework :
@@ -605,7 +582,7 @@ def is_simulator(self):
605582 return self .supported_platform_variant () == "simulator"
606583
607584 def is_device (self ):
608- return not "SupportedPlatformVariant" in self .library
585+ return "SupportedPlatformVariant" not in self .library
609586
610587 def is_ios (self ):
611588 return self .supported_platform () == "ios"
@@ -633,9 +610,7 @@ def __parse_libraries(self):
633610 )
634611
635612 def iOSDeviceModule (self ):
636- deviceLibrary = list (
637- filter (lambda x : x .is_ios () and x .is_device (), self .libraries )
638- )[0 ]
613+ deviceLibrary = list (filter (lambda x : x .is_ios () and x .is_device (), self .libraries ))[0 ]
639614 # return SDKModule(os.path.join(self.path, deviceLibrary.libraryIdentifier(), deviceLibrary.path()))
640615 return SDKModule (self .path , deviceLibrary )
641616
0 commit comments