Remove EWK_BRINGUPS for M120 #3
[platform/framework/web/chromium-efl.git] / chrome / app / PRESUBMIT.py
1 # Copyright 2013 The Chromium Authors
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Presubmit script for changes affecting chrome/app/
6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools.
9 """
10
11
12 import os
13 from xml.dom import minidom
14
15 def _CheckNoProductNameInGeneratedResources(input_api, output_api):
16   """Check that no PRODUCT_NAME placeholders are found in resources files.
17
18   These kinds of strings prevent proper localization in some languages. For
19   more information, see the following chromium-dev thread:
20   https://groups.google.com/a/chromium.org/forum/#!msg/chromium-dev/PBs5JfR0Aoc/NOcIHII9u14J
21   """
22
23   problems = []
24   filename_filter = lambda x: x.LocalPath().endswith(('.grd', '.grdp'))
25
26   for f, line_num, line in input_api.RightHandSideLines(filename_filter):
27     if ('PRODUCT_NAME' in line and 'name="IDS_PRODUCT_NAME"' not in line and
28        'name="IDS_SHORT_PRODUCT_NAME"' not in line):
29       problems.append('%s:%d' % (f.LocalPath(), line_num))
30
31   if problems:
32     return [output_api.PresubmitPromptWarning(
33         "Don't use PRODUCT_NAME placeholders in string resources. Instead, "
34         "add separate strings to google_chrome_strings.grd and "
35         "chromium_strings.grd. See http://goo.gl/6614MQ for more information. "
36         "Problems with this check? Contact dubroy@chromium.org.",
37         items=problems)]
38   return []
39
40 def _CheckFlagsMessageNotTranslated(input_api, output_api):
41   """Check: all about:flags messages are marked as not requiring translation.
42
43   This assumes that such messages are only added to generated_resources.grd and
44   that all such messages have names starting with IDS_FLAGS_. The expected mark
45   for not requiring translation is 'translateable="false"'.
46   """
47
48   problems = []
49   filename_filter = lambda x: x.LocalPath().endswith("generated_resources.grd")
50
51   for f, line_num, line in input_api.RightHandSideLines(filename_filter):
52     if "name=\"IDS_FLAGS_" in line and not "translateable=\"false\"" in line:
53       problems.append("Missing translateable=\"false\" in %s:%d"
54                       % (f.LocalPath(), line_num))
55       problems.append(line)
56
57   if problems:
58     return [output_api.PresubmitError(
59         "If you define a flag name, description or value, mark it as not "
60         "requiring translation by adding the 'translateable' attribute with "
61         "value \"false\". See https://crbug.com/587272 for more context.",
62         items=problems)]
63   return []
64
65   def _GetInfoStrings(file_contents):
66     """Retrieves IDS_EDU_LOGIN_INFO_* messages from the file contents
67
68     Args:
69       file_contents: string
70
71     Returns:
72       A list of tuples, where each element represents a message.
73       element[0] is the 'name' attribute of the message
74       element[1] is the message contents
75     """
76     return [(message.getAttribute('name'), message.firstChild.nodeValue)
77             for message in (file_contents.getElementsByTagName('grit-part')[0]
78                             .getElementsByTagName('message'))
79             if message.getAttribute('name').startswith('IDS_EDU_LOGIN_INFO_')]
80
81   strings_file = next((af for af in input_api.change.AffectedFiles()
82                       if af.AbsoluteLocalPath() == CHROMEOS_STRINGS_PATH), None)
83   if strings_file is None:
84     return []
85
86   old_info_strings = _GetInfoStrings(
87       minidom.parseString('\n'.join(strings_file.OldContents())))
88   new_info_strings = _GetInfoStrings(
89       minidom.parseString('\n'.join(strings_file.NewContents())))
90   if set(old_info_strings) == set(new_info_strings):
91     return []
92
93   if input_api.change.issue == 0:
94     # First upload, notify about string changes.
95     return [
96         output_api.PresubmitNotifyResult(
97             UPDATE_TEXT_VERSION_MESSAGE % "v<GERRIT_CL_NUMBER>"),
98         output_api.PresubmitNotifyResult(
99             UPDATE_INVALIDATION_VERSION_MESSAGE % "iv<GERRIT_CL_NUMBER>"),
100     ]
101
102   new_text_version = "v" + str(input_api.change.issue)
103   new_invalidation_version = "iv" + str(input_api.change.issue)
104
105   text_version_file = next((af for af in input_api.change.AffectedFiles()
106                             if af.AbsoluteLocalPath() == TEXT_VERSION_PATH),
107                             None)
108   result = []
109   # Check if text version was updated.
110   if text_version_file is None or new_text_version not in '\n'.join(
111       text_version_file.NewContents()):
112     result.append(
113         output_api.PresubmitError(
114             UPDATE_TEXT_VERSION_MESSAGE % new_text_version))
115   # Check if invalidation version was updated.
116   if text_version_file is None or new_invalidation_version not in '\n'.join(
117       text_version_file.NewContents()):
118     result.append(
119         output_api.PresubmitNotifyResult(
120             UPDATE_INVALIDATION_VERSION_MESSAGE % new_invalidation_version))
121   return result
122
123 def _CommonChecks(input_api, output_api):
124   """Checks common to both upload and commit."""
125   results = []
126   results.extend(_CheckNoProductNameInGeneratedResources(input_api, output_api))
127   results.extend(_CheckFlagsMessageNotTranslated(input_api, output_api))
128   return results
129
130 def CheckChangeOnUpload(input_api, output_api):
131   return _CommonChecks(input_api, output_api)
132
133 def CheckChangeOnCommit(input_api, output_api):
134   return _CommonChecks(input_api, output_api)