Generate iOS framework umbrella header.

Instead of keeping the umbrella header in sync manually and needing
ifdefs to make it include the correct headers depending on platform,
generate it based on the headers we include in the framework target.

Can also be used to only include internal software codec headers when
compiling with support for them.

Bug: webrtc:7925
Change-Id: I63f97af1efc8710cfd62d527fcb343fed05daae2
Reviewed-on: https://webrtc-review.googlesource.com/38702
Commit-Queue: Anders Carlsson <andersc@webrtc.org>
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21613}
diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn
index 3896bef..121e47c 100644
--- a/sdk/BUILD.gn
+++ b/sdk/BUILD.gn
@@ -562,6 +562,7 @@
           }
           deps = [
             ":common_objc",
+            ":framework_objc",
             ":peerconnection_objc",
             ":peerconnectionfactory_objc",
             ":videotoolbox_objc",
@@ -576,6 +577,7 @@
             "//build/config/ios:xctest",
             "//third_party/ocmock",
           ]
+          include_dirs += [ "$root_out_dir/WebRTC.framework/Headers/" ]
         }
 
         bundle_data("sdk_unittests_bundle_data") {
@@ -665,7 +667,7 @@
     }
 
     if (is_ios) {
-      ios_framework_bundle("framework_objc") {
+      ios_framework_bundle_with_umbrella_header("framework_objc") {
         info_plist = "objc/Framework/Info.plist"
         output_name = "WebRTC"
 
@@ -723,7 +725,6 @@
           "objc/Framework/Headers/WebRTC/RTCVideoTrack.h",
           "objc/Framework/Headers/WebRTC/RTCVideoViewShading.h",
           "objc/Framework/Headers/WebRTC/UIDevice+RTCDevice.h",
-          "objc/Framework/Headers/WebRTC/WebRTC.h",
         ]
         if (rtc_use_metal_rendering) {
           common_objc_headers +=
diff --git a/sdk/objc/Framework/Headers/WebRTC/WebRTC.h b/sdk/objc/Framework/Headers/WebRTC/WebRTC.h
deleted file mode 100644
index b9e0149..0000000
--- a/sdk/objc/Framework/Headers/WebRTC/WebRTC.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- *  Copyright 2016 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#import <WebRTC/RTCAVFoundationVideoSource.h>
-#if TARGET_OS_IPHONE
-#import <WebRTC/RTCAudioSession.h>
-#import <WebRTC/RTCAudioSessionConfiguration.h>
-#endif
-#import <WebRTC/RTCAudioSource.h>
-#import <WebRTC/RTCAudioTrack.h>
-#import <WebRTC/RTCCameraVideoCapturer.h>
-#import <WebRTC/RTCVideoCapturer.h>
-#if TARGET_OS_IPHONE
-#import <WebRTC/RTCCameraPreviewView.h>
-#endif
-#import <WebRTC/RTCConfiguration.h>
-#import <WebRTC/RTCDataChannel.h>
-#import <WebRTC/RTCDataChannelConfiguration.h>
-#import <WebRTC/RTCDispatcher.h>
-#if TARGET_OS_IPHONE
-#import <WebRTC/RTCEAGLVideoView.h>
-#import <WebRTC/RTCMTLVideoView.h>
-#import <WebRTC/RTCVideoViewShading.h>
-#endif
-#import <WebRTC/RTCFieldTrials.h>
-#import <WebRTC/RTCFileLogger.h>
-#import <WebRTC/RTCIceCandidate.h>
-#import <WebRTC/RTCIceServer.h>
-#import <WebRTC/RTCIntervalRange.h>
-#import <WebRTC/RTCLegacyStatsReport.h>
-#import <WebRTC/RTCLogging.h>
-#import <WebRTC/RTCMacros.h>
-#import <WebRTC/RTCMediaConstraints.h>
-#import <WebRTC/RTCMediaSource.h>
-#import <WebRTC/RTCMediaStream.h>
-#import <WebRTC/RTCMediaStreamTrack.h>
-#import <WebRTC/RTCMetrics.h>
-#import <WebRTC/RTCMetricsSampleInfo.h>
-#import <WebRTC/RTCPeerConnection.h>
-#import <WebRTC/RTCPeerConnectionFactory.h>
-#import <WebRTC/RTCPeerConnectionFactoryOptions.h>
-#import <WebRTC/RTCRtpCodecParameters.h>
-#import <WebRTC/RTCRtpEncodingParameters.h>
-#import <WebRTC/RTCRtpParameters.h>
-#import <WebRTC/RTCRtpReceiver.h>
-#import <WebRTC/RTCRtpSender.h>
-#import <WebRTC/RTCSSLAdapter.h>
-#import <WebRTC/RTCSessionDescription.h>
-#import <WebRTC/RTCTracing.h>
-#import <WebRTC/RTCVideoCodec.h>
-#import <WebRTC/RTCVideoCodecFactory.h>
-#import <WebRTC/RTCVideoCodecH264.h>
-#import <WebRTC/RTCVideoFrame.h>
-#import <WebRTC/RTCVideoFrameBuffer.h>
-#import <WebRTC/RTCVideoRenderer.h>
-#import <WebRTC/RTCVideoSource.h>
-#import <WebRTC/RTCVideoTrack.h>
-#if TARGET_OS_IPHONE
-#import <WebRTC/UIDevice+RTCDevice.h>
-#endif
diff --git a/sdk/objc/Framework/UnitTests/RTCDoNotPutCPlusPlusInFrameworkHeaders_xctest.m b/sdk/objc/Framework/UnitTests/RTCDoNotPutCPlusPlusInFrameworkHeaders_xctest.m
index 02bef9b..7548101 100644
--- a/sdk/objc/Framework/UnitTests/RTCDoNotPutCPlusPlusInFrameworkHeaders_xctest.m
+++ b/sdk/objc/Framework/UnitTests/RTCDoNotPutCPlusPlusInFrameworkHeaders_xctest.m
@@ -12,7 +12,7 @@
 
 #import <Foundation/Foundation.h>
 
-#import <WebRTC/WebRTC.h>
+#import <WebRTC.h>
 
 @interface RTCDoNotPutCPlusPlusInFrameworkHeaders : XCTestCase
 @end
diff --git a/tools_webrtc/ios/generate_umbrella_header.py b/tools_webrtc/ios/generate_umbrella_header.py
new file mode 100644
index 0000000..d8a87bf
--- /dev/null
+++ b/tools_webrtc/ios/generate_umbrella_header.py
@@ -0,0 +1,40 @@
+# Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS.  All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+import argparse
+import datetime
+import sys
+
+
+def GenerateUmbrellaHeader():
+  parser = argparse.ArgumentParser(description='Generate umbrella header')
+  parser.add_argument("-o", "--out", type=str, help="Output file.")
+  parser.add_argument("-s", "--sources", default=[], type=str, nargs='+',
+                      help="Headers to include.")
+
+  args = parser.parse_args()
+
+  with open(args.out, "w") as outfile:
+    outfile.write("""/*
+     *  Copyright %d The WebRTC project authors. All Rights Reserved.
+     *
+     *  Use of this source code is governed by a BSD-style license
+     *  that can be found in the LICENSE file in the root of the source
+     *  tree. An additional intellectual property rights grant can be found
+     *  in the file PATENTS.  All contributing project authors may
+     *  be found in the AUTHORS file in the root of the source tree.
+     */\n\n""" % datetime.datetime.now().year)
+
+    for s in args.sources:
+      outfile.write("#import <{}>\n".format(s))
+
+  return 0
+
+
+if __name__ == '__main__':
+  sys.exit(GenerateUmbrellaHeader())
diff --git a/webrtc.gni b/webrtc.gni
index ffa92d4..ae68318 100644
--- a/webrtc.gni
+++ b/webrtc.gni
@@ -431,6 +431,50 @@
       }
     }
   }
