OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
Mark Mentovai
2012/09/18 20:16:59
What year, now?
Robert Sesek
2012/09/18 20:42:10
Oops.
| |
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' | |
Mark Mentovai
2012/09/18 20:16:59
Technically incorrect if you’re requiring 10.8.1 b
Robert Sesek
2012/09/18 20:42:10
Done.
| |
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. | |
Mark Mentovai
2012/09/18 20:16:59
For the name of the variable to make sense, I thin
Robert Sesek
2012/09/18 20:42:10
The earliest 4.5 prerelease seed I found had build
| |
20 HUMAN_IB_VERSION = '4.4.x' | |
Mark Mentovai
2012/09/18 20:16:59
Similar to before, technically incorrect if you’re
Robert Sesek
2012/09/18 20:42:10
Done.
| |
21 | |
22 SYSTEM_VERSION_RE = \ | |
23 r'<string key="IBDocument\.SystemVersion">([0-9A-Z]+)</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(): | |
Mark Mentovai
2012/09/18 20:16:59
Why don’t you have your REs anchored with ^ and $,
Robert Sesek
2012/09/18 20:42:10
The AffectedFile only provides iterators to the li
| |
39 m = re.search(SYSTEM_VERSION_RE, line) | |
40 if m: | |
41 system_version = m.group(1) | |
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 or len(system_version) < 3: | |
51 incorrect_system_versions.append(xib.LocalPath()) | |
52 continue | |
53 if int(system_version[0:2]) != ALLOWED_DARWIN_VERSION: | |
Mark Mentovai
2012/09/18 20:16:59
Rather than system_version[0:2] and system_version
Robert Sesek
2012/09/18 20:42:10
Done.
| |
54 incorrect_system_versions.append(xib.LocalPath()) | |
55 continue | |
56 if system_version[2] < 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, | |
Mark Mentovai
2012/09/18 20:16:59
Can the message say which xib tripped the check? S
Robert Sesek
2012/09/18 20:42:10
That's what items= does.
| |
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 |