Move test and localization scripts

R=tvanderlippe@chromium.org

Change-Id: I9bfa77ef2791638b07089e4faf405f834ff47148
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1947525
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
diff --git a/scripts/compile_frontend.py b/scripts/compile_frontend.py
deleted file mode 100755
index ad264db..0000000
--- a/scripts/compile_frontend.py
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/usr/bin/env python
-# Copyright (c) 2012 Google Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-#     * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#     * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following disclaimer
-# in the documentation and/or other materials provided with the
-# distribution.
-#     * Neither the name of Google Inc. nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-from test import run_type_check
-
-if __name__ == '__main__':
-    run_type_check.main()
diff --git a/scripts/devtools_paths.py b/scripts/devtools_paths.py
index a8b8c29..def3726 100644
--- a/scripts/devtools_paths.py
+++ b/scripts/devtools_paths.py
@@ -59,11 +59,11 @@
 
 
 def check_localizable_resources_path():
-    return path.join(devtools_root_path(), 'scripts', 'check_localizable_resources.js')
+    return path.join(devtools_root_path(), 'scripts', 'localization', 'check_localizable_resources.js')
 
 
 def check_localized_strings_path():
-    return path.join(devtools_root_path(), 'scripts', 'check_localizability.js')
+    return path.join(devtools_root_path(), 'scripts', 'localization', 'check_localizability.js')
 
 
 def karma_path():
diff --git a/scripts/lint_javascript.py b/scripts/lint_javascript.py
deleted file mode 100755
index 75d194c..0000000
--- a/scripts/lint_javascript.py
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2016 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-from test import run_lint_check
-
-if __name__ == '__main__':
-    run_lint_check.main()
diff --git a/scripts/check_localizability.js b/scripts/localization/check_localizability.js
similarity index 98%
rename from scripts/check_localizability.js
rename to scripts/localization/check_localizability.js
index 94d1c55..9c111e6 100644
--- a/scripts/check_localizability.js
+++ b/scripts/localization/check_localizability.js
@@ -12,7 +12,7 @@
 // In this case, add it to the excluded errors at the top of the script.
 
 const path = require('path');
-const localizationUtils = require('./localization_utils/localization_utils');
+const localizationUtils = require('./utils/localization_utils');
 const esprimaTypes = localizationUtils.esprimaTypes;
 const escodegen = localizationUtils.escodegen;
 const esprima = localizationUtils.esprima;
