Fix include of isolate.gypi

Recent changes in GYP seem to have broken our previous
"hack" for getting the GYP rule for .isolate files
imported from the Chromium build/isolate.gypi.

The best solution for now is to remove the hack
and check in a copy of Chromium's src/build/isolate.gypi
in WebRTC's build/ dir instead. A similar approach is
used for our build/protoc.gypi file.

TEST=On Linux, I successfully ran:
gclient runhooks
ninja -C out/Release
and verified a bunch of .isolated files were created in
out/Release (which didn't happen before this patch).

I also renamed the build/isolate.gypi from Chromium to
ensure that our own is used and not that one (in case any
paths would be incorrect).

I also ran build/gyp_chromium in a Chromium checkout
with WebRTC in third_party/webrtc having this patch applied
to ensure GYP processing was still working.

Finally, I verified that the same project generation and
compilation from a Chromium checkout worked the way we build
our Android native tests, using:
. build/android/envsetup.sh
GYP_DEFINES="$GYP_DEFINES include_tests=1 enable_tracing=1" gclient runhooks
ninja -C out/Release android_builder_webrtc

BUG=1916
R=andrew@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/2338004

git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@4907 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/build/common.gypi b/build/common.gypi
index d534d28..1207cc1 100644
--- a/build/common.gypi
+++ b/build/common.gypi
@@ -25,13 +25,11 @@
             'build_with_libjingle': 1,
             'webrtc_root%': '<(DEPTH)/third_party/webrtc',
             'apk_tests_path%': '<(DEPTH)/third_party/webrtc/build/apk_tests.gyp',
-            'import_isolate_path%': '<(DEPTH)/third_party/webrtc/build/import_isolate_chromium.gyp',
             'modules_java_gyp_path%': '<(DEPTH)/third_party/webrtc/modules/modules_java_chromium.gyp',
           }, {
             'build_with_libjingle%': 0,
             'webrtc_root%': '<(DEPTH)/webrtc',
             'apk_tests_path%': '<(DEPTH)/webrtc/build/apk_test_noop.gyp',
-            'import_isolate_path%': '<(DEPTH)/webrtc/build/import_isolate_webrtc.gyp',
             'modules_java_gyp_path%': '<(DEPTH)/webrtc/modules/modules_java.gyp',
           }],
         ],
@@ -40,7 +38,6 @@
       'build_with_libjingle%': '<(build_with_libjingle)',
       'webrtc_root%': '<(webrtc_root)',
       'apk_tests_path%': '<(apk_tests_path)',
-      'import_isolate_path%': '<(import_isolate_path)',
       'modules_java_gyp_path%': '<(modules_java_gyp_path)',
 
       'webrtc_vp8_dir%': '<(webrtc_root)/modules/video_coding/codecs/vp8',
@@ -51,7 +48,6 @@
     'build_with_libjingle%': '<(build_with_libjingle)',
     'webrtc_root%': '<(webrtc_root)',
     'apk_tests_path%': '<(apk_tests_path)',
-    'import_isolate_path%': '<(import_isolate_path)',
     'modules_java_gyp_path%': '<(modules_java_gyp_path)',
     'webrtc_vp8_dir%': '<(webrtc_vp8_dir)',
     'include_opus%': '<(include_opus)',
