# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Presubmit script for changes affecting chrome/app/

See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into gcl.
"""

import os

def _CheckNoProductNameInGeneratedResources(input_api, output_api):
  """Check that no PRODUCT_NAME placeholders are found in resources files.

  These kinds of strings prevent proper localization in some languages. For
  more information, see the following chromium-dev thread:
  https://groups.google.com/a/chromium.org/forum/#!msg/chromium-dev/PBs5JfR0Aoc/NOcIHII9u14J
  """

  problems = []
  filename_filter = lambda x: x.LocalPath().endswith('.grd')

  for f, line_num, line in input_api.RightHandSideLines(filename_filter):
    if 'PRODUCT_NAME' in line:
      problems.append('%s:%d' % (f.LocalPath(), line_num))

  if problems:
    return [output_api.PresubmitPromptWarning(
        "Don't use PRODUCT_NAME placeholders in string resources. Instead, add "
        "separate strings to google_chrome_strings.grd and "
        "chromium_strings.grd. See http://goo.gl/6614MQ for more information."
        "Problems with this check? Contact dubroy@chromium.org.",
        items=problems)]
  return []

def _CommonChecks(input_api, output_api):
  """Checks common to both upload and commit."""
  results = []
  results.extend(_CheckNoProductNameInGeneratedResources(input_api, output_api))
  return results

def CheckChangeOnUpload(input_api, output_api):
  return _CommonChecks(input_api, output_api)

def CheckChangeOnCommit(input_api, output_api):
  return _CommonChecks(input_api, output_api)

Add presubmit check to catch use of PRODUCT_NAME in resources.
Add presubmit check to catch use of PRODUCT_NAME in resources.

We should not be adding any new strings resources that use a PRODUCT_NAME
placeholder, because it is difficult to localize in some languages. Add a
presubmit check which shows a warning whenever a line is that contains
PRODUCT_NAME is changed in a .grd file.

BUG=None

Review URL: https://codereview.chromium.org/32213002

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@230148 0039d316-1c4b-4281-b951-d872f2087c98
