Refactor import_inline into brave_chromium_utils (#21482)
* Rename import_inline -> brave_chromium_utils. * Add inline_chromium_src_override helper. * Remove inline_file_from_src. * Add typing info into brave_chromium_utils. * Format and fix sys_path usage. * Scan all overridable files in check_chromium_src.py. * Replace another occurence of the hardcoded path in the error message. * Move get_gn_arg to brave_chromium_utils. * Update patches after cr121 rebase.
This commit is contained in:
+11
-12
@@ -8,10 +8,9 @@ import copy
|
||||
import os
|
||||
import sys
|
||||
|
||||
import brave_chromium_utils
|
||||
import brave_node
|
||||
import chromium_presubmit_overrides
|
||||
import git_cl
|
||||
import import_inline
|
||||
import override_utils
|
||||
|
||||
USE_PYTHON3 = True
|
||||
@@ -78,6 +77,10 @@ def CheckPatchFormatted(input_api, output_api):
|
||||
# Pass a path where the current PRESUBMIT.py file is located.
|
||||
git_cl_format_cmd.append(input_api.PresubmitLocalPath())
|
||||
|
||||
with brave_chromium_utils.sys_path("//brave/vendor/depot_tools"):
|
||||
# pylint: disable=import-outside-toplevel
|
||||
import git_cl
|
||||
|
||||
# Run git cl format and get return code.
|
||||
git_cl_format_code, _ = git_cl.RunGitWithCode(git_cl_format_cmd)
|
||||
if git_cl_format_code not in (0, 2):
|
||||
@@ -148,9 +151,7 @@ def CheckESLint(input_api, output_api):
|
||||
files_to_check = input_api.AffectedFiles(file_filter=file_filter,
|
||||
include_deletes=False)
|
||||
|
||||
with import_inline.sys_path(
|
||||
input_api.os_path.join(input_api.PresubmitLocalPath(), '..',
|
||||
'tools')):
|
||||
with brave_chromium_utils.sys_path('//tools'):
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from web_dev_style import js_checker
|
||||
return js_checker.JSChecker(input_api,
|
||||
@@ -158,9 +159,7 @@ def CheckESLint(input_api, output_api):
|
||||
|
||||
|
||||
def CheckWebDevStyle(input_api, output_api):
|
||||
with import_inline.sys_path(
|
||||
input_api.os_path.join(input_api.PresubmitLocalPath(), '..',
|
||||
'tools')):
|
||||
with brave_chromium_utils.sys_path('//tools'):
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from web_dev_style import presubmit_support, js_checker
|
||||
# Disable RunEsLintChecks, it's run separately in CheckESLint.
|
||||
@@ -288,6 +287,8 @@ def CheckLicense(input_api, output_api):
|
||||
chromium_presubmit_overrides.inline_presubmit('//PRESUBMIT.py', globals(),
|
||||
locals())
|
||||
|
||||
# pyright: reportUnboundVariable=false, reportUndefinedVariable=false
|
||||
|
||||
_BANNED_CPP_FUNCTIONS += (
|
||||
BanRule(
|
||||
r'/\b(Basic|W)?StringPiece(16)?\b',
|
||||
@@ -409,11 +410,9 @@ def CheckJavaStyle(_original_check, input_api, output_api):
|
||||
if not sys.platform.startswith('linux'):
|
||||
return []
|
||||
|
||||
with import_inline.sys_path(
|
||||
input_api.os_path.join(input_api.PresubmitLocalPath(), 'tools',
|
||||
'android')):
|
||||
with brave_chromium_utils.sys_path('//tools/android/checkstyle'):
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from checkstyle import checkstyle
|
||||
import checkstyle
|
||||
|
||||
files_to_skip = input_api.DEFAULT_FILES_TO_SKIP
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
# You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
import brave_chromium_utils
|
||||
import chromium_presubmit_overrides
|
||||
import import_inline
|
||||
|
||||
USE_PYTHON3 = True
|
||||
PRESUBMIT_VERSION = '2.0.0'
|
||||
@@ -49,11 +49,9 @@ def CheckOverriddenHeadersDeclareIWYUExport(input_api, output_api):
|
||||
|
||||
def CheckOverrides(input_api, output_api):
|
||||
items = []
|
||||
with import_inline.sys_path(
|
||||
input_api.os_path.join(input_api.PresubmitLocalPath(), '..',
|
||||
'tools')):
|
||||
with brave_chromium_utils.sys_path('//brave/tools/chromium_src'):
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from chromium_src import check_chromium_src
|
||||
import check_chromium_src
|
||||
overrides = [
|
||||
f.AbsoluteLocalPath() for f in input_api.AffectedSourceFiles(None)
|
||||
]
|
||||
|
||||
@@ -6,23 +6,18 @@
|
||||
".*\\.clangd",
|
||||
".*\\.gn",
|
||||
".*\\.gni",
|
||||
".*\\.idl",
|
||||
".*\\.in",
|
||||
".*\\.info",
|
||||
".*\\.json",
|
||||
".*\\.json5",
|
||||
".*\\.mojom",
|
||||
".*\\.pdl",
|
||||
".*\\.py",
|
||||
".*\\.pyc",
|
||||
".*\\.xml",
|
||||
"(.*/)?DEPS",
|
||||
"python_modules/.*",
|
||||
],
|
||||
|
||||
// Files matching these exact paths will be excluded.
|
||||
// Please, keep in alphabetical order.
|
||||
"path_excludes": [
|
||||
"base/feature_override.h",
|
||||
"check_chromium_src_config.json5",
|
||||
"chrome/browser/devtools/url_constants_unittest.cc",
|
||||
"chrome/browser/history/history_utils_unittest.cc",
|
||||
"chrome/browser/notifications/notification_handler_impl.h",
|
||||
|
||||
@@ -13,7 +13,7 @@ from os.path import join
|
||||
|
||||
import override_utils
|
||||
|
||||
from import_inline import get_src_dir
|
||||
from brave_chromium_utils import get_src_dir
|
||||
from sign_binaries import sign_binaries
|
||||
|
||||
|
||||
|
||||
+7
-12
@@ -3,24 +3,19 @@
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
# You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import os.path
|
||||
import re
|
||||
import sys
|
||||
|
||||
import brave_chromium_utils
|
||||
import override_utils
|
||||
|
||||
# We patch the upstream script to inline this file, so the path reported by
|
||||
# __file__ will be the path of the upstream script.
|
||||
SCRIPTS_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||
sys.path.insert(1, SCRIPTS_DIR)
|
||||
|
||||
from bind_gen.code_node import SymbolNode, TextNode
|
||||
from bind_gen.codegen_accumulator import CodeGenAccumulator
|
||||
from bind_gen.codegen_context import CodeGenContext
|
||||
from bind_gen.codegen_format import format_template as _format
|
||||
# pylint: disable=relative-beyond-top-level
|
||||
from .code_node import SymbolNode, TextNode
|
||||
from .codegen_accumulator import CodeGenAccumulator
|
||||
from .codegen_context import CodeGenContext
|
||||
from .codegen_format import format_template as _format
|
||||
|
||||
# Get gn arg to enable WebAPI probes.
|
||||
_IS_PG_WEBAPI_PROBES_ENABLED = override_utils.get_gn_arg(
|
||||
_IS_PG_WEBAPI_PROBES_ENABLED = brave_chromium_utils.get_gn_arg(
|
||||
"enable_brave_page_graph_webapi_probes")
|
||||
|
||||
# Workaround attribute to set when is_observable_array codegen is active. This
|
||||
|
||||
+3
-2
@@ -3,14 +3,15 @@
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
# You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import brave_chromium_utils
|
||||
import override_utils
|
||||
|
||||
# pylint: disable=line-too-long
|
||||
|
||||
# Get gn arg to enable PageGraph.
|
||||
_IS_PG_ENABLED = override_utils.get_gn_arg("enable_brave_page_graph")
|
||||
_IS_PG_ENABLED = brave_chromium_utils.get_gn_arg("enable_brave_page_graph")
|
||||
# Get gn arg to enable WebAPI probes.
|
||||
_IS_PG_WEBAPI_PROBES_ENABLED = override_utils.get_gn_arg(
|
||||
_IS_PG_WEBAPI_PROBES_ENABLED = brave_chromium_utils.get_gn_arg(
|
||||
"enable_brave_page_graph_webapi_probes")
|
||||
|
||||
|
||||
|
||||
+3
-5
@@ -7,7 +7,7 @@ import os
|
||||
import re
|
||||
import pprint
|
||||
|
||||
import import_inline
|
||||
import brave_chromium_utils
|
||||
import override_utils
|
||||
|
||||
_original_parse = parse
|
||||
@@ -58,10 +58,8 @@ def _merge_commands(extended_domain, protocol_domain):
|
||||
|
||||
|
||||
def _merge_protocol(protocol, file_name):
|
||||
file_name = os.path.abspath(file_name)
|
||||
src_dir = import_inline.get_src_dir()
|
||||
chromium_src_file = os.path.join(src_dir, 'brave', 'chromium_src',
|
||||
file_name[len(src_dir) + 1:])
|
||||
chromium_src_file = brave_chromium_utils.get_chromium_src_override(
|
||||
file_name)
|
||||
if not os.path.exists(chromium_src_file):
|
||||
return
|
||||
with open(chromium_src_file, "r") as input_file:
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
# pylint: disable=line-too-long
|
||||
|
||||
import import_inline
|
||||
import brave_chromium_utils
|
||||
import override_utils
|
||||
|
||||
|
||||
@@ -35,8 +35,9 @@ class BraveFeatureDefinitionExtender:
|
||||
if not has_counterpart:
|
||||
return None
|
||||
|
||||
with open(import_inline.wspath(f"//brave/chromium_src/{source_file}"),
|
||||
"r") as f:
|
||||
with open(
|
||||
brave_chromium_utils.wspath(
|
||||
f"//brave/chromium_src/{source_file}"), "r") as f:
|
||||
parsed_json = json_parse.Parse(f.read())
|
||||
return parsed_json
|
||||
|
||||
@@ -45,21 +46,20 @@ class BraveFeatureDefinitionExtender:
|
||||
if has_counterpart is None:
|
||||
raise RuntimeError(
|
||||
f"Unknown features file {source_file}. Please update "
|
||||
"//brave/chromium_src/tools/json_schema_compiler/feature_compiler.py"
|
||||
)
|
||||
f"{brave_chromium_utils.get_chromium_src_override(__file__)}")
|
||||
return has_counterpart
|
||||
|
||||
def _ValidateKnownFiles(self):
|
||||
for source_file, should_exist in self.KNOWN_FILES.items():
|
||||
# Ensure original file exists.
|
||||
original_filepath = import_inline.wspath(f"//{source_file}")
|
||||
original_filepath = brave_chromium_utils.wspath(f"//{source_file}")
|
||||
if not os.path.exists(original_filepath):
|
||||
raise RuntimeError(
|
||||
f"Original features file {original_filepath} not found. Please update "
|
||||
"//brave/chromium_src/tools/json_schema_compiler/feature_compiler.py"
|
||||
f"{brave_chromium_utils.get_chromium_src_override(__file__)}"
|
||||
)
|
||||
# Ensure override file exists if it has to.
|
||||
overridden_filepath = import_inline.wspath(
|
||||
overridden_filepath = brave_chromium_utils.wspath(
|
||||
f"//brave/chromium_src/{source_file}")
|
||||
assert should_exist == os.path.exists(
|
||||
overridden_filepath), overridden_filepath
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
# You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import import_inline
|
||||
from brave_chromium_utils import inline_file
|
||||
|
||||
import_inline.inline_file_from_src(
|
||||
"chrome/installer/util/prebuild/create_installer_string_rc.py", globals(),
|
||||
locals())
|
||||
inline_file("//chrome/installer/util/prebuild/create_installer_string_rc.py",
|
||||
globals(), locals())
|
||||
|
||||
MODE_SPECIFIC_STRINGS = {
|
||||
'IDS_APP_SHORTCUTS_SUBDIR_NAME': {
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
# You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import import_inline
|
||||
from brave_chromium_utils import inline_file
|
||||
|
||||
import_inline.inline_file_from_src(
|
||||
"chrome/installer/util/prebuild/create_installer_string_rc.py", globals(),
|
||||
locals())
|
||||
inline_file("//chrome/installer/util/prebuild/create_installer_string_rc.py",
|
||||
globals(), locals())
|
||||
|
||||
MODE_SPECIFIC_STRINGS = {
|
||||
'IDS_APP_SHORTCUTS_SUBDIR_NAME': {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
diff --git a/build/android/gradle/generate_gradle.py b/build/android/gradle/generate_gradle.py
|
||||
index f6dce230f4609e53e55d453bed50e8d6e60d3e96..4fb51148c69fdbbd7a3adbb9637e883cebf92890 100755
|
||||
index f6dce230f4609e53e55d453bed50e8d6e60d3e96..1f6b7212c5f524fbe04bc0af4a882b960a47947c 100755
|
||||
--- a/build/android/gradle/generate_gradle.py
|
||||
+++ b/build/android/gradle/generate_gradle.py
|
||||
@@ -938,5 +938,6 @@ def main():
|
||||
'+/main/docs/android_studio.md')
|
||||
|
||||
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/build/android/gradle/generate_gradle.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
diff --git a/build/util/action_remote.py b/build/util/action_remote.py
|
||||
index 040d5118ffe822f265e3c9ce13896682302c96ee..e638d0b14895e2954157d712b32221b21a04321f 100755
|
||||
index 040d5118ffe822f265e3c9ce13896682302c96ee..e7bd51a3c415c2f6015835d8ed8ef0a77bfaa28d 100755
|
||||
--- a/build/util/action_remote.py
|
||||
+++ b/build/util/action_remote.py
|
||||
@@ -99,6 +99,7 @@ def _get_mojom_parser_inputs(exec_root, output_files, extra_args):
|
||||
processed_inputs)
|
||||
|
||||
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/build/util/action_remote.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
def main():
|
||||
# Set up argparser with some rewrapper flags.
|
||||
argparser = argparse.ArgumentParser(description='rewrapper executor for gn',
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
diff --git a/buildtools/checkdeps/checkdeps.py b/buildtools/checkdeps/checkdeps.py
|
||||
index 19e0854786de291fd9c94ac64dbbe181faee6180..02d4dc0cbe6fa8c759b5964dc425bbd5fb42775e 100755
|
||||
index 19e0854786de291fd9c94ac64dbbe181faee6180..55e02d2aee620da2312c0d41e5965ea828fc471b 100755
|
||||
--- a/buildtools/checkdeps/checkdeps.py
|
||||
+++ b/buildtools/checkdeps/checkdeps.py
|
||||
@@ -290,5 +290,6 @@ def main():
|
||||
return deps_checker.Report()
|
||||
|
||||
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/buildtools/checkdeps/checkdeps.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
if '__main__' == __name__:
|
||||
sys.exit(main())
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
diff --git a/chrome/tools/build/win/create_installer_archive.py b/chrome/tools/build/win/create_installer_archive.py
|
||||
index 56d34d12c48cb90316cc3411dac23b2bae921a67..6b010359e892d3b97569fab5c2b0ca217dc0a06d 100755
|
||||
index 56d34d12c48cb90316cc3411dac23b2bae921a67..98f45e15ab2317c92405526de5eb1f1175d949cd 100755
|
||||
--- a/chrome/tools/build/win/create_installer_archive.py
|
||||
+++ b/chrome/tools/build/win/create_installer_archive.py
|
||||
@@ -676,6 +676,7 @@ def _ParseOptions():
|
||||
@@ -14,7 +14,7 @@ index 56d34d12c48cb90316cc3411dac23b2bae921a67..6b010359e892d3b97569fab5c2b0ca21
|
||||
|
||||
return options
|
||||
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/chrome/tools/build/win/create_installer_archive.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
|
||||
if '__main__' == __name__:
|
||||
options = _ParseOptions()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
diff --git a/components/policy/tools/template_writers/writer_configuration.py b/components/policy/tools/template_writers/writer_configuration.py
|
||||
index 8cb77158561d326b1640adef8ebf6031f7389d08..6bc460b0a44830afaffd1f7e26d744f1b9aed80d 100755
|
||||
index 8cb77158561d326b1640adef8ebf6031f7389d08..0ed1d6a757dbfdbb880db1ecb398c194f185e79d 100755
|
||||
--- a/components/policy/tools/template_writers/writer_configuration.py
|
||||
+++ b/components/policy/tools/template_writers/writer_configuration.py
|
||||
@@ -132,3 +132,4 @@ def GetConfigurationForBuild(defines):
|
||||
config['mac_bundle_id'] = defines['mac_bundle_id']
|
||||
config['android_webview_restriction_prefix'] = 'com.android.browser:'
|
||||
return config
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/components/policy/tools/template_writers/writer_configuration.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
diff --git a/components/vector_icons/aggregate_vector_icons.py b/components/vector_icons/aggregate_vector_icons.py
|
||||
index 3e5a94a7f053ffc66f1a820073265cbfe1332b39..fe2065a020661fc59807a39b968e7673fd247f5c 100644
|
||||
index 3e5a94a7f053ffc66f1a820073265cbfe1332b39..cdd7f33b20f747aa093ce2e0d1462baa86c0fe21 100644
|
||||
--- a/components/vector_icons/aggregate_vector_icons.py
|
||||
+++ b/components/vector_icons/aggregate_vector_icons.py
|
||||
@@ -102,7 +102,7 @@ def ExtractIconReps(icon_file_name):
|
||||
@@ -48,7 +48,7 @@ index 3e5a94a7f053ffc66f1a820073265cbfe1332b39..fe2065a020661fc59807a39b968e7673
|
||||
output_cc.close()
|
||||
|
||||
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src('brave/chromium_src/components/vector_icons/aggregate_vector_icons.py', globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
def main():
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option("--working_directory",
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
diff --git a/mojo/public/tools/mojom/mojom_parser.py b/mojo/public/tools/mojom/mojom_parser.py
|
||||
index 9693090e44ea4bff0c8d0259a4bdf7c1b0ba0b77..811fc49983cb212829902fa51718dfb6c772e082 100755
|
||||
index 9693090e44ea4bff0c8d0259a4bdf7c1b0ba0b77..8785606744dad5dbc49410b9f96d9c2b3a2068ae 100755
|
||||
--- a/mojo/public/tools/mojom/mojom_parser.py
|
||||
+++ b/mojo/public/tools/mojom/mojom_parser.py
|
||||
@@ -492,6 +492,7 @@ already present in the provided output root.""")
|
||||
logging.info('Finished')
|
||||
|
||||
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/mojo/public/tools/mojom/mojom_parser.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
if __name__ == '__main__':
|
||||
Run(sys.argv[1:])
|
||||
# Exit without running GC, which can save multiple seconds due to the large
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
diff --git a/third_party/blink/renderer/bindings/scripts/bind_gen/interface.py b/third_party/blink/renderer/bindings/scripts/bind_gen/interface.py
|
||||
index 6b67a896f0bca44e0476af5f242d1b94ca989e32..93d41f6100291b09de1d205461432b0f18d55b6b 100644
|
||||
index 6b67a896f0bca44e0476af5f242d1b94ca989e32..c70975e5cb9e07e95c44d8bbf6060adb420bd18b 100644
|
||||
--- a/third_party/blink/renderer/bindings/scripts/bind_gen/interface.py
|
||||
+++ b/third_party/blink/renderer/bindings/scripts/bind_gen/interface.py
|
||||
@@ -7493,3 +7493,4 @@ def generate_interfaces(task_queue):
|
||||
"InitIDLInterfacesForTesting",
|
||||
"init_idl_interfaces_for_testing",
|
||||
for_testing=True)
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/third_party/blink/renderer/bindings/scripts/bind_gen/interface.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
\ No newline at end of file
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
diff --git a/third_party/blink/renderer/build/scripts/make_instrumenting_probes.py b/third_party/blink/renderer/build/scripts/make_instrumenting_probes.py
|
||||
index dc76ba59292e4052bf596dbc45caf07ee7661362..1054bbdca5b4e3400b999afdc82612cfe9522883 100644
|
||||
index dc76ba59292e4052bf596dbc45caf07ee7661362..a1a2340b4ec63f6fd1724465938f0a81aa3bd6c4 100644
|
||||
--- a/third_party/blink/renderer/build/scripts/make_instrumenting_probes.py
|
||||
+++ b/third_party/blink/renderer/build/scripts/make_instrumenting_probes.py
|
||||
@@ -307,5 +307,6 @@ def main():
|
||||
h_file.close()
|
||||
|
||||
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/third_party/blink/renderer/build/scripts/make_instrumenting_probes.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
diff --git a/third_party/inspector_protocol/pdl.py b/third_party/inspector_protocol/pdl.py
|
||||
index 6b448c07443c7e440b5a951b63b4e7e706bdcd5c..7385d46d842b00b3a98e13faa0df49f7ed4a0e02 100644
|
||||
index 6b448c07443c7e440b5a951b63b4e7e706bdcd5c..9fadb5fdc3686d74c7ecc11257710dd0fafcffa8 100644
|
||||
--- a/third_party/inspector_protocol/pdl.py
|
||||
+++ b/third_party/inspector_protocol/pdl.py
|
||||
@@ -179,3 +179,4 @@ def loads(data, file_name, map_binary_to_string=False):
|
||||
if file_name.endswith(".pdl"):
|
||||
return parse(data, file_name, map_binary_to_string)
|
||||
return json.loads(data)
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/third_party/inspector_protocol/pdl.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
diff --git a/common/py_utils/py_utils/discover.py b/common/py_utils/py_utils/discover.py
|
||||
index 7eac0c545a85345f972e1de15f2c2306ba43ff75..8126acc29ec161f39f0bbea66802be53868c0353 100644
|
||||
index 7eac0c545a85345f972e1de15f2c2306ba43ff75..f719c26d87559066a64eec1a7c261b5f423d80cb 100644
|
||||
--- a/common/py_utils/py_utils/discover.py
|
||||
+++ b/common/py_utils/py_utils/discover.py
|
||||
@@ -189,3 +189,4 @@ _COUNTER = [0]
|
||||
def _GetUniqueModuleName():
|
||||
_COUNTER[0] += 1
|
||||
return "module_" + str(_COUNTER[0])
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/third_party/catapult/common/py_utils/py_utils/discover.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
diff --git a/telemetry/telemetry/internal/backends/android_browser_backend_settings.py b/telemetry/telemetry/internal/backends/android_browser_backend_settings.py
|
||||
index b2749323b85f49f85036981897d58e8be851593a..b06e5edab41206370c5ec983bb6a8ee0e4cc39e5 100644
|
||||
index b2749323b85f49f85036981897d58e8be851593a..59752aee4e792e285cc7452c1f41f932fa73be17 100644
|
||||
--- a/telemetry/telemetry/internal/backends/android_browser_backend_settings.py
|
||||
+++ b/telemetry/telemetry/internal/backends/android_browser_backend_settings.py
|
||||
@@ -468,3 +468,4 @@ ANDROID_BACKEND_SETTINGS = (
|
||||
ANDROID_CHROME_CANARY,
|
||||
ANDROID_SYSTEM_CHROME
|
||||
)
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/third_party/catapult/telemetry/telemetry/internal/backends/android_browser_backend_settings.py", globals(), locals());
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
diff --git a/tools/clang/pylib/clang/compile_db.py b/tools/clang/pylib/clang/compile_db.py
|
||||
index 06bb1da03ffa5243c3cde9ef7b2f1a36b5eccb5d..aaa00c88f6a6b999cb2fb476551d4701e7db767d 100755
|
||||
index 06bb1da03ffa5243c3cde9ef7b2f1a36b5eccb5d..aa58f572ecdb56d10ef89a97f02c766bb5e9d911 100755
|
||||
--- a/tools/clang/pylib/clang/compile_db.py
|
||||
+++ b/tools/clang/pylib/clang/compile_db.py
|
||||
@@ -224,3 +224,4 @@ def Read(path):
|
||||
"""
|
||||
with open(os.path.join(path, 'compile_commands.json'), 'rb') as db:
|
||||
return json.load(db)
|
||||
+import os, sys; sys.path.append(os.path.join(os.path.dirname(__file__), *[os.pardir] * 4, 'brave', 'script')); from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/tools/clang/pylib/clang/compile_db.py", globals(), locals())
|
||||
+import os, sys; sys.path.append(os.path.join(os.path.dirname(__file__), *[os.pardir] * 4, 'brave', 'script')); from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
diff --git a/tools/grit/grit/gather/policy_json.py b/tools/grit/grit/gather/policy_json.py
|
||||
index c708c0a037b01d6a6517ab6022a579fdb29c607f..3a01e545e55fa9096601c0e1d5899e1013ffdb44 100644
|
||||
index c708c0a037b01d6a6517ab6022a579fdb29c607f..de2ca976e0ca2e5ae0bc4b0f034bfd3449304f4a 100644
|
||||
--- a/tools/grit/grit/gather/policy_json.py
|
||||
+++ b/tools/grit/grit/gather/policy_json.py
|
||||
@@ -350,3 +350,4 @@ class PolicyJson(skeleton_gatherer.SkeletonGatherer):
|
||||
}
|
||||
else:
|
||||
raise Exception('Unknown build')
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/tools/grit/grit/gather/policy_json.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
diff --git a/tools/json_schema_compiler/feature_compiler.py b/tools/json_schema_compiler/feature_compiler.py
|
||||
index cd8faa30d7b2c37c5d87ebcb5412db765371e39a..7d1942511a4f4e8c80baa53b82cb338e47a2db2f 100644
|
||||
index cd8faa30d7b2c37c5d87ebcb5412db765371e39a..49f921020e0741bb132cb57408ef689c2164feef 100644
|
||||
--- a/tools/json_schema_compiler/feature_compiler.py
|
||||
+++ b/tools/json_schema_compiler/feature_compiler.py
|
||||
@@ -969,6 +969,7 @@ class FeatureCompiler(object):
|
||||
cc_file.Concat(cc_end)
|
||||
f.write(cc_file.Render().strip())
|
||||
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/tools/json_schema_compiler/feature_compiler.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Compile json feature files')
|
||||
parser.add_argument('chrome_root', type=str,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
diff --git a/tools/perf/benchmarks/system_health.py b/tools/perf/benchmarks/system_health.py
|
||||
index b5d11fb82029d5db007b18d72da03d4bcd357de0..9fd46d179a95c8cd6982da0006fe41b4933802ee 100644
|
||||
index b5d11fb82029d5db007b18d72da03d4bcd357de0..d615a4861c9082737b3fd541c343fe49d47f3460 100644
|
||||
--- a/tools/perf/benchmarks/system_health.py
|
||||
+++ b/tools/perf/benchmarks/system_health.py
|
||||
@@ -261,3 +261,4 @@ class WebviewStartupSystemHealthBenchmark(perf_benchmark.PerfBenchmark):
|
||||
@classmethod
|
||||
def Name(cls):
|
||||
return 'system_health.webview_startup'
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/tools/perf/benchmarks/system_health.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
diff --git a/tools/perf/core/perf_benchmark.py b/tools/perf/core/perf_benchmark.py
|
||||
index 2da4191c86d584a578d821863ee482abb85c20d0..0512f8cdf20e6b39d078b24df027feaa10661cbf 100644
|
||||
index 2da4191c86d584a578d821863ee482abb85c20d0..709390317a56ca04707c9d9baefa4ea45f7cfd28 100644
|
||||
--- a/tools/perf/core/perf_benchmark.py
|
||||
+++ b/tools/perf/core/perf_benchmark.py
|
||||
@@ -211,3 +211,4 @@ class PerfBenchmark(benchmark.Benchmark):
|
||||
if 'XVFB_DISPLAY' in os.environ:
|
||||
return True
|
||||
return False
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/tools/perf/core/perf_benchmark.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
diff --git a/tools/perf/core/results_dashboard.py b/tools/perf/core/results_dashboard.py
|
||||
index d9d262b836877a4e39c9c3481c68aa08f1eb5796..4b2f14378d26a3e7dd2bc869bca73f1ef7e6fe06 100755
|
||||
index d9d262b836877a4e39c9c3481c68aa08f1eb5796..9034695561a275e3703b0f922376aeb3ee2bf2a4 100755
|
||||
--- a/tools/perf/core/results_dashboard.py
|
||||
+++ b/tools/perf/core/results_dashboard.py
|
||||
@@ -507,3 +507,4 @@ def _SendHistogramJson(url, histogramset_json, token_generator_callback):
|
||||
logging.info('Upload completion token created. Token id: %s' % token)
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
logging.warning('Error fetching upload completion token: %s' % e)
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/tools/perf/core/results_dashboard.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
diff --git a/tools/symsrc/source_index.py b/tools/symsrc/source_index.py
|
||||
index d23e2f22d3379eb03314a909c4e16194a53c8626..915e51caf915fc91cbf986fec68477aa6b571618 100755
|
||||
index d23e2f22d3379eb03314a909c4e16194a53c8626..92b79a7d1a6ec8623b28bc1f30a360810666d9a8 100755
|
||||
--- a/tools/symsrc/source_index.py
|
||||
+++ b/tools/symsrc/source_index.py
|
||||
@@ -600,5 +600,6 @@ def main():
|
||||
return 0
|
||||
|
||||
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/tools/symsrc/source_index.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
diff --git a/tools/typescript/ts_library.py b/tools/typescript/ts_library.py
|
||||
index bce222f243c30b9b5a19ed1de3461b492b577ba2..2a00d03c42b6e8b81900c536a5e2ad374e1fab55 100644
|
||||
index bce222f243c30b9b5a19ed1de3461b492b577ba2..dd6819156ec91362749391aa340ed4d43ea97cfe 100644
|
||||
--- a/tools/typescript/ts_library.py
|
||||
+++ b/tools/typescript/ts_library.py
|
||||
@@ -279,5 +279,6 @@ def main(argv):
|
||||
json.dump(manifest_data, manifest_file)
|
||||
|
||||
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/tools/typescript/ts_library.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv[1:])
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
diff --git a/tools/web_dev_style/eslint.py b/tools/web_dev_style/eslint.py
|
||||
index 18be4f4b076888f18538323096e84d52a8659a5c..e29cc0173d69cb9ff5d972b7c210bf25714b5049 100755
|
||||
index 18be4f4b076888f18538323096e84d52a8659a5c..f719b65aec6b0d01cdb620be23c41ec73da8c280 100755
|
||||
--- a/tools/web_dev_style/eslint.py
|
||||
+++ b/tools/web_dev_style/eslint.py
|
||||
@@ -26,6 +26,7 @@ def Run(os_path=None, args=None):
|
||||
] + args)
|
||||
|
||||
|
||||
+from import_inline import inline_file_from_src; inline_file_from_src("brave/chromium_src/tools/web_dev_style/eslint.py", globals(), locals())
|
||||
+from brave_chromium_utils import inline_chromium_src_override; inline_chromium_src_override(globals(), locals())
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
# Copyright (c) 2022 The Brave Authors. All rights reserved.
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
# You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
import contextlib
|
||||
import functools
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=None)
|
||||
def get_src_dir() -> str:
|
||||
"""Searches for src/ dir which includes brave/ dir."""
|
||||
current_file = globals().get('__file__')
|
||||
if current_file:
|
||||
current_dir = os.path.dirname(os.path.abspath(current_file))
|
||||
else:
|
||||
current_dir = os.getcwd()
|
||||
while True:
|
||||
if os.path.basename(current_dir) == 'src' and os.path.isdir(
|
||||
os.path.join(current_dir, 'brave')):
|
||||
return current_dir
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
if parent_dir == current_dir:
|
||||
# We hit the system root directory.
|
||||
raise RuntimeError("Can't find src/ directory")
|
||||
current_dir = parent_dir
|
||||
|
||||
|
||||
def wspath(path: str) -> str:
|
||||
"""Convert workspace path to OS path. Examples:
|
||||
|
||||
`//chrome/file.txt` -> `/home/user/brave_checkout/src/chrome/file.txt`
|
||||
`//chrome/file.txt` -> `C:\\brave_checkout\\src\\chrome\\file.txt`
|
||||
"""
|
||||
assert isinstance(path, str)
|
||||
|
||||
if path.startswith('//'):
|
||||
path = os.path.join(get_src_dir(), path[2:])
|
||||
|
||||
# Normalize path separators.
|
||||
return os.path.normpath(path)
|
||||
|
||||
|
||||
def get_chromium_src_override(path: str) -> str:
|
||||
"""Convert path into `//brave/chromium_src` override path."""
|
||||
assert path, path
|
||||
if not os.path.isabs(path):
|
||||
path = os.path.abspath(path)
|
||||
assert os.path.exists(path), path
|
||||
src_dir = get_src_dir()
|
||||
assert path.startswith(src_dir), (path, src_dir)
|
||||
src_path = path[len(src_dir) + 1:]
|
||||
return wspath(f'//brave/chromium_src/{src_path}')
|
||||
|
||||
|
||||
def inline_file(path: str, _globals: Dict[str, Any],
|
||||
_locals: Dict[str, Any]) -> None:
|
||||
"""Inline file from `path` by executing it using `_globals` and `_locals`
|
||||
scopes."""
|
||||
path = wspath(path)
|
||||
with open(path, "r") as f:
|
||||
# Compile first to set the location explicitly. This makes stacktrace to
|
||||
# show the actual filename instead of '<string>'.
|
||||
code = compile(f.read(), path, 'exec')
|
||||
# pylint: disable=exec-used
|
||||
exec(code, _globals, _locals)
|
||||
|
||||
|
||||
def inline_chromium_src_override(_globals: Dict[str, Any],
|
||||
_locals: Dict[str, Any]) -> None:
|
||||
"""Inline `__file__` override from `//brave/chromium_src`."""
|
||||
orig_file = _globals.get('__file__')
|
||||
if not orig_file:
|
||||
raise RuntimeError(
|
||||
'__file__ is not set to inline from //brave/chromium_src. '
|
||||
'Use inline_file() with full path instead.')
|
||||
chromium_src_override = get_chromium_src_override(orig_file)
|
||||
inline_file(chromium_src_override, _globals, _locals)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def sys_path(path: str, position: Optional[int] = None):
|
||||
path = wspath(path)
|
||||
path_exists = path in sys.path
|
||||
if not path_exists:
|
||||
if position is None:
|
||||
sys.path.append(path)
|
||||
else:
|
||||
sys.path.insert(position, path)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
if not path_exists:
|
||||
if sys.path[-1] == path:
|
||||
sys.path.pop()
|
||||
else:
|
||||
sys.path.remove(path)
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=None)
|
||||
def get_gn_args(output_dir: str) -> Dict[str, Any]:
|
||||
"""Return parsed `args.gn` from `output_dir`."""
|
||||
ARGS_GN = "args.gn"
|
||||
args_gn_filename = os.path.join(output_dir, ARGS_GN)
|
||||
if not os.path.exists(args_gn_filename):
|
||||
raise FileNotFoundError(f"{ARGS_GN} not found in {output_dir}")
|
||||
|
||||
with sys_path('//build'):
|
||||
import gn_helpers # pylint: disable=import-outside-toplevel
|
||||
with open(args_gn_filename, "r") as f:
|
||||
return gn_helpers.FromGNArgs(f.read())
|
||||
|
||||
|
||||
def get_gn_arg(arg: str, output_dir=os.getcwd()) -> Any:
|
||||
"""Return GN arg from `args.gn` in `output_dir`."""
|
||||
|
||||
gn_arg = get_gn_args(output_dir).get(arg)
|
||||
if gn_arg is None:
|
||||
raise RuntimeError(
|
||||
f"Python-checked gn arg should be explicitly set during gn gen: "
|
||||
f"{arg} gn arg not found")
|
||||
|
||||
return gn_arg
|
||||
@@ -12,8 +12,8 @@ import os
|
||||
import re
|
||||
import traceback
|
||||
|
||||
import brave_chromium_utils
|
||||
import override_utils
|
||||
import import_inline
|
||||
|
||||
# pylint: disable=line-too-long,protected-access,unused-variable
|
||||
|
||||
@@ -22,12 +22,13 @@ CANNED_CHECKS_KEY = 'canned'
|
||||
|
||||
# Helper to load json5 presubmit config.
|
||||
def load_presubmit_config():
|
||||
with import_inline.sys_path('//third_party/pyjson5/src'):
|
||||
# pylint: disable=import-outside-toplevel,import-error
|
||||
with brave_chromium_utils.sys_path('//third_party/pyjson5/src'):
|
||||
# pylint: disable=import-outside-toplevel
|
||||
import json5
|
||||
return json5.load(
|
||||
open(import_inline.wspath(
|
||||
'//brave/chromium_presubmit_config.json5')))
|
||||
open(
|
||||
brave_chromium_utils.wspath(
|
||||
'//brave/chromium_presubmit_config.json5')))
|
||||
|
||||
|
||||
config = load_presubmit_config()
|
||||
@@ -187,7 +188,8 @@ def setup_per_check_file_filter(input_api):
|
||||
def inline_presubmit(filename, _globals, _locals):
|
||||
class State:
|
||||
def __init__(self, filename):
|
||||
self.presubmit_dir = os.path.dirname(import_inline.wspath(filename))
|
||||
self.presubmit_dir = os.path.dirname(
|
||||
brave_chromium_utils.wspath(filename))
|
||||
self.orig_cwd = os.getcwd()
|
||||
self.orig_presubmit_dir = ''
|
||||
|
||||
@@ -211,7 +213,7 @@ def inline_presubmit(filename, _globals, _locals):
|
||||
assert pre_check_name not in _globals
|
||||
_globals[pre_check_name] = PreRunChecks
|
||||
|
||||
import_inline.inline_file(filename, _globals, _locals)
|
||||
brave_chromium_utils.inline_file(filename, _globals, _locals)
|
||||
apply_generic_check_overrides(_globals, filename, True)
|
||||
|
||||
def PostRunChecks(input_api, _output_api):
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
# Copyright (c) 2022 The Brave Authors. All rights reserved.
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
# You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import contextlib
|
||||
import functools
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=None)
|
||||
def get_src_dir() -> str:
|
||||
"""Searches for src/ dir which includes brave/ dir."""
|
||||
current_file = globals().get('__file__')
|
||||
if current_file:
|
||||
current_dir = os.path.dirname(os.path.abspath(current_file))
|
||||
else:
|
||||
current_dir = os.getcwd()
|
||||
while True:
|
||||
if os.path.basename(current_dir) == 'src' and os.path.isdir(
|
||||
os.path.join(current_dir, 'brave')):
|
||||
return current_dir
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
if parent_dir == current_dir:
|
||||
# We hit the system root directory.
|
||||
raise RuntimeError("Can't find src/ directory")
|
||||
current_dir = parent_dir
|
||||
|
||||
|
||||
# Returns OS path from workspace path (//brave/path/file.py).
|
||||
def wspath(path: str) -> str:
|
||||
assert isinstance(path, str)
|
||||
|
||||
if path.startswith('//'):
|
||||
path = os.path.join(get_src_dir(), path[2:])
|
||||
|
||||
# Normalize path separators.
|
||||
return os.path.normpath(path)
|
||||
|
||||
|
||||
# Inline file by executing it using passed scopes.
|
||||
def inline_file(path: str, _globals, _locals):
|
||||
path = wspath(path)
|
||||
with open(path, "r") as f:
|
||||
# Compile first to set the location explicitly. This makes stacktrace to
|
||||
# show the actual filename instead of '<string>'.
|
||||
code = compile(f.read(), path, 'exec')
|
||||
# pylint: disable=exec-used
|
||||
exec(code, _globals, _locals)
|
||||
|
||||
|
||||
# Locate src/ dir and inline relative file by executing it using passed scopes.
|
||||
def inline_file_from_src(path: str, _globals, _locals):
|
||||
inline_file(f"//{path}", _globals, _locals)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def sys_path(path: str, position=None):
|
||||
path = wspath(path)
|
||||
path_exists = path in sys.path
|
||||
if not path_exists:
|
||||
if position is None:
|
||||
sys.path.append(path)
|
||||
else:
|
||||
sys.path.insert(position, path)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
if not path_exists:
|
||||
if sys.path[-1] == path:
|
||||
sys.path.pop()
|
||||
else:
|
||||
sys.path.remove(path)
|
||||
@@ -6,9 +6,9 @@
|
||||
import contextlib
|
||||
import inspect
|
||||
import types
|
||||
import os
|
||||
|
||||
_gn_args = None
|
||||
from typing import Any
|
||||
|
||||
|
||||
def override_function(scope, name=None, condition=True):
|
||||
"""Replaces an existing function in the scope."""
|
||||
@@ -47,7 +47,7 @@ def override_method(scope, name=None, condition=True):
|
||||
def decorator(new_method):
|
||||
assert not isinstance(scope, dict)
|
||||
method_name = name or new_method.__name__
|
||||
original_method = getattr(scope, method_name, None)
|
||||
original_method: Any = getattr(scope, method_name, None)
|
||||
|
||||
if not condition:
|
||||
wrapped_method = original_method
|
||||
@@ -117,8 +117,7 @@ def override_scope_variable(scope,
|
||||
var_exist = hasattr(scope, name)
|
||||
if fail_if_not_found and not var_exist:
|
||||
raise NameError(f'Failed to override scope variable: {name} not found')
|
||||
if var_exist:
|
||||
original_value = getattr(scope, name)
|
||||
original_value = getattr(scope, name) if var_exist else None
|
||||
try:
|
||||
setattr(scope, name, value)
|
||||
yield
|
||||
@@ -127,23 +126,3 @@ def override_scope_variable(scope,
|
||||
setattr(scope, name, original_value)
|
||||
else:
|
||||
delattr(scope, name)
|
||||
|
||||
|
||||
def get_gn_arg(arg, output_dir=os.getcwd()):
|
||||
"""Returns GN arg from args.gn in output_dir."""
|
||||
global _gn_args # pylint: disable=global-statement
|
||||
if _gn_args is None:
|
||||
ARGS_GN = "args.gn"
|
||||
args_gn_filename = os.path.join(output_dir, ARGS_GN)
|
||||
if not os.path.exists(args_gn_filename):
|
||||
raise FileNotFoundError(f"{ARGS_GN} not found in {output_dir}")
|
||||
with open(args_gn_filename, "r") as f:
|
||||
import gn_helpers # pylint: disable=import-outside-toplevel
|
||||
_gn_args = gn_helpers.FromGNArgs(f.read())
|
||||
|
||||
if arg not in _gn_args:
|
||||
raise RuntimeError(
|
||||
f"Python-checked gn arg should be explicitly set during gn gen: "
|
||||
f"{arg} gn arg not found")
|
||||
|
||||
return _gn_args[arg]
|
||||
|
||||
Vendored
+2
-2
@@ -1,3 +1,3 @@
|
||||
# Inline upstream rules.
|
||||
from import_inline import inline_file_from_src
|
||||
inline_file_from_src('third_party/blink/renderer/DEPS', globals(), locals())
|
||||
from brave_chromium_utils import inline_file
|
||||
inline_file('//third_party/blink/renderer/DEPS', globals(), locals())
|
||||
|
||||
Vendored
+2
-2
@@ -1,3 +1,3 @@
|
||||
# Inline upstream rules.
|
||||
from import_inline import inline_file_from_src
|
||||
inline_file_from_src('third_party/blink/renderer/core/DEPS', globals(), locals())
|
||||
from brave_chromium_utils import inline_file
|
||||
inline_file('//third_party/blink/renderer/core/DEPS', globals(), locals())
|
||||
|
||||
+2
-2
@@ -1,3 +1,3 @@
|
||||
# Inline upstream rules.
|
||||
from import_inline import inline_file_from_src
|
||||
inline_file_from_src('third_party/blink/renderer/platform/DEPS', globals(), locals())
|
||||
from brave_chromium_utils import inline_file
|
||||
inline_file('//third_party/blink/renderer/platform/DEPS', globals(), locals())
|
||||
|
||||
@@ -57,7 +57,7 @@ def merge_rewrapper_cfg(rewrapper_cfg, tool, _host_os):
|
||||
'inputs': [
|
||||
('{src_dir}/buildtools/reclient_cfgs/python/'
|
||||
'python_remote_wrapper'),
|
||||
'{src_dir}/brave/script/import_inline.py',
|
||||
'{src_dir}/brave/script/brave_chromium_utils.py',
|
||||
'{src_dir}/brave/script/override_utils.py',
|
||||
],
|
||||
'remote_wrapper': ('{src_dir}/buildtools/reclient_cfgs/'
|
||||
|
||||
@@ -8,7 +8,7 @@ from os import getcwd
|
||||
from os.path import basename, dirname
|
||||
from subprocess import check_call
|
||||
|
||||
from import_inline import sys_path
|
||||
from brave_chromium_utils import sys_path
|
||||
|
||||
with sys_path('//chrome/tools/build/win'):
|
||||
import create_installer_archive as upstream_impl
|
||||
|
||||
Reference in New Issue
Block a user