@@ -41,7 +41,7 @@
 
   try {
     let filePaths = [];
-    const frontendPath = path.resolve(__dirname, '..', 'front_end');
+    const frontendPath = path.resolve(__dirname, '..', '..', 'front_end');
     let filePathPromises = [localizationUtils.getFilesFromDirectory(frontendPath, filePaths, ['.grdp'])];
     if (process.argv[2] === '-a') {
       filePathPromises.push(localizationUtils.getFilesFromDirectory(frontendPath, filePaths, ['.js']));
diff --git a/scripts/check_localizable_resources.js b/scripts/localization/check_localizable_resources.js
similarity index 97%
rename from scripts/check_localizable_resources.js
rename to scripts/localization/check_localizable_resources.js
index 48b5126..c9fb0d5 100644
--- a/scripts/check_localizable_resources.js
+++ b/scripts/localization/check_localizable_resources.js
@@ -16,8 +16,8 @@
 const {promisify} = require('util');
 const writeFileAsync = promisify(fs.writeFile);
 const appendFileAsync = promisify(fs.appendFile);
-const checkLocalizedStrings = require('./localization_utils/check_localized_strings');
-const localizationUtils = require('./localization_utils/localization_utils');
+const checkLocalizedStrings = require('./utils/check_localized_strings');
+const localizationUtils = require('./utils/localization_utils');
 
 const grdpFileStart = '<?xml version="1.0" encoding="utf-8"?>\n<grit-part>\n';
 const grdpFileEnd = '</grit-part>';
diff --git a/scripts/localization_utils/check_localized_strings.js b/scripts/localization/utils/check_localized_strings.js
similarity index 99%
rename from scripts/localization_utils/check_localized_strings.js
rename to scripts/localization/utils/check_localized_strings.js
index 491226c..0ceae2c 100644
--- a/scripts/localization_utils/check_localized_strings.js
+++ b/scripts/localization/utils/check_localized_strings.js
@@ -60,7 +60,7 @@
 const IDSkeys = new Map();
 const fileToGRDPMap = new Map();
 
-const devtoolsFrontendPath = path.resolve(__dirname, '..', '..', 'front_end');
+const devtoolsFrontendPath = path.resolve(__dirname, '..', '..', '..', 'front_end');
 let devtoolsFrontendDirs;
 
 /**
diff --git a/scripts/localization_utils/localization_utils.js b/scripts/localization/utils/localization_utils.js
similarity index 98%
rename from scripts/localization_utils/localization_utils.js
rename to scripts/localization/utils/localization_utils.js
index 75e9711..a0c13e9 100644
--- a/scripts/localization_utils/localization_utils.js
+++ b/scripts/localization/utils/localization_utils.js
@@ -32,9 +32,9 @@
 };
 const IDSPrefix = 'IDS_DEVTOOLS_';
 
-const SRC_PATH = path.resolve(__dirname, '..', '..');
+const SRC_PATH = path.resolve(__dirname, '..', '..', '..');
 const GRD_PATH = path.resolve(SRC_PATH, 'front_end', 'langpacks', 'devtools_ui_strings.grd');
-const SHARED_STRINGS_PATH = path.resolve(__dirname, '..', '..', 'front_end', 'langpacks', 'shared_strings.grdp');
+const SHARED_STRINGS_PATH = path.resolve(SRC_PATH, 'front_end', 'langpacks', 'shared_strings.grdp');
 const NODE_MODULES_PATH = path.resolve(SRC_PATH, 'node_modules');
 const escodegen = require(path.resolve(NODE_MODULES_PATH, 'escodegen'));
 const esprima = require(path.resolve(NODE_MODULES_PATH, 'esprima'));
diff --git a/scripts/localization_utils/md5.js b/scripts/localization/utils/md5.js
similarity index 99%
rename from scripts/localization_utils/md5.js
rename to scripts/localization/utils/md5.js
index 3f59f37..a54c3a9 100644
--- a/scripts/localization_utils/md5.js
+++ b/scripts/localization/utils/md5.js
@@ -154,4 +154,4 @@
   return str;
 }
 
-module.exports = md5;
\ No newline at end of file
+module.exports = md5;
diff --git a/scripts/run_tests.py b/scripts/run_tests.py
deleted file mode 100755
index 36aeed5..0000000
--- a/scripts/run_tests.py
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2019 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-from test import run_unittests
-
-if __name__ == '__main__':
-    run_unittests.main()
diff --git a/scripts/test/run_type_check.py b/scripts/test/run_type_check.py
index 2a65a65..ae5cebb 100755
--- a/scripts/test/run_type_check.py
+++ b/scripts/test/run_type_check.py
@@ -29,7 +29,7 @@
 
 import argparse
 import os
-import os.path as path
+from os import path
 import re
 import shutil
 import subprocess
@@ -102,7 +102,6 @@
 
 JAVA_BUILD_REGEX = re.compile(r'\w+ version "(\d+)\.(\d+)')
 
-
 def log_error(message):
     print 'ERROR: ' + message
 
@@ -206,11 +205,44 @@
 
 
 def find_java():
+    # Based on http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python.
+    def which(program):
+        def is_executable(fpath):
+            return path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+        fpath, fname = path.split(program)
+        if fpath:
+            if is_executable(program):
+                return program
+            return None
+        env_paths = os.environ["PATH"].split(os.pathsep)
+        if sys.platform == "win32":
+            env_paths = get_windows_path(env_paths)
+        for part in env_paths:
+            part = part.strip('\"')
+            file = path.join(part, program)
+            if is_executable(file):
+                return file
+            if sys.platform == "win32" and not file.endswith(".exe"):
+                file_exe = file + ".exe"
+                if is_executable(file_exe):
+                    return file_exe
+        return None
+
+    # Use to find 64-bit programs (e.g. Java) when using 32-bit python in Windows
+    def get_windows_path(env_paths):
+        new_env_paths = env_paths[:]
+        for env_path in env_paths:
+            env_path = env_path.lower()
+            if "system32" in env_path:
+                new_env_paths.append(env_path.replace("system32", "sysnative"))
+        return new_env_paths
+
     required_major = 1
     required_minor = 7
     exec_command = None
     has_server_jvm = True
-    java_path = utils.which('java')
+    java_path = which('java')
 
     if not java_path:
         print 'NOTE: No Java executable found in $PATH.'