tools/resources/list_unused_grit_header.py
def NeedsGritInclude(grit_header, resources, filename):
  """Return whether a file needs a given grit header or not.

  Args:
    grit_header: The grit header file name.
    resources: The list of resource names in grit_header.
    filename: The file to scan.

  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 = (
      '#include "ui_localizer_table.h"',  # ui_localizer.mm
      'DECLARE_RESOURCE_ID',  # chrome/browser/android/resource_mapper.cc
      )
  with open(filename, 'rb') as f:
    grit_header_line = grit_header + '"\n'
    has_grit_header = False
    while True:
      line = f.readline()
      if not line:
        break
      if line.endswith(grit_header_line):
        has_grit_header = True
        break

    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) or
            any(keyword in rest_of_the_file for keyword in SPECIAL_KEYWORDS))
Return whether a file needs a given grit header or not.

  Args:
    grit_header: The grit header file name.
    resources: The list of resource names in grit_header.
    filename: The file to scan.

  Returns:
    True if the file should include the grit header.
  
Return whether a file needs a given grit header or not.
Return whether a file needs a given grit header or not .
def NeedsGritInclude(grit_header, resources, filename):
  SPECIAL_KEYWORDS = (
      '#include "ui_localizer_table.h"',  
      'DECLARE_RESOURCE_ID',  
      )
  with open(filename, 'rb') as f:
    grit_header_line = grit_header + '"\n'
    has_grit_header = False
    while True:
      line = f.readline()
      if not line:
        break
      if line.endswith(grit_header_line):
        has_grit_header = True
        break
    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) or
            any(keyword in rest_of_the_file for keyword in SPECIAL_KEYWORDS))
def NeedsGritInclude ( grit_header , resources , filename ) : SPECIAL_KEYWORDS = ( '#include "ui_localizer_table.h"' , 'DECLARE_RESOURCE_ID' , ) with open ( filename , 'rb' ) as f : grit_header_line = grit_header + '"\n' has_grit_header = False while True : line = f . readline ( ) if not line : break if line . endswith ( grit_header_line ) : has_grit_header = True break 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 ) or any ( keyword in rest_of_the_file for keyword in SPECIAL_KEYWORDS ) )
Return whether a file needs a given grit header or not.
Return whether a file needs a given grit header or not .
"""Return whether a file needs a given grit header or not.

  Args:
    grit_header: The grit header file name.
    resources: The list of resource names in grit_header.
    filename: The file to scan.

  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. # ui_localizer.mm # chrome/browser/android/resource_mapper.cc
True if the file should include the grit header.
True if the file should include the grit header .
grit_header
The grit header file name.
The grit header file name .
resources
The list of resource names in grit_header.
The list of resource names in grit_header .
filename
The file to scan.
The file to scan .