Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(816)

Unified Diff: tools/unused-grit-header.py

Issue 514493002: Cleanup: Remove unneeded grit include in chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@grit_clean_chromium_strings_401588_a
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/third_party/mozilla_security_manager/nsNSSCertificate.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/unused-grit-header.py
diff --git a/tools/unused-grit-header.py b/tools/unused-grit-header.py
index da85b55f3809cd2be49e457e316f766289942d9a..79c329d2fc7e350183626ceb6977d905c4bd6f35 100755
--- a/tools/unused-grit-header.py
+++ b/tools/unused-grit-header.py
@@ -78,16 +78,13 @@ def GetResourcesForGrdFile(tree, grd_file):
release_node = FindNodeWithTag(root, 'release')
assert release_node != None
- messages_node = FindNodeWithTag(release_node, 'messages')
- messages = set()
- if messages_node != None:
- messages = set(GetResourcesForNode(messages_node, grd_file, 'message'))
-
- includes_node = FindNodeWithTag(release_node, 'includes')
- includes = set()
- if includes_node != None:
- includes = set(GetResourcesForNode(includes_node, grd_file, 'include'))
- return messages.union(includes)
+ resources = set()
+ for node_type in ('message', 'include', 'structure'):
+ resources_node = FindNodeWithTag(release_node, node_type + 's')
+ if resources_node != None:
+ resources = resources.union(
+ set(GetResourcesForNode(resources_node, grd_file, node_type)))
+ return resources
def GetOutputFileForNode(node):
@@ -150,6 +147,13 @@ def NeedsGritInclude(grit_header, resources, filename):
Returns:
True if the file should include the grit header.
"""
+ # A list of special keywords that implies the file needs grit headers.
+ # To be more thorough, one would need to run a pre-processor.
+ SPECIAL_KEYWORDS = (
+ 'IMAGE_GRID(', # Macro in nine_image_painter_factory.h
tfarina 2014/08/29 17:55:54 https://chromium.googlesource.com/chromium/src/+/m
+ '#include "ui_localizer_table.h"', # ui_localizer.mm
+ 'DEFINE_RESOURCE_ID', # chrome/browser/android/resource_mapper.cc
+ )
with open(filename, 'rb') as f:
grit_header_line = grit_header + '"\n'
has_grit_header = False
@@ -164,7 +168,8 @@ def NeedsGritInclude(grit_header, resources, filename):
if not has_grit_header:
return True
rest_of_the_file = f.read()
- return any(resource in rest_of_the_file for resource in resources)
+ return (any(resource in rest_of_the_file for resource in resources) or
+ any(keyword in rest_of_the_file for keyword in SPECIAL_KEYWORDS))
def main(argv):
« no previous file with comments | « chrome/third_party/mozilla_security_manager/nsNSSCertificate.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698