mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 09:47:56 +08:00
The current Loc presubmit are doing two checks: check_localizable_resources and check_localizability (Details of what they are checking: https://docs.google.com/document/d/1L6TkT2-42MMQ72ZSBMFwUaq7M6mDgA2X0x8oHHKaV_U/edit#heading=h.w1no7qaa0mi0) This CL merge two checks into one single check. check_localizability are modified into a utils file, and check_localizable_resources will also run those localizability checks when the files are visited. By doing this, we avoid the extra call to node during presubmit, and all files and nodes will only be visited once. Also adding these fixes https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2370103 Fix: - Pass the fullpath for comparison.(itemPath) - Normalize comparison between paths - using native fs.promises instead of promisify (https://github.com/nodejs/node/pull/26581) Bug: 1116989 Change-Id: I054040d83a65b5f798a21c040096422e287bc799 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2381320 Reviewed-by: Vidal Diazleal <vidorteg@microsoft.com> Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Simon Zünd <szuend@chromium.org> Commit-Queue: Christy Chen <chrche@microsoft.com>
90 lines
2.9 KiB
Python
Executable File
90 lines
2.9 KiB
Python
Executable File
#!/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.
|
|
|
|
import argparse
|
|
import os.path as path
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
|
|
scripts_path = path.dirname(path.dirname(path.abspath(__file__)))
|
|
sys.path.append(scripts_path)
|
|
import devtools_paths
|
|
|
|
devtools_path = devtools_paths.devtools_root_path()
|
|
|
|
|
|
def parse_options(cli_args):
|
|
parser = argparse.ArgumentParser(description='Process localization check arguments.')
|
|
parser.add_argument('--all', '-a', action='store_true', dest='all_files', help='If present, check all devtools frontend .js files')
|
|
parser.add_argument('--files', nargs='+', help='List of .js files with absolute paths separated by a space')
|
|
parser.add_argument('--file-list', dest='file_list', help='Specifies a file with a list of files (one per line)')
|
|
parser.add_argument(
|
|
'--autofix', action='store_true', help='If present, errors in localizable resources will be fixed automatically')
|
|
args = parser.parse_args(cli_args)
|
|
|
|
if len(cli_args) == 0:
|
|
print('No argument provided. Assuming --all to check all files.')
|
|
args.all_files = True
|
|
|
|
if args.all_files and args.files:
|
|
parser.error(
|
|
"Please provide only one option for scanning files: --all for all files or --files <FILE_LIST> for specific files.")
|
|
return args
|
|
|
|
|
|
def popen(arguments, cwd=None):
|
|
return subprocess.Popen(arguments, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
|
|
|
def check_with_node_script(script_path, script_description, args):
|
|
print(script_description + "...")
|
|
script_proc_errors_found = False
|
|
exec_command = [
|
|
devtools_paths.node_path(),
|
|
script_path,
|
|
] + args
|
|
|
|
script_proc = popen(exec_command)
|
|
(script_proc_out, _) = script_proc.communicate()
|
|
if script_proc.returncode != 0:
|
|
script_proc_errors_found = True
|
|
|
|
print(script_proc_out)
|
|
return script_proc_errors_found
|
|
|
|
|
|
def show_result(errors):
|
|
if errors:
|
|
print('Check failed (see above)')
|
|
sys.exit(1)
|
|
else:
|
|
print('Check succeeded')
|
|
|
|
|
|
def check_devtools_localizable_resources(
|
|
check_devtools_localizable_resources_args):
|
|
script_path = devtools_paths.check_localizable_resources_path()
|
|
script_description = 'Verifying all resources are localizable and checking the structure of grd files'
|
|
return check_with_node_script(script_path, script_description, check_devtools_localizable_resources_args)
|
|
|
|
|
|
def main():
|
|
check_devtools_localizable_resources_args = []
|
|
|
|
parsed_args = parse_options(sys.argv[1:])
|
|
|
|
if parsed_args.autofix:
|
|
check_devtools_localizable_resources_args = ['--autofix']
|
|
|
|
resources_errors_found_localizable = check_devtools_localizable_resources(
|
|
check_devtools_localizable_resources_args)
|
|
show_result(resources_errors_found_localizable)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|