def main(): if len(sys.argv) > 2: print(""" Usage: check_all_styles.py [<path>] Takes a path as input and runs style/license header checks with filters where necessary. """) exit(-1) if len(sys.argv) < 2: path = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..")) else: path = os.path.realpath(sys.argv[1]) print("Check {}".format(path)) binary_files = { r'\.res$', r'\.pptx$', r'\.png$', r'\.PNG$', r'\.bmp$', r'\.BMP$', r'\.ttf$', r'\.pyc$', r'\.bin$', r'\.pac$', r'\.rex$', r'\.ctm$', r'\.tar\.bz2$', } # These files are not checked at all shared_blacklist = binary_files | { r'\.git', r'\.gitignore', r'\.patch', r'gitconfig$', r'\.clang-format$', r'\.clang-tidy$', # Protobuffer files r'\.pb.h$', r'\.pb.cc$', r'\.proto$', r'\.ptx$', r'(^|/)build[^/]*/', } # Whitelist for source files src_whitelist = { r'\.h$', r'\.hpp$', r'\.cpp$' } # Externals are allowed to have their own code style src_blacklist = shared_blacklist | {r'^external/'} src_files = get_all_files_with_filter(path, src_whitelist, src_blacklist) # Check all styles for source files for f in src_files: file_contents, file_lines = read_file(f) clean_file_contents, clean_file_lines = clean_file_content(file_contents) check_header_guards (f, file_contents) check_license_for_file (f, file_contents, path) check_tabbing_and_spacing (f, file_lines) check_curly_braces_alone_on_line (f, file_contents, clean_file_contents, file_lines, clean_file_lines) check_single_statement_on_line (f, file_contents, clean_file_contents, file_lines, clean_file_lines) check_single_definition_on_line (f, file_contents, clean_file_contents, file_lines, clean_file_lines) check_enum_style (f, clean_file_contents) check_last_line_newline (f, file_contents) check_api_export_symbols (f, clean_file_contents) shared_blacklist_non_src_files = shared_blacklist | { # Externals allowed to have own formatting and license r'^external', r'valgrind/suppressions$', r'\.spdx$', r'^CHANGELOG\.txt$', # Doesn't need a license r'^LICENSE\.txt$', # Contains license info, not related to code/content r'^.lfsconfig$', # Doesn't need a license # Only on the build server, needs to be blacklisted r'^envVar\.txt$', } blacklist_files_formatting = shared_blacklist_non_src_files | { # Formatting intended the way it is r'with-additional-spaces-and-empty-lines.*config$', } files_formatting = get_all_files_with_filter(path, {r'.*'}, blacklist_files_formatting) # Check subset of the rules for non-source files for f in files_formatting: file_contents, file_lines = read_file(f) check_tabs_no_spaces (f, file_lines) check_no_spacing_line_end (f, file_lines) check_last_line_newline (f, file_contents) blacklist_license = shared_blacklist_non_src_files | { # Can be safely excluded, don't need license header because trivial r'__init__\.py$', r'asan_suppressions\.txt$', r'lsan_suppressions\.txt$', r'tsan_blacklist\.txt$', r'DOCKER_TAG$', r'maven_settings\.xml$', r'\.config$', r'\.conf$', r'\.filepathesconfig$', # Excluded on purpose - add new lines reasonibly here! r'\.patch$', # License headers can't be added to patch files r'\.tmpl$', # File content hash-dependent, can't modify r'^README\.txt$', # Doesn't need a license r'^proprietary/oss/README\.md$', # Doesn't need a license r'^integration/TestContent/res/BigString\.txt$', # Test file with random content - doesn't need license r'^cmake/templates/ramses-version\.in$', # Just a template, doesn't need license } files_license_header = get_all_files_with_filter(path, {r'.*'}, blacklist_license) # Check subset of the rules for non-source files for f in files_license_header: file_contents, file_lines = read_file(f) check_license_for_file (f, file_contents, path) print('checked {0} files'.format(len(set(src_files) | set(files_formatting) | set(files_license_header)))) if 0 == config.G_WARNING_COUNT: print("your style is awesome! no style guide violations detected.") else: print("detected {0} style guide issues".format(config.G_WARNING_COUNT)) exit(-config.G_WARNING_COUNT)
def main(): sdk_root = os.path.realpath( os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..")) parser = argparse.ArgumentParser() parser.add_argument(dest="basepath", nargs='?', default=sdk_root, help='Path to check (default: repo root)') args = parser.parse_args() path = os.path.realpath(args.basepath) print("Check {}".format(path)) binary_files = { r'\.res$', r'\.pptx$', r'\.png$', r'\.PNG$', r'\.bmp$', r'\.BMP$', r'\.ttf$', r'\.pyc$', r'\.bin$', r'\.pac$', r'\.rex$', r'\.ctm$', r'\.tar\.bz2$', r'\.jar$', r'\.rgba_astc$', r'\.dds$', r'\.mdzip$', } # These files are not checked at all shared_blacklist = binary_files | { r'\.git', r'\.gitignore', r'\.patch', r'gitconfig$', r'\.clang-format$', r'\.clang-tidy$', r'/id_rsa[^\\]*$', # Protobuffer files r'\.pb.h$', r'\.pb.cc$', r'\.proto$', r'\.ptx$', r'(^|/)build[^/]*/', } # Whitelist for source files src_whitelist = {r'\.h$', r'\.hpp$', r'\.cpp$'} # Externals are allowed to have their own code style src_blacklist = shared_blacklist | {r'^external/'} src_files = common_modules.common.get_all_files_with_filter( sdk_root, path, src_whitelist, src_blacklist) # Check all styles for source files for f in src_files: file_contents, file_lines = common_modules.common.read_file(f) clean_file_contents, clean_file_lines = common_modules.common.clean_file_content( file_contents) check_header_guards(f, file_contents) check_license_for_file(f, file_contents, sdk_root) check_tabbing_and_spacing(f, file_lines) check_curly_braces_alone_on_line(f, file_contents, clean_file_contents, file_lines, clean_file_lines) check_single_statement_on_line(f, file_contents, clean_file_contents, file_lines, clean_file_lines) check_single_definition_on_line(f, file_contents, clean_file_contents, file_lines, clean_file_lines) check_deprecated(f, file_contents, clean_file_contents, file_lines, clean_file_lines) check_enum_style(f, clean_file_contents) check_last_line_newline(f, file_contents) check_api_export_symbols(f, clean_file_contents) check_doxygen_singleline_comments(f, file_lines) shared_blacklist_non_src_files = shared_blacklist | { # Externals allowed to have own formatting r'^external', # created by Android Studio r'.*/\.idea/', r'.*/gradle/wrapper', r'.*/gradle\.properties$', r'.*/gradlew$', r'.*/gradlew\.bat$', r'^demo/android/ramses-renderer-android-app/app/src/main/res/', r'^demo/android/ramses-renderer-android-app/build\.gradle', r'^demo/android/ramses-renderer-android-app-native-activity/app/src/main/res/', r'^demo/android/ramses-renderer-android-app-native-activity/build\.gradle', } blacklist_files_formatting = shared_blacklist_non_src_files | { # Formatting intended the way it is r'with-additional-spaces-and-empty-lines.*config$', } files_formatting = common_modules.common.get_all_files_with_filter( sdk_root, path, {r'.*'}, blacklist_files_formatting) # Check subset of the rules for non-source files for f in files_formatting: file_contents, file_lines = common_modules.common.read_file(f) check_tabs_no_spaces(f, file_lines) check_no_spacing_line_end(f, file_lines) check_last_line_newline(f, file_contents) blacklist_license = shared_blacklist_non_src_files | { # Can be safely excluded, don't need license header because trivial r'__init__\.py$', r'asan_suppressions\.txt$', r'lsan_suppressions\.txt$', r'tsan_blacklist\.txt$', r'DOCKER_TAG$', r'maven_settings\.xml$', r'\.config$', r'\.conf$', r'\.filepathesconfig$', r'^demo/android/DemoRamsesAndroidModule/src/main/AndroidManifest\.xml', # Excluded on purpose - add new lines reasonibly here! r'\.patch$', # License headers can't be added to patch files r'\.tmpl$', # File content hash-dependent, can't modify r'\.md$', # Markdown files never need license r'^integration/TestContent/res/BigString\.txt$', # Test file with random content - doesn't need license r'^cmake/templates/ramses-version\.in$', # Just a template, doesn't need license r'.*/AndroidManifest\.xml$', # formatting different due to xml restrictions } files_license_header = common_modules.common.get_all_files_with_filter( sdk_root, path, {r'.*'}, blacklist_license) # Check subset of the rules for non-source files for f in files_license_header: file_contents, file_lines = common_modules.common.read_file(f) check_license_for_file(f, file_contents, sdk_root) files_attribute_checking = common_modules.common.get_all_files_with_filter( sdk_root, path, {r'.*'}, {r'\.sh$', r'\.py$', r'/gradlew$', r'\.bat$'}) for f in files_attribute_checking: check_file_attributes(f) print('checked {0} files'.format( len( set(src_files) | set(files_formatting) | set(files_license_header)))) if 0 == common_modules.common.G_WARNING_COUNT: print("your style is awesome! no style guide violations detected.") return 0 else: print("detected {0} style guide issues".format( common_modules.common.G_WARNING_COUNT)) return 1