Add flag to clean up temporary results after building iOS Framework or static lib

The --purify flag can now be passed to remove the temporary
files and directories created while building the iOS Framework or static
library. That way, only the final result(s) are taking up space in the
output folder.

BUG=None
NOTRY=True

Review-Url: https://codereview.webrtc.org/2740923003
Cr-Commit-Position: refs/heads/master@{#17224}
diff --git a/tools-webrtc/ios/build_ios_libs.py b/tools-webrtc/ios/build_ios_libs.py
index fbc8df0..734f3e2 100755
--- a/tools-webrtc/ios/build_ios_libs.py
+++ b/tools-webrtc/ios/build_ios_libs.py
@@ -50,6 +50,9 @@
       help='Architectures to build. Defaults to %(default)s.')
   parser.add_argument('-c', '--clean', action='store_true', default=False,
       help='Removes the previously generated build output, if any.')
+  parser.add_argument('-p', '--purify', action='store_true', default=False,
+      help='Purifies the previously generated build output by '
+           'removing the temporary results used when (re)building.')
   parser.add_argument('-o', '--output-dir', default=SDK_OUTPUT_DIR,
       help='Specifies a directory to output the build artifacts to. '
            'If specified together with -c, deletes the dir.')
@@ -78,6 +81,15 @@
     shutil.rmtree(output_dir)
 
 
+def _CleanTemporary(output_dir, architectures):
+  if os.path.isdir(output_dir):
+    logging.info('Removing temporary build files.')
+    for arch in architectures:
+      arch_lib_path = os.path.join(output_dir, arch + '_libs')
+      if os.path.isdir(arch_lib_path):
+        shutil.rmtree(arch_lib_path)
+
+
 def BuildWebRTC(output_dir, target_arch, flavor, build_type,
                 ios_deployment_target, libvpx_build_vp9, use_bitcode,
                 use_goma, extra_gn_args):
@@ -146,6 +158,11 @@
     return 0
 
   architectures = list(args.arch)
+
+  if args.purify:
+    _CleanTemporary(args.output_dir, architectures)
+    return 0
+
   # Ignoring x86 except for static libraries for now because of a GN build issue
   # where the generated dynamic framework has the wrong architectures.
   if 'x86' in architectures and args.build_type != 'static_only':