Skip to content

Commit

Permalink
Revert of Add a presubmit check that warns about declaring Singleton<…
Browse files Browse the repository at this point in the history
…T> in header files (patchset chromium#2 id:20001 of https://codereview.chromium.org/929043002/)

Reason for revert:
Reverting because of presubmit crashes:

Traceback (most recent call last):
  File "/usr/local/google/ssd/depot_tools/git_cl.py", line 2983, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/usr/local/google/ssd/depot_tools/git_cl.py", line 2969, in main
    return dispatcher.execute(OptionParser(), argv)
  File "/usr/local/google/ssd/depot_tools/subcommand.py", line 245, in execute
    return command(parser, args[1:])
  File "/usr/local/google/ssd/depot_tools/git_cl.py", line 1614, in CMDpresubmit
    change=cl.GetChange(base_branch, None))
  File "/usr/local/google/ssd/depot_tools/git_cl.py", line 936, in RunHook
    rietveld_obj=self.RpcServer())
  File "/usr/local/google/ssd/depot_tools/presubmit_support.py", line 1396, in DoPresubmitChecks
    results += executer.ExecPresubmitScript(presubmit_script, filename)
  File "/usr/local/google/ssd/depot_tools/presubmit_support.py", line 1313, in ExecPresubmitScript
    result = eval(function_name + '(*__args)', context)
  File "<string>", line 1, in <module>
  File "<string>", line 1727, in CheckChangeOnCommit
  File "<string>", line 1455, in _CommonChecks
  File "<string>", line 1322, in _CheckSingletonInHeaders
  File "/usr/local/google/ssd/depot_tools/presubmit_support.py", line 472, in ReadFile
    raise IOError('Access outside the repository root is denied.')
IOError: Access outside the repository root is denied.

Original issue's description:
> Add a presubmit check that warns about declaring Singleton<T> in header files
> (except for base/memory/singleton.h)
> This check is copied from presubmit_canned_checks.py in depot_tools/ with an
> added exception for base/memory/singleton.h.
> The corresponding code will be removed from presubmit_canned_checks.py afterwards.
>
> BUG=349861
> R=phajdan.jr@chromium.org,
>
> Committed: https://crrev.com/9b73d0393037452d13358f4e2766cb62adbdede8
> Cr-Commit-Position: refs/heads/master@{#316546}

TBR=phajdan.jr@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=349861

Review URL: https://codereview.chromium.org/934723003

Cr-Commit-Position: refs/heads/master@{#316559}
  • Loading branch information
glider authored and Commit bot committed Feb 17, 2015
1 parent 749a85c commit 99aac94
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 61 deletions.
31 changes: 0 additions & 31 deletions PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -1305,36 +1305,6 @@ def _CheckForCopyrightedCode(input_api, output_api):
return copyright_scanner.ScanAtPresubmit(input_api, output_api)


def _CheckSingletonInHeaders(input_api, output_api):
"""Checks to make sure no header files have |Singleton<|."""
def FileFilter(affected_file):
# It's ok for base/memory/singleton.h to have |Singleton<|.
black_list = (_EXCLUDED_PATHS +
input_api.DEFAULT_BLACK_LIST +
(r"^base[\\\/]memory[\\\/]singleton\.h$",))
return input_api.FilterSourceFile(affected_file, black_list=black_list)

pattern = input_api.re.compile(r'(?<!class\s)Singleton\s*<')
files = []
for f in input_api.AffectedSourceFiles(FileFilter):
if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or
f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')):
contents = input_api.ReadFile(f.LocalPath())
for line in contents.splitlines(False):
if (not input_api.re.match(r'//', line) and # Strip C++ comment.
pattern.search(line)):
files.append(f)
break

if files:
return [ output_api.PresubmitError(
'Found Singleton<T> in the following header files.\n' +
'Please move them to an appropriate source file so that the ' +
'template gets instantiated in a single compilation unit.',
files) ]
return []


_DEPRECATED_CSS = [
# Values
( "-webkit-box", "flex" ),
Expand Down Expand Up @@ -1452,7 +1422,6 @@ def _CommonChecks(input_api, output_api):
results.extend(_CheckForIPCRules(input_api, output_api))
results.extend(_CheckForCopyrightedCode(input_api, output_api))
results.extend(_CheckForWindowsLineEndings(input_api, output_api))
results.extend(_CheckSingletonInHeaders(input_api, output_api))

if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
Expand Down
27 changes: 0 additions & 27 deletions PRESUBMIT_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,33 +384,6 @@ def testOnlyOwnersFiles(self):
self.assertEqual({}, results)


class CheckSingletonInHeadersTest(unittest.TestCase):
def testSingletonInArbitraryHeader(self):
diff_singleton_h = ['base::subtle::AtomicWord '
'Singleton<Type, Traits, DifferentiatingType>::']
diff_foo_h = ['// Singleton<Foo> in comment.',
'friend class Singleton<Foo>']
diff_bad_h = ['Foo* foo = Singleton<Foo>::get();']
mock_input_api = MockInputApi()
mock_input_api.files = [MockFile('base/memory/singleton.h',
diff_singleton_h),
MockFile('foo.h', diff_foo_h),
MockFile('bad.h', diff_bad_h)]
warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api,
MockOutputApi())
self.assertEqual(1, len(warnings))
self.assertEqual('error', warnings[0].type)
self.assertTrue('Found Singleton<T>' in warnings[0].message)

def testSingletonInCC(self):
diff_cc = ['Foo* foo = Singleton<Foo>::get();']
mock_input_api = MockInputApi()
mock_input_api.files = [MockFile('some/path/foo.cc', diff_cc)]
warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api,
MockOutputApi())
self.assertEqual(0, len(warnings))


class InvalidOSMacroNamesTest(unittest.TestCase):
def testInvalidOSMacroNames(self):
lines = ['#if defined(OS_WINDOWS)',
Expand Down
3 changes: 0 additions & 3 deletions PRESUBMIT_test_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ def __init__(self):
def AffectedFiles(self, file_filter=None):
return self.files

def AffectedSourceFiles(self, file_filter=None):
return self.files

def PresubmitLocalPath(self):
return os.path.dirname(__file__)

Expand Down

0 comments on commit 99aac94

Please sign in to comment.