MB: Add support for isolating scripts + isolate low_bandwidth_audio_test.py.

NOTRY=True

Bug: chromium:755660
Change-Id: I92de99cd1e3dd206f6cd366dbfd1c8c211d37cc7
Reviewed-on: https://webrtc-review.googlesource.com/4420
Commit-Queue: Edward Lemur <ehmaldonado@webrtc.org>
Reviewed-by: Henrik Kjellander <kjellander@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20089}
diff --git a/.gitignore b/.gitignore
index ce0a07a..6631190 100644
--- a/.gitignore
+++ b/.gitignore
@@ -49,8 +49,10 @@
 /tools_webrtc/android/profiling/flamegraph
 /tools_webrtc/android/profiling/simpleperf
 /tools_webrtc/audio_quality/linux/pesq
+/tools_webrtc/audio_quality/linux/PolqaOem64
 /tools_webrtc/audio_quality/mac/pesq
 /tools_webrtc/audio_quality/win/*.exe
+/tools_webrtc/audio_quality/win/*.dll
 /tools_webrtc/video_quality_toolchain/linux/ffmpeg
 /tools_webrtc/video_quality_toolchain/linux/zxing
 /tools_webrtc/video_quality_toolchain/mac/ffmpeg
diff --git a/audio/BUILD.gn b/audio/BUILD.gn
index 04dec03..6917713 100644
--- a/audio/BUILD.gn
+++ b/audio/BUILD.gn
@@ -154,10 +154,28 @@
       }
 
       data = [
+        "../resources/voice_engine/audio_dtx16.wav",
         "../resources/voice_engine/audio_tiny16.wav",
         "../resources/voice_engine/audio_tiny48.wav",
-        "../resources/voice_engine/audio_dtx16.wav",
+        "test/low_bandwidth_audio_test.py",
       ]
+      if (is_linux) {
+        data += [
+          "../tools_webrtc/audio_quality/linux/PolqaOem64",
+          "../tools_webrtc/audio_quality/linux/pesq",
+        ]
+      }
+      if (is_win) {
+        data += [
+          "../tools_webrtc/audio_quality/win/PolqaOem64.dll",
+          "../tools_webrtc/audio_quality/win/PolqaOem64.exe",
+          "../tools_webrtc/audio_quality/win/pesq.exe",
+          "../tools_webrtc/audio_quality/win/vcomp120.dll",
+        ]
+      }
+      if (is_mac) {
+        data += [ "../tools_webrtc/audio_quality/mac/pesq" ]
+      }
 
       if (!build_with_chromium && is_clang) {
         # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163)
diff --git a/tools_webrtc/mb/gn_isolate_map.pyl b/tools_webrtc/mb/gn_isolate_map.pyl
index 09314a9..33544bc 100644
--- a/tools_webrtc/mb/gn_isolate_map.pyl
+++ b/tools_webrtc/mb/gn_isolate_map.pyl
@@ -62,6 +62,14 @@
       "--quick",
     ],
   },
+  "low_bandwidth_audio_perf_test": {
+    "label": "//audio:low_bandwidth_audio_test",
+    "type": "script",
+    "script": "//audio/test/low_bandwidth_audio_test.py",
+    "args": [
+      ".", "--remove",
+    ],
+  },
   "modules_tests": {
     "label": "//modules:modules_tests",
     "type": "console_test_launcher",
diff --git a/tools_webrtc/mb/mb.py b/tools_webrtc/mb/mb.py
index 2cd54f2..dcf6a57 100755
--- a/tools_webrtc/mb/mb.py
+++ b/tools_webrtc/mb/mb.py
@@ -833,19 +833,14 @@
           runtime_deps_targets = ['browser_tests.exe.runtime_deps']
         else:
           runtime_deps_targets = ['browser_tests.runtime_deps']
-      elif (isolate_map[target]['type'] == 'script' or
-            isolate_map[target].get('label_type') == 'group'):
-        # For script targets, the build target is usually a group,
-        # for which gn generates the runtime_deps next to the stamp file
-        # for the label, which lives under the obj/ directory, but it may
-        # also be an executable.
-        label = isolate_map[target]['label']
+      elif isolate_map[target]['type'] == 'script':
+        label = isolate_map[target]['label'].split(':')[1]
         runtime_deps_targets = [
-            'obj/%s.stamp.runtime_deps' % label.replace(':', '/')]
+            '%s.runtime_deps' % label]
         if self.platform == 'win32':
-          runtime_deps_targets += [ target + '.exe.runtime_deps' ]
+          runtime_deps_targets += [ label + '.exe.runtime_deps' ]
         else:
-          runtime_deps_targets += [ target + '.runtime_deps' ]
+          runtime_deps_targets += [ label + '.runtime_deps' ]
       elif self.platform == 'win32':
         runtime_deps_targets = [target + '.exe.runtime_deps']
       else:
@@ -1047,7 +1042,7 @@
                                 output_path=None)
     if test_type not in ('console_test_launcher', 'windowed_test_launcher',
                          'non_parallel_console_test_launcher',
-                         'additional_compile_target', 'junit_test'):
+                         'additional_compile_target', 'junit_test', 'script'):
       self.WriteFailureAndRaise('No command line for %s found (test type %s).'
                                 % (target, test_type), output_path=None)
 
@@ -1063,6 +1058,8 @@
 
       if test_type != 'junit_test':
         cmdline += ['--target-devices-file', '${SWARMING_BOT_FILE}']
+    elif test_type == "script":
+      cmdline = ['../../' + self.ToSrcRelPath(isolate_map[target]['script'])]
     else:
       extra_files = ['../../testing/test_env.py']
 
diff --git a/tools_webrtc/mb/mb_unittest.py b/tools_webrtc/mb/mb_unittest.py
index 312fee6..e24a01b 100755
--- a/tools_webrtc/mb/mb_unittest.py
+++ b/tools_webrtc/mb/mb_unittest.py
@@ -467,6 +467,41 @@
         '--tsan=0',
     ])
 
+  def test_gn_gen_script(self):
+    test_files = {
+      '/tmp/swarming_targets': 'base_unittests_script\n',
+      '/fake_src/testing/buildbot/gn_isolate_map.pyl': (
+          "{'base_unittests_script': {"
+          "  'label': '//base:base_unittests',"
+          "  'type': 'script',"
+          "  'script': '//base/base_unittests_script.py',"
+          "}}\n"
+      ),
+      '/fake_src/out/Default/base_unittests.runtime_deps': (
+          "base_unittests\n"
+          "base_unittests_script.py\n"
+      ),
+    }
+    mbw = self.check(['gen', '-c', 'gn_debug_goma', '//out/Default',
+                      '--swarming-targets-file', '/tmp/swarming_targets',
+                      '--isolate-map-file',
+                      '/fake_src/testing/buildbot/gn_isolate_map.pyl'],
+                     files=test_files, ret=0)
+
+    isolate_file = (
+        mbw.files['/fake_src/out/Default/base_unittests_script.isolate'])
+    isolate_file_contents = ast.literal_eval(isolate_file)
+    files = isolate_file_contents['variables']['files']
+    command = isolate_file_contents['variables']['command']
+
+    self.assertEqual(files, [
+        'base_unittests',
+        'base_unittests_script.py',
+    ])
+    self.assertEqual(command, [
+        '../../base/base_unittests_script.py',
+    ])
+
   def test_gn_gen_non_parallel_console_test_launcher(self):
     test_files = {
       '/tmp/swarming_targets': 'base_unittests\n',