diff --git a/build/import_isolate_chromium.gyp b/build/import_isolate_chromium.gyp
deleted file mode 100644
index 587f995..0000000
--- a/build/import_isolate_chromium.gyp
+++ /dev/null
@@ -1,22 +0,0 @@
-# Copyright (c) 2013 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.
-
-# See webrtc/build/import_isolate_webrtc.gyp for information about this file.
-{
-  'targets': [
-    {
-      'target_name': 'import_isolate_gypi',
-      'type': 'none',
-      'includes': [
-        # Relative path to isolate.gypi when WebRTC is built from inside
-        # Chromium (i.e. the webrtc/ folder is checked out into third_party/).
-        '../../../build/apk_test.gypi',
-      ],
-    },
-  ],
-}
diff --git a/build/import_isolate_webrtc.gyp b/build/import_isolate_webrtc.gyp
deleted file mode 100644
index b585fae..0000000
--- a/build/import_isolate_webrtc.gyp
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright (c) 2013 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.
-
-# This file exists so we can find the isolate.gypi both when WebRTC is built
-# stand-alone and when built as a part of Chrome.
-# This is needed since GYP does not support evaluating variables in the
-# includes sections of a target, so we cannot use <(DEPTH) or <(webrtc_root).
-{
-  'targets': [
-    {
-      'target_name': 'import_isolate_gypi',
-      'type': 'none',
-      'includes': [
-        # Relative path to isolate.gypi when WebRTC built as a stand-alone
-        # project (i.e. Chromium's build/ folder is checked out into the root).
-        '../../build/isolate.gypi',
-      ],
-    },
-  ],
-}
diff --git a/build/isolate.gypi b/build/isolate.gypi
new file mode 100644
index 0000000..91b92a6
--- /dev/null
+++ b/build/isolate.gypi
@@ -0,0 +1,117 @@
+# Copyright (c) 2013 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.
+
+# Copied from Chromium's src/build/isolate.gypi
+#
+# It was necessary to copy this file to WebRTC, because the path to
+# build/common.gypi is different for the standalone and Chromium builds. Gyp
+# doesn't permit conditional inclusion or variable expansion in include paths.
+# http://code.google.com/p/gyp/wiki/InputFormatReference#Including_Other_Files
+
+# This file is meant to be included into a target to provide a rule
+# to "build" .isolate files into a .isolated file.
+#
+# To use this, create a gyp target with the following form:
+# 'conditions': [
+#   ['test_isolation_mode != "noop"', {
+#     'targets': [
+#       {
+#         'target_name': 'foo_test_run',
+#         'type': 'none',
+#         'dependencies': [
+#           'foo_test',
+#         ],
+#         'includes': [
+#           '../build/isolate.gypi',
+#           'foo_test.isolate',
+#         ],
+#         'sources': [
+#           'foo_test.isolate',
+#         ],
+#       },
+#     ],
+#   }],
+# ],
+#
+# Note: foo_test.isolate is included and a source file. It is an inherent
+# property of the .isolate format. This permits to define GYP variables but is
+# a stricter format than GYP so isolate.py can read it.
+#
+# The generated .isolated file will be:
+#   <(PRODUCT_DIR)/foo_test.isolated
+
+{
+  'rules': [
+    {
+      'rule_name': 'isolate',
+      'extension': 'isolate',
+      'inputs': [
+        # Files that are known to be involved in this step.
+        '<(DEPTH)/tools/swarm_client/isolate.py',
+        '<(DEPTH)/tools/swarm_client/run_isolated.py',
+        '<(DEPTH)/tools/swarm_client/googletest/run_test_cases.py',
+
+        # Disable file tracking by the build driver for now. This means the
+        # project must have the proper build-time dependency for their runtime
+        # dependency. This improves the runtime of the build driver since it
+        # doesn't have to stat() all these files.
+        #
+        # More importantly, it means that even if a isolate_dependency_tracked
+        # file is missing, for example if a file was deleted and the .isolate
+        # file was not updated, that won't break the build, especially in the
+        # case where foo_tests_run is not built! This should be reenabled once
+        # the switch-over to running tests on Swarm is completed.
+        #'<@(isolate_dependency_tracked)',
+      ],
+      'outputs': [
+        '<(PRODUCT_DIR)/<(RULE_INPUT_ROOT).isolated',
+      ],
+      'conditions': [
+        ["test_isolation_outdir==''", {
+          'action': [
+            'python',
+            '<(DEPTH)/tools/swarm_client/isolate.py',
+            '<(test_isolation_mode)',
+            # GYP will eliminate duplicate arguments so '<(PRODUCT_DIR)' cannot
+            # be provided twice. To work around this behavior, append '/'.
+            #
+            # Also have a space after <(PRODUCT_DIR) or visual studio will
+            # escape the argument wrappping " with the \ and merge it into
+            # the following arguments.
+            #
+            # Other variables should use the -V FOO=<(FOO) form so frequent
+            # values, like '0' or '1', aren't stripped out by GYP.
+            '--outdir', '<(PRODUCT_DIR)/ ',
+            '--variable', 'PRODUCT_DIR', '<(PRODUCT_DIR) ',
+            '--variable', 'OS=<(OS)',
+            '--result', '<@(_outputs)',
+            '--isolate', '<(RULE_INPUT_PATH)',
+          ],
+        }, {
+          'action': [
+            'python',
+            '<(DEPTH)/tools/swarm_client/isolate.py',
+            '<(test_isolation_mode)',
+            '--outdir', '<(test_isolation_outdir)',
+            # See comment above.
+            '--variable', 'PRODUCT_DIR', '<(PRODUCT_DIR) ',
+            '--variable', 'OS=<(OS)',
+            '--result', '<@(_outputs)',
+            '--isolate', '<(RULE_INPUT_PATH)',
+          ],
+        }],
+        ['test_isolation_fail_on_missing == 0', {
+            'action': ['--ignore_broken_items'],
+          },
+        ],
+      ],
+
+      'msvs_cygwin_shell': 0,
+    },
+  ],
+}
diff --git a/common_audio/common_audio.gyp b/common_audio/common_audio.gyp
index 1318684..da52673 100644
--- a/common_audio/common_audio.gyp
+++ b/common_audio/common_audio.gyp
@@ -236,10 +236,10 @@
               'target_name': 'common_audio_unittests_run',
               'type': 'none',
               'dependencies': [
-                '<(import_isolate_path):import_isolate_gypi',
                 'common_audio_unittests',
               ],
               'includes': [
+                '../build/isolate.gypi',
                 'common_audio_unittests.isolate',
               ],
               'sources': [
diff --git a/common_video/common_video.gyp b/common_video/common_video.gyp
index 2ba1681..f4d9ceb 100644
--- a/common_video/common_video.gyp
+++ b/common_video/common_video.gyp
@@ -114,10 +114,10 @@
               'target_name': 'common_video_unittests_run',
               'type': 'none',
               'dependencies': [
-                '<(import_isolate_path):import_isolate_gypi',
                 'common_video_unittests',
               ],
               'includes': [
+                '../build/isolate.gypi',
                 'common_video_unittests.isolate',
               ],
               'sources': [
diff --git a/modules/audio_coding/neteq/neteq.gypi b/modules/audio_coding/neteq/neteq.gypi
index 31297ff..9306137 100644
--- a/modules/audio_coding/neteq/neteq.gypi
+++ b/modules/audio_coding/neteq/neteq.gypi
@@ -251,10 +251,10 @@
               'target_name': 'neteq_unittests_run',
               'type': 'none',
               'dependencies': [
-                '<(import_isolate_path):import_isolate_gypi',
                 'neteq_unittests',
               ],
               'includes': [
+                '../../../build/isolate.gypi',
                 'neteq_unittests.isolate',
               ],
               'sources': [
diff --git a/modules/audio_coding/neteq4/neteq.gypi b/modules/audio_coding/neteq4/neteq.gypi
index e98178d..1a01a34 100644
--- a/modules/audio_coding/neteq4/neteq.gypi
+++ b/modules/audio_coding/neteq4/neteq.gypi
@@ -200,10 +200,10 @@
               'target_name': 'audio_decoder_unittests_run',
               'type': 'none',
               'dependencies': [
-                '<(import_isolate_path):import_isolate_gypi',
                 'audio_decoder_unittests',
               ],
               'includes': [
+                '../../../build/isolate.gypi',
                 'audio_decoder_unittests.isolate',
               ],
               'sources': [
diff --git a/modules/audio_device/audio_device.gypi b/modules/audio_device/audio_device.gypi
index a56c81d..75fbf73 100644
--- a/modules/audio_device/audio_device.gypi
+++ b/modules/audio_device/audio_device.gypi
@@ -241,10 +241,10 @@
               'target_name': 'audio_device_tests_run',
               'type': 'none',
               'dependencies': [
-                '<(import_isolate_path):import_isolate_gypi',
                 'audio_device_tests',
               ],
               'includes': [
+                '../../build/isolate.gypi',
                 'audio_device_tests.isolate',
               ],
               'sources': [
diff --git a/modules/modules.gyp b/modules/modules.gyp
index 38f9377..3a93624 100644
--- a/modules/modules.gyp
+++ b/modules/modules.gyp
@@ -349,10 +349,10 @@
               'target_name': 'modules_tests_run',
               'type': 'none',
               'dependencies': [
-                '<(import_isolate_path):import_isolate_gypi',
                 'modules_tests',
               ],
               'includes': [
+                '../build/isolate.gypi',
                 'modules_tests.isolate',
               ],
               'sources': [
@@ -363,10 +363,10 @@
               'target_name': 'modules_unittests_run',
               'type': 'none',
               'dependencies': [
-                '<(import_isolate_path):import_isolate_gypi',
                 'modules_unittests',
               ],
               'includes': [
+                '../build/isolate.gypi',
                 'modules_unittests.isolate',
               ],
               'sources': [
diff --git a/modules/video_capture/video_capture.gypi b/modules/video_capture/video_capture.gypi
index 1e39260..ea6d04b 100644
--- a/modules/video_capture/video_capture.gypi
+++ b/modules/video_capture/video_capture.gypi
@@ -185,10 +185,10 @@
               'target_name': 'video_capture_tests_run',
               'type': 'none',
               'dependencies': [
-                '<(import_isolate_path):import_isolate_gypi',
                 'video_capture_tests',
               ],
               'includes': [
+                '../../build/isolate.gypi',
                 'video_capture_tests.isolate',
               ],
               'sources': [
diff --git a/modules/video_render/video_render.gypi b/modules/video_render/video_render.gypi
index f8662c3..4f38444 100644
--- a/modules/video_render/video_render.gypi
+++ b/modules/video_render/video_render.gypi
@@ -228,10 +228,10 @@
               'target_name': 'video_render_tests_run',
               'type': 'none',
               'dependencies': [
-                '<(import_isolate_path):import_isolate_gypi',
                 'video_render_tests',
               ],
               'includes': [
+                '../../build/isolate.gypi',
                 'video_render_tests.isolate',
               ],
               'sources': [
diff --git a/system_wrappers/source/system_wrappers_tests.gyp b/system_wrappers/source/system_wrappers_tests.gyp
index 36c47d2..b8587eb 100644
--- a/system_wrappers/source/system_wrappers_tests.gyp
+++ b/system_wrappers/source/system_wrappers_tests.gyp
@@ -79,10 +79,10 @@
           'target_name': 'system_wrappers_unittests_run',
           'type': 'none',
           'dependencies': [
-            '<(import_isolate_path):import_isolate_gypi',
             'system_wrappers_unittests',
           ],
           'includes': [
+            '../../build/isolate.gypi',
             'system_wrappers_unittests.isolate',
           ],
           'sources': [
diff --git a/test/metrics.gyp b/test/metrics.gyp
index 1a2714e..3d61b6c 100644
--- a/test/metrics.gyp
+++ b/test/metrics.gyp
@@ -70,10 +70,10 @@
           'target_name': 'metrics_unittests_run',
           'type': 'none',
           'dependencies': [
-            '<(import_isolate_path):import_isolate_gypi',
             'metrics_unittests',
           ],
           'includes': [
+            '../build/isolate.gypi',
             'metrics_unittests.isolate',
           ],
           'sources': [
diff --git a/test/test.gyp b/test/test.gyp
index 4e01b25..3991106 100644
--- a/test/test.gyp
+++ b/test/test.gyp
@@ -208,10 +208,10 @@
           'target_name': 'test_support_unittests_run',
           'type': 'none',
           'dependencies': [
-            '<(import_isolate_path):import_isolate_gypi',
             'test_support_unittests',
           ],
           'includes': [
+            '../build/isolate.gypi',
             'test_support_unittests.isolate',
           ],
           'sources': [
diff --git a/tools/tools.gyp b/tools/tools.gyp
index 655181b..fa79046 100644
--- a/tools/tools.gyp
+++ b/tools/tools.gyp
@@ -150,10 +150,10 @@
               'target_name': 'tools_unittests_run',
               'type': 'none',
               'dependencies': [
-                '<(import_isolate_path):import_isolate_gypi',
                 'tools_unittests',
               ],
               'includes': [
+                '../build/isolate.gypi',
                 'tools_unittests.isolate',
               ],
               'sources': [
diff --git a/video_engine/test/auto_test/vie_auto_test.gypi b/video_engine/test/auto_test/vie_auto_test.gypi
index 1c226b8..0a9250c 100644
--- a/video_engine/test/auto_test/vie_auto_test.gypi
+++ b/video_engine/test/auto_test/vie_auto_test.gypi
@@ -133,10 +133,10 @@
           'target_name': 'vie_auto_test_run',
           'type': 'none',
           'dependencies': [
-            '<(import_isolate_path):import_isolate_gypi',
             'vie_auto_test',
           ],
           'includes': [
+            '../../../build/isolate.gypi',
             'vie_auto_test.isolate',
           ],
           'sources': [
diff --git a/video_engine/video_engine_core.gypi b/video_engine/video_engine_core.gypi
index b683474..8bae1fd 100644
--- a/video_engine/video_engine_core.gypi
+++ b/video_engine/video_engine_core.gypi
@@ -185,10 +185,10 @@
               'target_name': 'video_engine_core_unittests_run',
               'type': 'none',
               'dependencies': [
-                '<(import_isolate_path):import_isolate_gypi',
                 'video_engine_core_unittests',
               ],
               'includes': [
+                '../build/isolate.gypi',
                 'video_engine_core_unittests.isolate',
               ],
               'sources': [
diff --git a/voice_engine/voice_engine.gyp b/voice_engine/voice_engine.gyp
index 34070fa..5e00077 100644
--- a/voice_engine/voice_engine.gyp
+++ b/voice_engine/voice_engine.gyp
@@ -303,10 +303,10 @@
               'target_name': 'voice_engine_unittests_run',
               'type': 'none',
               'dependencies': [
-                '<(import_isolate_path):import_isolate_gypi',
                 'voice_engine_unittests',
               ],
               'includes': [
+                '../build/isolate.gypi',
                 'voice_engine_unittests.isolate',
               ],
               'sources': [
@@ -317,10 +317,10 @@
               'target_name': 'voe_auto_test_run',
               'type': 'none',
               'dependencies': [
-                '<(import_isolate_path):import_isolate_gypi',
                 'voe_auto_test',
               ],
               'includes': [
+                '../build/isolate.gypi',
                 'voe_auto_test.isolate',
               ],
               'sources': [