Commit a4561e70 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Disallow OS_APPLE in chrome/.

OS_APPLE means OS_MAC or OS_IOS. Since OS_IOS is disallowed in chrome/,
it makes more sense to use OS_MAC in chrome/ instead of OS_APPLE.

Replace existing OS_APPLE usage with OS_MAC, and add a presubmit to
check for OS_APPLE usage.

Change-Id: I539f062f5f82a93dcbd861501421977e4f027517
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2365434Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800196}
parent b62c28be
......@@ -63,6 +63,34 @@ def _CheckNoContentUnitTestsInChrome(input_api, output_api):
items=problems)]
def _CheckNoOSAPPLEMacrosInChromeFile(input_api, f):
"""Check for OS_APPLE in a given file in chrome/."""
preprocessor_statement = input_api.re.compile(r'^\s*#')
apple_macro = input_api.re.compile(r'defined\(OS_APPLE\)')
results = []
for lnum, line in f.ChangedContents():
if preprocessor_statement.search(line) and apple_macro.search(line):
results.append(' %s:%d' % (f.LocalPath(), lnum))
return results
def _CheckNoOSAPPLEMacrosInChrome(input_api, output_api):
"""Check for OS_APPLE which isn't used in chrome/."""
apple_macros = []
def SourceFilter(affected_file):
return input_api.FilterSourceFile(affected_file, INCLUDE_SOURCE_FILES_ONLY,
input_api.DEFAULT_FILES_TO_SKIP)
for f in input_api.AffectedSourceFiles(SourceFilter):
apple_macros.extend(_CheckNoOSAPPLEMacrosInChromeFile(input_api, f))
if not apple_macros:
return []
return [output_api.PresubmitError(
'OS_APPLE is not used in chrome/ but found in:\n', apple_macros)]
def _CheckNoOSIOSMacrosInChromeFile(input_api, f):
"""Check for OS_IOS in a given file in chrome/."""
preprocessor_statement = input_api.re.compile(r'^\s*#')
......@@ -95,6 +123,7 @@ def _CommonChecks(input_api, output_api):
"""Checks common to both upload and commit."""
results = []
results.extend(_CheckNoContentUnitTestsInChrome(input_api, output_api))
results.extend(_CheckNoOSAPPLEMacrosInChrome(input_api, output_api))
results.extend(_CheckNoOSIOSMacrosInChrome(input_api, output_api))
return results
......
......@@ -13,6 +13,15 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from PRESUBMIT_test_mocks import MockFile, MockInputApi
class InvalidOSMacroNamesTest(unittest.TestCase):
def testChromeDoesNotUseOSAPPLE(self):
lines = ['#if defined(OS_APPLE)',
'#error OS_APPLE not allowed',
'#endif']
errors = PRESUBMIT._CheckNoOSAPPLEMacrosInChromeFile(
MockInputApi(), MockFile('chrome/path/foo_platform.cc', lines))
self.assertEqual(1, len(errors))
self.assertEqual(' chrome/path/foo_platform.cc:1', errors[0])
def testChromeDoesNotUseOSIOS(self):
lines = ['#if defined(OS_IOS)',
'#error OS_IOS not allowed',
......@@ -22,6 +31,5 @@ class InvalidOSMacroNamesTest(unittest.TestCase):
self.assertEqual(1, len(errors))
self.assertEqual(' chrome/path/foo_platform.cc:1', errors[0])
if __name__ == '__main__':
unittest.main()
......@@ -5658,7 +5658,7 @@ const FeatureEntry kFeatureEntries[] = {
FEATURE_VALUE_TYPE(
password_manager::features::kEnablePasswordsAccountStorage)},
#if defined(OS_WIN) || defined(OS_APPLE) || defined(OS_LINUX) || \
#if defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX) || \
defined(OS_CHROMEOS)
{"passwords-account-storage-iph",
flag_descriptions::kEnablePasswordsAccountStorageIPHName,
......@@ -5666,7 +5666,7 @@ const FeatureEntry kFeatureEntries[] = {
kOsWin | kOsMac | kOsLinux,
FEATURE_VALUE_TYPE(
feature_engagement::kIPHPasswordsAccountStorageFeature)},
#endif // defined(OS_WIN) || defined(OS_APPLE) || defined(OS_LINUX) ||
#endif // defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX) ||
// defined(OS_CHROMEOS)
{"autofill-always-return-cloud-tokenized-card",
......
......@@ -16,7 +16,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#elif defined(OS_WIN) || defined(OS_APPLE)
#elif defined(OS_WIN) || defined(OS_MAC)
#include "base/enterprise_util.h"
#endif
......@@ -88,7 +88,7 @@ bool IsEnterpriseManaged() {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
return connector->IsEnterpriseManaged();
#elif defined(OS_WIN) || defined(OS_APPLE)
#elif defined(OS_WIN) || defined(OS_MAC)
return base::IsMachineExternallyManaged();
#else
return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment