0

Android: presubmit check against IS_DESKTOP_ANDROID

No change to production behavior. This adds a presubmit check for
IS_DESKTOP_ANDROID. The goal is to confine use of this value to chrome/
layer and other higher layers, but to ban this in content/ layer and
below.

This has "warning" status only so that it can be bypassed in case of
false positive, however the intention is that generally
IS_DESKTOP_ANDROID should only live in higher layers.

Fixed: 401628399
Test: vpython3 PRESUBMIT_test.py
Change-Id: Ice010be105a476100acf5cf70a3d262228916c33
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6336803
Reviewed-by: Dirk Pranke <dpranke@google.com>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1431159}
This commit is contained in:
Nate Fischer
2025-03-11 14:34:19 -07:00
committed by Chromium LUCI CQ
parent 4068f7c84c
commit d541ff839b
2 changed files with 46 additions and 0 deletions

@ -299,6 +299,24 @@ _BANNED_JAVA_FUNCTIONS : Sequence[BanRule] = (
' for more details and suggested replacements.', ),
False,
),
BanRule(
pattern=(r'IS_DESKTOP_ANDROID'),
explanation=(
'Features which depend on IS_DESKTOP_ANDROID should only exist in '
'chrome/ layer and similar layers. Lower layers such as content/ '
'should not have features which are only designed for '
'desktop-android builds. See https://crbug.com/401628399.', ),
treat_as_error=False,
excluded_paths=[
_THIRD_PARTY_EXCEPT_BLINK, # Don't warn in third_party folders.
r'^build/', # This is permitted in build/ folder.
r'^chrome/', # This is permitted in chrome/ folder.
r'^components/', # This is permitted only for components/ that are not shared by WebView.
r'^extensions/', # This is permitted in chrome/ folder.
r'^infra/', # This is permitted in infra/ folder.
r'^tools/', # This is permitted in tools/ folder.
],
),
)
_BANNED_JAVASCRIPT_FUNCTIONS : Sequence [BanRule] = (
@ -2163,6 +2181,24 @@ _BANNED_CPP_FUNCTIONS: Sequence[BanRule] = (
'See https://crbug.com/40485510 for more details.', ),
treat_as_error=False,
),
BanRule(
pattern=(r'IS_DESKTOP_ANDROID'),
explanation=(
'Features which depend on IS_DESKTOP_ANDROID should only exist in '
'chrome/ layer and similar layers. Lower layers such as content/ '
'should not have features which are only designed for '
'desktop-android builds. See https://crbug.com/401628399.', ),
treat_as_error=False,
excluded_paths=[
_THIRD_PARTY_EXCEPT_BLINK, # Don't warn in third_party folders.
r'^build/', # This is permitted in build/ folder.
r'^chrome/', # This is permitted in chrome/ folder.
r'^components/', # This is permitted only for components/ that are not shared by WebView.
r'^extensions/', # This is permitted in chrome/ folder.
r'^infra/', # This is permitted in infra/ folder.
r'^tools/', # This is permitted in tools/ folder.
],
),
)
_DEPRECATED_SYNC_CONSENT_FUNCTION_WARNING = (

@ -2972,6 +2972,10 @@ class BannedTypeCheckTest(unittest.TestCase):
'some/java/problematic/accessibilityTypeAnnouncement.java', [
'accessibilityEvent.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT);'
]),
MockFile(
'content/java/problematic/desktopandroid.java', [
'if (BuildConfig.IS_DESKTOP_ANDROID) {}'
]),
]
errors = PRESUBMIT.CheckNoBannedFunctions(input_api, MockOutputApi())
@ -3001,6 +3005,9 @@ class BannedTypeCheckTest(unittest.TestCase):
self.assertTrue(
'some/java/problematic/accessibilityTypeAnnouncement.java' in
errors[0].message)
self.assertTrue(
'content/java/problematic/desktopandroid.java' in
errors[0].message)
def testBannedCppFunctions(self):
@ -3029,6 +3036,8 @@ class BannedTypeCheckTest(unittest.TestCase):
MockFile('banned_ranges_usage.cc',
['std::ranges::subrange(first, last)']),
MockFile('views_usage.cc', ['std::views::all(vec)']),
MockFile('content/desktop_android.cc',
['#if BUILDFLAG(IS_DESKTOP_ANDROID)']),
]
results = PRESUBMIT.CheckNoBannedFunctions(input_api, MockOutputApi())
@ -3051,6 +3060,7 @@ class BannedTypeCheckTest(unittest.TestCase):
self.assertFalse('allowed_ranges_usage.cc' in results[1].message)
self.assertTrue('banned_ranges_usage.cc' in results[1].message)
self.assertTrue('views_usage.cc' in results[1].message)
self.assertTrue('content/desktop_android.cc' in results[0].message)
def testBannedCppRandomFunctions(self):
banned_rngs = [