2013-06-24 09:03:48 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2017-12-18 16:22:51 +00:00
|
|
|
import argparse
|
2013-06-24 09:03:48 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2017-12-18 16:22:51 +00:00
|
|
|
from lib.config import enable_verbose_mode
|
2014-02-26 14:08:01 +00:00
|
|
|
from lib.util import execute
|
|
|
|
|
2017-12-20 00:37:02 +00:00
|
|
|
IGNORE_FILES = set(os.path.join(*components) for components in [
|
|
|
|
['atom', 'browser', 'mac', 'atom_application.h'],
|
|
|
|
['atom', 'browser', 'mac', 'atom_application_delegate.h'],
|
|
|
|
['atom', 'browser', 'resources', 'win', 'resource.h'],
|
|
|
|
['atom', 'browser', 'ui', 'cocoa', 'atom_menu_controller.h'],
|
|
|
|
['atom', 'browser', 'ui', 'cocoa', 'atom_touch_bar.h'],
|
|
|
|
['atom', 'browser', 'ui', 'cocoa', 'touch_bar_forward_declarations.h'],
|
|
|
|
['atom', 'browser', 'ui', 'cocoa', 'NSColor+Hex.h'],
|
|
|
|
['atom', 'browser', 'ui', 'cocoa', 'NSString+ANSI.h'],
|
|
|
|
['atom', 'common', 'api', 'api_messages.h'],
|
|
|
|
['atom', 'common', 'common_message_generator.cc'],
|
|
|
|
['atom', 'common', 'common_message_generator.h'],
|
|
|
|
['atom', 'node', 'osfhandle.cc'],
|
|
|
|
['brightray', 'browser', 'mac', 'bry_inspectable_web_contents_view.h'],
|
|
|
|
['brightray', 'browser', 'mac', 'event_dispatching_window.h'],
|
|
|
|
['brightray', 'browser', 'mac', 'notification_center_delegate.h'],
|
|
|
|
['brightray', 'browser', 'win', 'notification_presenter_win7.h'],
|
|
|
|
['brightray', 'browser', 'win', 'win32_desktop_notifications', 'common.h'],
|
|
|
|
['brightray', 'browser', 'win', 'win32_desktop_notifications',
|
|
|
|
'desktop_notification_controller.cc'],
|
|
|
|
['brightray', 'browser', 'win', 'win32_desktop_notifications',
|
|
|
|
'desktop_notification_controller.h'],
|
|
|
|
['brightray', 'browser', 'win', 'win32_desktop_notifications', 'toast.h'],
|
|
|
|
['brightray', 'browser', 'win', 'win32_notification.h']
|
|
|
|
])
|
2013-06-24 09:03:48 +00:00
|
|
|
|
2014-08-08 08:41:10 +00:00
|
|
|
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
2013-06-24 09:03:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2017-12-18 16:22:51 +00:00
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Run cpplint on Electron's C++ files",
|
|
|
|
formatter_class=argparse.RawTextHelpFormatter
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'-c', '--only-changed',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
dest='only_changed',
|
|
|
|
help='only run on changed files'
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'-v', '--verbose',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
dest='verbose',
|
|
|
|
help='show cpplint output'
|
|
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2017-10-15 19:18:20 +00:00
|
|
|
if not os.path.isfile(cpplint_path()):
|
|
|
|
print("[INFO] Skipping cpplint, dependencies has not been bootstrapped")
|
|
|
|
return
|
|
|
|
|
2017-12-18 16:22:51 +00:00
|
|
|
if args.verbose:
|
|
|
|
enable_verbose_mode()
|
|
|
|
|
2013-06-24 09:03:48 +00:00
|
|
|
os.chdir(SOURCE_ROOT)
|
2017-12-19 21:57:03 +00:00
|
|
|
files = find_files(['atom', 'brightray'], is_cpp_file)
|
2017-12-20 00:37:02 +00:00
|
|
|
files -= IGNORE_FILES
|
2017-12-18 16:22:51 +00:00
|
|
|
if args.only_changed:
|
2017-12-19 21:40:11 +00:00
|
|
|
files &= find_changed_files()
|
2017-12-20 00:37:02 +00:00
|
|
|
call_cpplint(files)
|
2013-06-24 09:03:48 +00:00
|
|
|
|
2017-05-10 20:51:57 +00:00
|
|
|
|
2017-12-19 21:57:03 +00:00
|
|
|
def find_files(roots, test):
|
2017-12-18 16:22:51 +00:00
|
|
|
matches = set()
|
2017-12-19 21:57:03 +00:00
|
|
|
for root in roots:
|
|
|
|
for parent, _, children, in os.walk(root):
|
2017-12-19 21:50:09 +00:00
|
|
|
for child in children:
|
2017-12-19 22:02:36 +00:00
|
|
|
filename = os.path.join(parent, child)
|
2017-12-19 21:50:09 +00:00
|
|
|
if test(filename):
|
|
|
|
matches.add(filename)
|
2013-06-24 09:03:48 +00:00
|
|
|
return matches
|
|
|
|
|
|
|
|
|
2017-12-19 21:50:09 +00:00
|
|
|
def is_cpp_file(filename):
|
2017-12-19 22:23:27 +00:00
|
|
|
return filename.endswith('.cc') or filename.endswith('.h')
|
2017-12-19 21:50:09 +00:00
|
|
|
|
|
|
|
|
2017-12-19 21:40:11 +00:00
|
|
|
def find_changed_files():
|
2017-12-18 16:22:51 +00:00
|
|
|
return set(execute(['git', 'diff', '--name-only']).splitlines())
|
|
|
|
|
|
|
|
|
2013-06-24 09:03:48 +00:00
|
|
|
def call_cpplint(files):
|
2017-12-18 16:22:51 +00:00
|
|
|
if files:
|
|
|
|
cpplint = cpplint_path()
|
2017-12-20 00:37:02 +00:00
|
|
|
execute([sys.executable, cpplint] + list(files))
|
2013-06-24 09:03:48 +00:00
|
|
|
|
|
|
|
|
2017-10-15 19:18:20 +00:00
|
|
|
def cpplint_path():
|
|
|
|
return os.path.join(SOURCE_ROOT, 'vendor', 'depot_tools', 'cpplint.py')
|
|
|
|
|
|
|
|
|
2013-06-24 09:03:48 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|