Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / chrome / app / nibs / PRESUBMIT.py
blobb2ccdef84a0979f11c7e9ec62bdf6993eaf9a8d0
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Presubmit script to verify that XIB changes are done with the right version.
7 See http://dev.chromium.org/developers/design-documents/mac-xib-files for more
8 information.
9 """
11 import re
13 # Minimum is Mac OS X 10.9.5 (13F34).
14 HUMAN_DARWIN_VERSION = '10.9.x, x >= 1'
15 ALLOWED_DARWIN_VERSION = 13 # Darwin 12 = 10.9.
16 MINIMUM_DARWIN_RELEASE = 'F' # Release F = 10.9.5.
18 MINIMUM_IB_VERSION = 5053 # Xcode 5.1.
19 MAXIMUM_IB_VERSION = 5056 # Xcode 5.1.1.
20 HUMAN_IB_VERSION = '>= 5.1, <= 5.1.1'
22 SYSTEM_VERSION_RE = r'<document .* systemVersion="([0-9]{,2})([A-Z])([0-9]+)"'
24 IB_VERSION_RE = \
25 r'<plugIn identifier="com\.apple\.InterfaceBuilder\.CocoaPlugin" ' + \
26 'version="([0-9]+)"/>'
28 def _CheckXIBSystemAndXcodeVersions(input_api, output_api, error_type):
29 affected_xibs = [x for x in input_api.AffectedFiles()
30 if x.LocalPath().endswith('.xib')]
32 incorrect_system_versions = []
33 incorrect_ib_versions = []
35 for xib in affected_xibs:
36 if len(xib.NewContents()) == 0:
37 continue
39 system_version = None
40 ib_version = None
42 new_contents = xib.NewContents()
43 if not new_contents:
44 # Deleting files is always fine.
45 continue
47 for line in new_contents:
48 m = re.search(SYSTEM_VERSION_RE, line)
49 if m:
50 system_version = (m.group(1), m.group(2), m.group(3))
52 m = re.search(IB_VERSION_RE, line)
53 if m:
54 ib_version = m.group(1)
56 if system_version is not None and ib_version is not None:
57 break
59 if system_version is None:
60 incorrect_system_versions.append(xib.LocalPath())
61 continue
62 if int(system_version[0]) != ALLOWED_DARWIN_VERSION:
63 incorrect_system_versions.append(xib.LocalPath())
64 continue
65 if system_version[1] < MINIMUM_DARWIN_RELEASE:
66 incorrect_system_versions.append(xib.LocalPath())
67 continue
69 if ib_version is None or int(ib_version) < MINIMUM_IB_VERSION or \
70 int(ib_version) > MAXIMUM_IB_VERSION:
71 incorrect_ib_versions.append(xib.LocalPath())
72 continue
74 problems = []
75 if incorrect_system_versions:
76 problems.append(error_type(
77 'XIB files need to be saved on Mac OS X ' + HUMAN_DARWIN_VERSION,
78 items=incorrect_system_versions))
79 if incorrect_ib_versions:
80 problems.append(error_type(
81 'XIB files need to be saved using Xcode version ' + HUMAN_IB_VERSION,
82 items=incorrect_ib_versions))
83 return problems
85 def CheckChangeOnUpload(input_api, output_api):
86 # Allow uploads to happen even if the presubmit fails, so that contributors
87 # can ask their reviewer or another person to re-save the XIBs for them.
88 return _CheckXIBSystemAndXcodeVersions(input_api, output_api,
89 error_type=output_api.PresubmitPromptWarning)
91 def CheckChangeOnCommit(input_api, output_api):
92 return _CheckXIBSystemAndXcodeVersions(input_api, output_api,
93 error_type=output_api.PresubmitError)