electron/script/cpplint.py

110 lines
3.5 KiB
Python
Raw Normal View History

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 fnmatch
import os
import sys
2017-12-18 16:22:51 +00:00
from lib.config import enable_verbose_mode
from lib.util import execute
2013-08-13 09:07:36 +00:00
IGNORE_FILES = [
2014-04-15 07:42:46 +00:00
os.path.join('atom', 'browser', 'mac', 'atom_application.h'),
os.path.join('atom', 'browser', 'mac', 'atom_application_delegate.h'),
2014-03-16 00:58:59 +00:00
os.path.join('atom', 'browser', 'resources', 'win', 'resource.h'),
os.path.join('atom', 'browser', 'ui', 'cocoa', 'atom_menu_controller.h'),
2017-02-28 20:33:56 +00:00
os.path.join('atom', 'browser', 'ui', 'cocoa', 'atom_touch_bar.h'),
os.path.join('atom', 'browser', 'ui', 'cocoa',
'touch_bar_forward_declarations.h'),
2017-11-28 06:36:45 +00:00
os.path.join('atom', 'browser', 'ui', 'cocoa', 'NSColor+Hex.h'),
os.path.join('atom', 'browser', 'ui', 'cocoa', 'NSString+ANSI.h'),
2014-03-16 00:58:59 +00:00
os.path.join('atom', 'common', 'api', 'api_messages.h'),
2014-08-21 12:25:12 +00:00
os.path.join('atom', 'common', 'common_message_generator.cc'),
os.path.join('atom', 'common', 'common_message_generator.h'),
2017-05-10 20:51:57 +00:00
os.path.join('brightray', 'browser', 'mac',
'bry_inspectable_web_contents_view.h'),
os.path.join('brightray', 'browser', 'mac', 'event_dispatching_window.h'),
os.path.join('brightray', 'browser', 'mac',
'notification_center_delegate.h'),
os.path.join('brightray', 'browser', 'win', 'notification_presenter_win7.h'),
os.path.join('brightray', 'browser', 'win', 'win32_desktop_notifications',
'common.h'),
2017-05-10 20:51:57 +00:00
os.path.join('brightray', 'browser', 'win', 'win32_desktop_notifications',
'desktop_notification_controller.cc'),
os.path.join('brightray', 'browser', 'win', 'win32_desktop_notifications',
'desktop_notification_controller.h'),
os.path.join('brightray', 'browser', 'win', 'win32_desktop_notifications',
'toast.h'),
os.path.join('brightray', 'browser', 'win', 'win32_notification.h')
2013-06-24 09:03:48 +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()
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-18 16:22:51 +00:00
files = list_files('atom',
['app', 'browser', 'common', 'renderer', 'utility'],
['*.cc', '*.h'])
2017-12-19 21:07:11 +00:00
files += list_files('brightray', ['browser', 'common'], ['*.cc', '*.h'])
2017-12-19 21:38:23 +00:00
files -= set(IGNORE_FILES)
2017-12-18 16:22:51 +00:00
if args.only_changed:
files &= get_changed_files()
2017-12-18 16:22:51 +00:00
call_cpplint(list(files))
2013-06-24 09:03:48 +00:00
2017-05-10 20:51:57 +00:00
def list_files(parent, directories, filters):
2017-12-18 16:22:51 +00:00
matches = set()
2013-06-24 09:03:48 +00:00
for directory in directories:
2017-05-10 20:51:57 +00:00
for root, _, filenames, in os.walk(os.path.join(parent, directory)):
2013-06-24 09:03:48 +00:00
for f in filters:
for filename in fnmatch.filter(filenames, f):
2017-12-18 16:22:51 +00:00
matches.add(os.path.join(root, filename))
2013-06-24 09:03:48 +00:00
return matches
2017-12-18 16:22:51 +00:00
def get_changed_files():
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()
execute([sys.executable, cpplint] + files)
2013-06-24 09:03:48 +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())