tools/android/checkxmlstyle/checkxmlstyle.py
def _CheckSemanticColorsReferences(input_api, output_api):
  """
  Checks colors defined in semantic_colors_non_adaptive.xml only referencing
  resources in color_palette.xml.
  """
  errors = []
  color_palette = None

  for f in IncludedFiles(input_api):
    if not f.LocalPath().endswith('/semantic_colors_non_adaptive.xml'):
      continue

    if color_palette is None:
      color_palette = _colorXml2Dict(
        input_api.ReadFile(helpers.COLOR_PALETTE_PATH))
    for line_number, line in f.ChangedContents():
      r = helpers.COLOR_REFERENCE_PATTERN.search(line)
      if not r:
        continue
      color = r.group()
      if _removePrefix(color) not in color_palette:
        errors.append(
            '  %s:%d\n    \t%s' % (f.LocalPath(), line_number, line.strip()))

  if errors:
    return [
        output_api.PresubmitError(
            '''
  Android Semantic Color Reference Check failed:
    Your new color values added in semantic_colors_non_adaptive.xml are not
    defined in ui/android/java/res/values/color_palette.xml, listed below.

    This is banned. Colors in semantic colors can only reference
    the existing color resource from color_palette.xml.

    See https://crbug.com/775198 for more information.
  ''', errors)
    ]
  return []

  Checks colors defined in semantic_colors_non_adaptive.xml only referencing
  resources in color_palette.xml.
  
Checks colors defined in semantic_colors_non_adaptive.xml only referencing
resources in color_palette.xml.
Checks colors defined in semantic_colors_non_adaptive . xml only referencing resources in color_palette . xml .
def _CheckSemanticColorsReferences(input_api, output_api):
  errors = []
  color_palette = None
  for f in IncludedFiles(input_api):
    if not f.LocalPath().endswith('/semantic_colors_non_adaptive.xml'):
      continue
    if color_palette is None:
      color_palette = _colorXml2Dict(
        input_api.ReadFile(helpers.COLOR_PALETTE_PATH))
    for line_number, line in f.ChangedContents():
      r = helpers.COLOR_REFERENCE_PATTERN.search(line)
      if not r:
        continue
      color = r.group()
      if _removePrefix(color) not in color_palette:
        errors.append(
            '  %s:%d\n    \t%s' % (f.LocalPath(), line_number, line.strip()))
  if errors:
    return [
        output_api.PresubmitError(
            '''
  Android Semantic Color Reference Check failed:
    Your new color values added in semantic_colors_non_adaptive.xml are not
    defined in ui/android/java/res/values/color_palette.xml, listed below.
    This is banned. Colors in semantic colors can only reference
    the existing color resource from color_palette.xml.
    See https://crbug.com/775198 for more information.
  ''', errors)
    ]
  return []
def _CheckSemanticColorsReferences ( input_api , output_api ) : errors = [ ] color_palette = None for f in IncludedFiles ( input_api ) : if not f . LocalPath ( ) . endswith ( '/semantic_colors_non_adaptive.xml' ) : continue if color_palette is None : color_palette = _colorXml2Dict ( input_api . ReadFile ( helpers . COLOR_PALETTE_PATH ) ) for line_number , line in f . ChangedContents ( ) : r = helpers . COLOR_REFERENCE_PATTERN . search ( line ) if not r : continue color = r . group ( ) if _removePrefix ( color ) not in color_palette : errors . append ( '  %s:%d\n    \t%s' % ( f . LocalPath ( ) , line_number , line . strip ( ) ) ) if errors : return [ output_api . PresubmitError ( '''
  Android Semantic Color Reference Check failed:
    Your new color values added in semantic_colors_non_adaptive.xml are not
    defined in ui/android/java/res/values/color_palette.xml, listed below.

    This is banned. Colors in semantic colors can only reference
    the existing color resource from color_palette.xml.

    See https://crbug.com/775198 for more information.
  ''' , errors ) ] return [ ]
Checks colors defined in semantic_colors_non_adaptive.xml only referencing
resources in color_palette.xml.
Checks colors defined in semantic_colors_non_adaptive . xml only referencing resources in color_palette . xml .
"""
  Checks colors defined in semantic_colors_non_adaptive.xml only referencing
  resources in color_palette.xml.
  """
input_api
output_api