Fixed CheckSettingsChanges presubmit function (#34666)
* Fixed `CheckSettingsChanges` presubmit function There were two problems: 1. Somehow the `registry_full_path` misses segments `chrome` and `android` when accessing `SearchIndexProviderRegistry.java`, so it is `.../brave-browser/src/java/src/org/chromium/chrome/browser/settings/search/SearchIndexProviderRegistry.java` instead of an actual `.../brave-browser/src/chrome/android/java/src/org/chromium/chrome/browser/settings/search/SearchIndexProviderRegistry.java` which causes the registry not being read 2. `input_api.ReadFile` could not read outside of repo root which is `brave-browser/src/brave` so it could not read `SearchIndexProviderRegistry.java` Fixed both with patching or chromium_presubmit_overrides.py Resolves https://github.com/brave/brave-browser/issues/53560
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
|
||||
index 00f85840ae075b43d7503f386a221f7037f40503..1f077c67a3d9e54ecbd3f766e9c18a0bf16c7f20 100644
|
||||
--- a/PRESUBMIT.py
|
||||
+++ b/PRESUBMIT.py
|
||||
@@ -8207,6 +8207,7 @@ def CheckSettingsChanges(input_api, output_api):
|
||||
relevant_files_found = False
|
||||
registry_content = ''
|
||||
registry_full_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
|
||||
+ "chrome", "android",
|
||||
registry_path)
|
||||
|
||||
try:
|
||||
@@ -100,6 +100,7 @@ def modify_input_api(input_api):
|
||||
*config['additional_default_files_to_check'], )
|
||||
override_canned_checks(input_api.canned_checks)
|
||||
setup_per_check_file_filter(input_api)
|
||||
setup_read_file_override(input_api)
|
||||
|
||||
|
||||
# Disables checks or forces presubmit errors for checks listed in the config.
|
||||
@@ -185,6 +186,46 @@ def setup_per_check_file_filter(input_api):
|
||||
return self._cached_changed_contents[:]
|
||||
|
||||
|
||||
def setup_read_file_override(input_api):
|
||||
|
||||
@override_utils.override_method(input_api)
|
||||
def ReadFile(_self, original_method, file_item, mode='r'):
|
||||
|
||||
def is_affected_file_inside_chromium_repo(_self, file_item):
|
||||
if isinstance(file_item, input_api.change._AFFECTED_FILES):
|
||||
file_item = file_item.AbsoluteLocalPath()
|
||||
|
||||
from pathlib import Path
|
||||
repo_root = Path(_self.change.RepositoryRoot())
|
||||
|
||||
if (repo_root.name == "brave" and repo_root.parent.name == "src"
|
||||
and file_item.startswith(str(repo_root.parent))):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
try:
|
||||
return original_method(file_item, mode)
|
||||
except IOError as io_error:
|
||||
# We want to pass over the exception of reading
|
||||
# reading anything outside the repository from InputApi.ReadFile.
|
||||
# So just re-throw as is any other exception
|
||||
if (str(io_error)
|
||||
!= 'Access outside the repository root is denied.'):
|
||||
raise
|
||||
|
||||
# We are here because of the original input_api.ReadFile
|
||||
# behaviour. When the RepositoryRoot() is brave-browser/src/brave -
|
||||
# it doesn't allow us to access brave-browser/src .
|
||||
# But in fact we are ok to read from brave-browser/src
|
||||
if is_affected_file_inside_chromium_repo(_self, file_item):
|
||||
import gclient_utils
|
||||
return gclient_utils.FileRead(file_item, 'r')
|
||||
|
||||
# Give up, we are even outside brave-browser/src
|
||||
raise
|
||||
|
||||
|
||||
# Inlines presubmit file as if it was run from the dir where it's located.
|
||||
def inline_presubmit(filename, _globals, _locals):
|
||||
class State:
|
||||
|
||||
Reference in New Issue
Block a user