
Python2 has been considered obsolete since 2020-01-01. Some Linux distributions are increasingly moving away from installing a Python2 binary in `/usr/bin/python`, which means that any Unix shebang lines that refer to it will stop working. This CL changes (almost) all of the shebang lines found in chromium/src to use `#!/usr/bin/env python` instead, which is more portable (it allows you to have your own Python as long as it is simply somewhere in $PATH). There are a few cases where I did not update the changes because they were in third_party code. The actual command used to generate this CL was: git grep -l '^#!\s*/usr/bin/python$' -- \*.py | egrep -v 'external/wpt|third_party/(abseil-cpp|android_platform|libxml|closure_compiler|google_input_tools|libxml|mako|opus|protobuf|wpt_tools|zxcvbn-cpp)' | xargs perl -pi -e 's-^#!/usr/bin/python-#!/usr/bin/env python-' Bug: 1191100 Change-Id: Ifca134a1e24d56b25114c6f70a173d71fec8e6d5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2780719 Commit-Queue: Dirk Pranke <dpranke@google.com> Reviewed-by: Nico Weber <thakis@chromium.org> Reviewed-by: Kentaro Hara <haraken@chromium.org> Owners-Override: Kentaro Hara <haraken@chromium.org> Owners-Override: Nico Weber <thakis@chromium.org> Cr-Commit-Position: refs/heads/master@{#866002}
216 lines
6.4 KiB
Python
Executable File
216 lines
6.4 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# Copyright 2020 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.
|
|
"""Tests for mb_validate.py."""
|
|
|
|
from __future__ import print_function
|
|
from __future__ import absolute_import
|
|
|
|
import sys
|
|
import ast
|
|
import os
|
|
import unittest
|
|
|
|
sys.path.insert(0, os.path.join(
|
|
os.path.dirname(os.path.abspath(__file__)), '..'))
|
|
|
|
from mb import mb
|
|
from mb import mb_unittest
|
|
from mb.lib import validation
|
|
|
|
TEST_UNREFERENCED_MIXIN_CONFIG = """\
|
|
{
|
|
'public_artifact_builders': {},
|
|
'configs': {
|
|
'rel_bot_1': ['rel'],
|
|
'rel_bot_2': ['rel'],
|
|
},
|
|
'builder_groups': {
|
|
'fake_builder_group_a': {
|
|
'fake_builder_a': 'rel_bot_1',
|
|
'fake_builder_b': 'rel_bot_2',
|
|
},
|
|
},
|
|
'mixins': {
|
|
'unreferenced_mixin': {
|
|
'gn_args': 'proprietary_codecs=true',
|
|
},
|
|
'rel': {
|
|
'gn_args': 'is_debug=false',
|
|
},
|
|
},
|
|
}
|
|
"""
|
|
|
|
TEST_UNKNOWNMIXIN_CONFIG = """\
|
|
{
|
|
'public_artifact_builders': {},
|
|
'configs': {
|
|
'rel_bot_1': ['rel'],
|
|
'rel_bot_2': ['rel', 'unknown_mixin'],
|
|
},
|
|
'builder_groups': {
|
|
'fake_builder_group_a': {
|
|
'fake_builder_a': 'rel_bot_1',
|
|
'fake_builder_b': 'rel_bot_2',
|
|
},
|
|
},
|
|
'mixins': {
|
|
'rel': {
|
|
'gn_args': 'is_debug=false',
|
|
},
|
|
},
|
|
}
|
|
"""
|
|
|
|
TEST_UNKNOWN_NESTED_MIXIN_CONFIG = """\
|
|
{
|
|
'public_artifact_builders': {},
|
|
'configs': {
|
|
'rel_bot_1': ['rel', 'nested_mixin'],
|
|
'rel_bot_2': ['rel'],
|
|
},
|
|
'builder_groups': {
|
|
'fake_builder_group_a': {
|
|
'fake_builder_a': 'rel_bot_1',
|
|
'fake_builder_b': 'rel_bot_2',
|
|
},
|
|
},
|
|
'mixins': {
|
|
'nested_mixin': {
|
|
'mixins': {
|
|
'unknown_mixin': {
|
|
'gn_args': 'proprietary_codecs=true',
|
|
},
|
|
},
|
|
},
|
|
'rel': {
|
|
'gn_args': 'is_debug=false',
|
|
},
|
|
},
|
|
}
|
|
"""
|
|
|
|
|
|
class UnitTest(unittest.TestCase):
|
|
def test_GetAllConfigs(self):
|
|
configs = ast.literal_eval(mb_unittest.TEST_CONFIG)
|
|
all_configs = validation.GetAllConfigs(configs['builder_groups'])
|
|
self.assertEqual(all_configs['rel_bot'], 'fake_builder_group')
|
|
self.assertEqual(all_configs['debug_goma'], 'fake_builder_group')
|
|
|
|
def test_CheckAllConfigsAndMixinsReferenced_ok(self):
|
|
configs = ast.literal_eval(mb_unittest.TEST_CONFIG)
|
|
errs = []
|
|
all_configs = validation.GetAllConfigs(configs['builder_groups'])
|
|
config_configs = configs['configs']
|
|
mixins = configs['mixins']
|
|
|
|
validation.CheckAllConfigsAndMixinsReferenced(errs, all_configs,
|
|
config_configs, mixins)
|
|
|
|
self.assertEqual(errs, [])
|
|
|
|
def test_CheckAllConfigsAndMixinsReferenced_unreferenced(self):
|
|
configs = ast.literal_eval(TEST_UNREFERENCED_MIXIN_CONFIG)
|
|
errs = []
|
|
all_configs = validation.GetAllConfigs(configs['builder_groups'])
|
|
config_configs = configs['configs']
|
|
mixins = configs['mixins']
|
|
|
|
validation.CheckAllConfigsAndMixinsReferenced(errs, all_configs,
|
|
config_configs, mixins)
|
|
|
|
self.assertIn('Unreferenced mixin "unreferenced_mixin".', errs)
|
|
|
|
def test_CheckAllConfigsAndMixinsReferenced_unknown(self):
|
|
configs = ast.literal_eval(TEST_UNKNOWNMIXIN_CONFIG)
|
|
errs = []
|
|
all_configs = validation.GetAllConfigs(configs['builder_groups'])
|
|
config_configs = configs['configs']
|
|
mixins = configs['mixins']
|
|
|
|
validation.CheckAllConfigsAndMixinsReferenced(errs, all_configs,
|
|
config_configs, mixins)
|
|
self.assertIn(
|
|
'Unknown mixin "unknown_mixin" '
|
|
'referenced by config "rel_bot_2".', errs)
|
|
|
|
def test_CheckAllConfigsAndMixinsReferenced_unknown_nested(self):
|
|
configs = ast.literal_eval(TEST_UNKNOWN_NESTED_MIXIN_CONFIG)
|
|
errs = []
|
|
all_configs = validation.GetAllConfigs(configs['builder_groups'])
|
|
config_configs = configs['configs']
|
|
mixins = configs['mixins']
|
|
|
|
validation.CheckAllConfigsAndMixinsReferenced(errs, all_configs,
|
|
config_configs, mixins)
|
|
|
|
self.assertIn(
|
|
'Unknown mixin "unknown_mixin" '
|
|
'referenced by mixin "nested_mixin".', errs)
|
|
|
|
def test_CheckAllConfigsAndMixinsReferenced_unused(self):
|
|
configs = ast.literal_eval(TEST_UNKNOWN_NESTED_MIXIN_CONFIG)
|
|
errs = []
|
|
all_configs = validation.GetAllConfigs(configs['builder_groups'])
|
|
config_configs = configs['configs']
|
|
mixins = configs['mixins']
|
|
|
|
validation.CheckAllConfigsAndMixinsReferenced(errs, all_configs,
|
|
config_configs, mixins)
|
|
|
|
self.assertIn(
|
|
'Unknown mixin "unknown_mixin" '
|
|
'referenced by mixin "nested_mixin".', errs)
|
|
|
|
def test_EnsureNoProprietaryMixins(self):
|
|
bad_configs = ast.literal_eval(mb_unittest.TEST_BAD_CONFIG)
|
|
errs = []
|
|
builder_groups = bad_configs['builder_groups']
|
|
mixins = bad_configs['mixins']
|
|
config_configs = bad_configs['configs']
|
|
|
|
validation.EnsureNoProprietaryMixins(errs, builder_groups, config_configs,
|
|
mixins)
|
|
|
|
self.assertIn(
|
|
'Public artifact builder "a" '
|
|
'can not contain the "chrome_with_codecs" mixin.', errs)
|
|
self.assertIn(
|
|
'Public artifact builder "b" '
|
|
'can not contain the "chrome_with_codecs" mixin.', errs)
|
|
self.assertEqual(len(errs), 2)
|
|
|
|
def test_CheckDuplicateConfigs_ok(self):
|
|
configs = ast.literal_eval(mb_unittest.TEST_CONFIG)
|
|
config_configs = configs['configs']
|
|
mixins = configs['mixins']
|
|
grouping = configs['builder_groups']
|
|
errs = []
|
|
|
|
validation.CheckDuplicateConfigs(errs, config_configs, mixins, grouping,
|
|
mb.FlattenConfig)
|
|
self.assertEqual(errs, [])
|
|
|
|
@unittest.skip('bla')
|
|
def test_CheckDuplicateConfigs_dups(self):
|
|
configs = ast.literal_eval(mb_unittest.TEST_DUP_CONFIG)
|
|
config_configs = configs['configs']
|
|
mixins = configs['mixins']
|
|
grouping = configs['builder_groups']
|
|
errs = []
|
|
|
|
validation.CheckDuplicateConfigs(errs, config_configs, mixins, grouping,
|
|
mb.FlattenConfig)
|
|
self.assertIn(
|
|
'Duplicate configs detected. When evaluated fully, the '
|
|
'following configs are all equivalent: \'some_config\', '
|
|
'\'some_other_config\'. Please consolidate these configs '
|
|
'into only one unique name per configuration value.', errs)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|