+
+  template("ios_framework_bundle_with_umbrella_header") {
+    forward_variables_from(invoker, [ "output_name" ])
+    umbrella_header_path =
+        "$target_gen_dir/$output_name.framework/Headers/$output_name.h"
+
+    ios_framework_bundle(target_name) {
+      forward_variables_from(invoker, "*", [])
+
+      deps += [ ":copy_umbrella_header_$target_name" ]
+    }
+
+    action("umbrella_header_$target_name") {
+      forward_variables_from(invoker, [ "public_headers" ])
+
+      script = "//tools_webrtc/ios/generate_umbrella_header.py"
+
+      outputs = [
+        umbrella_header_path,
+      ]
+      args = [
+               "--out",
+               rebase_path(umbrella_header_path, root_build_dir),
+               "--sources",
+             ] + rebase_path(public_headers, "objc/Framework/Headers/")
+    }
+
+    copy("copy_umbrella_header_$target_name") {
+      sources = [
+        umbrella_header_path,
+      ]
+      outputs = [
+        "$root_out_dir/$output_name.framework/Headers/$output_name.h",
+      ]
+
+      deps = [
+        ":umbrella_header_$target_name",
+      ]
+    }
+  }
+
+  set_defaults("ios_framework_bundle_with_umbrella_header") {
+    configs = default_shared_library_configs
+  }
 }
 
 if (is_android) {