OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 """Presubmit script to verify that XIB changes are done with the right version. |
| 6 |
| 7 See http://dev.chromium.org/developers/design-documents/mac-xib-files for more |
| 8 information. |
| 9 """ |
| 10 |
| 11 import re |
| 12 |
| 13 # Minimum is Mac OS X 10.8.1 (12B19). |
| 14 HUMAN_DARWIN_VERSION = '10.8.x, x >= 1' |
| 15 ALLOWED_DARWIN_VERSION = 12 # Darwin 12 = 10.8. |
| 16 MINIMUM_DARWIN_RELEASE = 'B' # Release B = 10.8.1. |
| 17 |
| 18 MINIMUM_IB_VERSION = 2549 # Xcode 4.4.1. |
| 19 MAXIMUM_IB_VERSION = 2800 # Xcode 4.5.x. |
| 20 HUMAN_IB_VERSION = '4.4.x, x >= 1' |
| 21 |
| 22 SYSTEM_VERSION_RE = r'<string key="IBDocument\.SystemVersion">' + \ |
| 23 '([0-9]{,2})([A-Z])([0-9]+)</string>' |
| 24 |
| 25 IB_VERSION_RE = \ |
| 26 r'<string key="IBDocument\.InterfaceBuilderVersion">([0-9]+)</string>' |
| 27 |
| 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')] |
| 31 |
| 32 incorrect_system_versions = [] |
| 33 incorrect_ib_versions = [] |
| 34 |
| 35 for xib in affected_xibs: |
| 36 system_version = None |
| 37 ib_version = None |
| 38 for line in xib.NewContents(): |
| 39 m = re.search(SYSTEM_VERSION_RE, line) |
| 40 if m: |
| 41 system_version = (m.group(1), m.group(2), m.group(3)) |
| 42 |
| 43 m = re.search(IB_VERSION_RE, line) |
| 44 if m: |
| 45 ib_version = m.group(1) |
| 46 |
| 47 if system_version is not None and ib_version is not None: |
| 48 break |
| 49 |
| 50 if system_version is None: |
| 51 incorrect_system_versions.append(xib.LocalPath()) |
| 52 continue |
| 53 if int(system_version[0]) != ALLOWED_DARWIN_VERSION: |
| 54 incorrect_system_versions.append(xib.LocalPath()) |
| 55 continue |
| 56 if system_version[1] < MINIMUM_DARWIN_RELEASE: |
| 57 incorrect_system_versions.append(xib.LocalPath()) |
| 58 continue |
| 59 |
| 60 if ib_version is None or int(ib_version) < MINIMUM_IB_VERSION or \ |
| 61 int(ib_version) >= MAXIMUM_IB_VERSION: |
| 62 incorrect_ib_versions.append(xib.LocalPath()) |
| 63 continue |
| 64 |
| 65 problems = [] |
| 66 if incorrect_system_versions: |
| 67 problems.append(error_type( |
| 68 'XIB files need to be saved on Mac OS X ' + HUMAN_DARWIN_VERSION, |
| 69 items=incorrect_system_versions)) |
| 70 if incorrect_ib_versions: |
| 71 problems.append(error_type( |
| 72 'XIB files need to be saved using Xcode ' + HUMAN_IB_VERSION, |
| 73 items=incorrect_ib_versions)) |
| 74 return problems |
| 75 |
| 76 def CheckChangeOnUpload(input_api, output_api): |
| 77 # Allow uploads to happen even if the presubmit fails, so that contributors |
| 78 # can ask their reviewer or another person to re-save the XIBs for them. |
| 79 return _CheckXIBSystemAndXcodeVersions(input_api, output_api, |
| 80 error_type=output_api.PresubmitPromptWarning) |
| 81 |
| 82 def CheckChangeOnCommit(input_api, output_api): |
| 83 return _CheckXIBSystemAndXcodeVersions(input_api, output_api, |
| 84 error_type=output_api.PresubmitError) |
OLD | NEW |