Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: test/ios/gyptest-per-config-settings.py

Issue 1454433002: Python 3 compatibility Base URL: https://chromium.googlesource.com/external/gyp.git@master
Patch Set: Rebase with master (4ec6c4e3a94bd04a6da2858163d40b2429b8aad1) Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # Copyright (c) 2012 Google Inc. All rights reserved. 3 # Copyright (c) 2012 Google Inc. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """ 7 """
8 Verifies that device and simulator bundles are built correctly. 8 Verifies that device and simulator bundles are built correctly.
9 """ 9 """
10 10
11 from __future__ import print_function
12
11 import plistlib 13 import plistlib
12 import TestGyp 14 import TestGyp
13 import os 15 import os
14 import struct 16 import struct
15 import subprocess 17 import subprocess
16 import sys 18 import sys
17 import tempfile 19 import tempfile
18 import TestMac 20 import TestMac
19 21
20 def CheckFileType(file, expected): 22 def CheckFileType(file, expected):
21 proc = subprocess.Popen(['lipo', '-info', file], stdout=subprocess.PIPE) 23 proc = subprocess.Popen(['lipo', '-info', file], stdout=subprocess.PIPE)
22 o = proc.communicate()[0].strip() 24 o = proc.communicate()[0].strip()
23 assert not proc.returncode 25 assert not proc.returncode
24 if not expected in o: 26 if not expected in o:
25 print 'File: Expected %s, got %s' % (expected, o) 27 print('File: Expected %s, got %s' % (expected, o))
26 test.fail_test() 28 test.fail_test()
27 29
28 def HasCerts(): 30 def HasCerts():
29 # Because the bots do not have certs, don't check them if there are no 31 # Because the bots do not have certs, don't check them if there are no
30 # certs available. 32 # certs available.
31 proc = subprocess.Popen(['security','find-identity','-p', 'codesigning', 33 proc = subprocess.Popen(['security','find-identity','-p', 'codesigning',
32 '-v'], stdout=subprocess.PIPE) 34 '-v'], stdout=subprocess.PIPE)
33 return "0 valid identities found" not in proc.communicate()[0].strip() 35 return "0 valid identities found" not in proc.communicate()[0].strip()
34 36
35 def CheckSignature(file): 37 def CheckSignature(file):
36 proc = subprocess.Popen(['codesign', '-v', file], stdout=subprocess.PIPE) 38 proc = subprocess.Popen(['codesign', '-v', file], stdout=subprocess.PIPE)
37 o = proc.communicate()[0].strip() 39 o = proc.communicate()[0].strip()
38 assert not proc.returncode 40 assert not proc.returncode
39 if "code object is not signed at all" in o: 41 if "code object is not signed at all" in o:
40 print 'File %s not properly signed.' % (file) 42 print('File %s not properly signed.' % (file))
41 test.fail_test() 43 test.fail_test()
42 44
43 def CheckEntitlements(file, expected_entitlements): 45 def CheckEntitlements(file, expected_entitlements):
44 with tempfile.NamedTemporaryFile() as temp: 46 with tempfile.NamedTemporaryFile() as temp:
45 proc = subprocess.Popen(['codesign', '--display', '--entitlements', 47 proc = subprocess.Popen(['codesign', '--display', '--entitlements',
46 temp.name, file], stdout=subprocess.PIPE) 48 temp.name, file], stdout=subprocess.PIPE)
47 o = proc.communicate()[0].strip() 49 o = proc.communicate()[0].strip()
48 assert not proc.returncode 50 assert not proc.returncode
49 data = temp.read() 51 data = temp.read()
50 entitlements = ParseEntitlements(data) 52 entitlements = ParseEntitlements(data)
51 if not entitlements: 53 if not entitlements:
52 print 'No valid entitlements found in %s.' % (file) 54 print('No valid entitlements found in %s.' % (file))
53 test.fail_test() 55 test.fail_test()
54 if entitlements != expected_entitlements: 56 if entitlements != expected_entitlements:
55 print 'Unexpected entitlements found in %s.' % (file) 57 print('Unexpected entitlements found in %s.' % (file))
56 test.fail_test() 58 test.fail_test()
57 59
58 def ParseEntitlements(data): 60 def ParseEntitlements(data):
59 if len(data) < 8: 61 if len(data) < 8:
60 return None 62 return None
61 magic, length = struct.unpack('>II', data[:8]) 63 magic, length = struct.unpack('>II', data[:8])
62 if magic != 0xfade7171 or length != len(data): 64 if magic != 0xfade7171 or length != len(data):
63 return None 65 return None
64 return data[8:] 66 return data[8:]
65 67
66 def GetXcodeVersionValue(type): 68 def GetXcodeVersionValue(type):
67 args = ['xcodebuild', '-version', '-sdk', 'iphoneos', type] 69 args = ['xcodebuild', '-version', '-sdk', 'iphoneos', type]
68 job = subprocess.Popen(args, stdout=subprocess.PIPE) 70 job = subprocess.Popen(args, stdout=subprocess.PIPE)
69 return job.communicate()[0].strip() 71 return job.communicate()[0].strip()
70 72
71 def GetMachineBuild(): 73 def GetMachineBuild():
72 args = ['sw_vers', '-buildVersion'] 74 args = ['sw_vers', '-buildVersion']
73 job = subprocess.Popen(args, stdout=subprocess.PIPE) 75 job = subprocess.Popen(args, stdout=subprocess.PIPE)
74 return job.communicate()[0].strip() 76 return job.communicate()[0].strip()
75 77
76 def CheckPlistvalue(plist, key, expected): 78 def CheckPlistvalue(plist, key, expected):
77 if key not in plist: 79 if key not in plist:
78 print '%s not set in plist' % key 80 print('%s not set in plist' % key)
79 test.fail_test() 81 test.fail_test()
80 return 82 return
81 actual = plist[key] 83 actual = plist[key]
82 if actual != expected: 84 if actual != expected:
83 print 'File: Expected %s, got %s for %s' % (expected, actual, key) 85 print('File: Expected %s, got %s for %s' % (expected, actual, key))
84 test.fail_test() 86 test.fail_test()
85 87
86 def CheckPlistNotSet(plist, key): 88 def CheckPlistNotSet(plist, key):
87 if key in plist: 89 if key in plist:
88 print '%s should not be set in plist' % key 90 print('%s should not be set in plist' % key)
89 test.fail_test() 91 test.fail_test()
90 return 92 return
91 93
92 def ConvertBinaryPlistToXML(path): 94 def ConvertBinaryPlistToXML(path):
93 proc = subprocess.call(['plutil', '-convert', 'xml1', path], 95 proc = subprocess.call(['plutil', '-convert', 'xml1', path],
94 stdout=subprocess.PIPE) 96 stdout=subprocess.PIPE)
95 97
96 if sys.platform == 'darwin': 98 if sys.platform == 'darwin':
97 test = TestGyp.TestGyp(formats=['ninja', 'xcode']) 99 test = TestGyp.TestGyp(formats=['ninja', 'xcode'])
98 100
99 test.run_gyp('test-device.gyp', chdir='app-bundle') 101 test.run_gyp('test-device.gyp', chdir='app-bundle')
100 102
101 test_configs = ['Default-iphoneos', 'Default'] 103 test_configs = ['Default-iphoneos', 'Default']
102 for configuration in test_configs: 104 for configuration in test_configs:
103 test.set_configuration(configuration) 105 test.set_configuration(configuration)
104 test.build('test-device.gyp', 'test_app', chdir='app-bundle') 106 test.build('test-device.gyp', 'test_app', chdir='app-bundle')
105 result_file = test.built_file_path('Test App Gyp.app/Test App Gyp', 107 result_file = test.built_file_path('Test App Gyp.app/Test App Gyp',
106 chdir='app-bundle') 108 chdir='app-bundle')
107 test.must_exist(result_file) 109 test.must_exist(result_file)
108 info_plist = test.built_file_path('Test App Gyp.app/Info.plist', 110 info_plist = test.built_file_path('Test App Gyp.app/Info.plist',
109 chdir='app-bundle') 111 chdir='app-bundle')
110 plist = plistlib.readPlist(info_plist) 112 plist = plistlib.readPlist(info_plist)
111 xcode_version = TestMac.Xcode.Version() 113 xcode_version = TestMac.Xcode.Version()
112 if xcode_version >= '0720': 114 if xcode_version >= '0720':
113 if len(plist) != 23: 115 if len(plist) != 23:
114 print 'plist should have 23 entries, but it has %s' % len(plist) 116 print('plist should have 23 entries, but it has %s' % len(plist))
115 test.fail_test() 117 test.fail_test()
116 118
117 # Values that will hopefully never change. 119 # Values that will hopefully never change.
118 CheckPlistvalue(plist, 'CFBundleDevelopmentRegion', 'English') 120 CheckPlistvalue(plist, 'CFBundleDevelopmentRegion', 'English')
119 CheckPlistvalue(plist, 'CFBundleExecutable', 'Test App Gyp') 121 CheckPlistvalue(plist, 'CFBundleExecutable', 'Test App Gyp')
120 CheckPlistvalue(plist, 'CFBundleIdentifier', 'com.google.Test App Gyp') 122 CheckPlistvalue(plist, 'CFBundleIdentifier', 'com.google.Test App Gyp')
121 CheckPlistvalue(plist, 'CFBundleInfoDictionaryVersion', '6.0') 123 CheckPlistvalue(plist, 'CFBundleInfoDictionaryVersion', '6.0')
122 CheckPlistvalue(plist, 'CFBundleName', 'Test App Gyp') 124 CheckPlistvalue(plist, 'CFBundleName', 'Test App Gyp')
123 CheckPlistvalue(plist, 'CFBundlePackageType', 'APPL') 125 CheckPlistvalue(plist, 'CFBundlePackageType', 'APPL')
124 CheckPlistvalue(plist, 'CFBundleShortVersionString', '1.0') 126 CheckPlistvalue(plist, 'CFBundleShortVersionString', '1.0')
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 plist = plistlib.readPlist(info_plist) 178 plist = plistlib.readPlist(info_plist)
177 CheckPlistvalue(plist, 'UIDeviceFamily', [1]) 179 CheckPlistvalue(plist, 'UIDeviceFamily', [1])
178 180
179 entitlements_file = test.built_file_path('sig_test.xcent', 181 entitlements_file = test.built_file_path('sig_test.xcent',
180 chdir='app-bundle') 182 chdir='app-bundle')
181 if os.path.isfile(entitlements_file): 183 if os.path.isfile(entitlements_file):
182 expected_entitlements = open(entitlements_file).read() 184 expected_entitlements = open(entitlements_file).read()
183 CheckEntitlements(result_file, expected_entitlements) 185 CheckEntitlements(result_file, expected_entitlements)
184 186
185 test.pass_test() 187 test.pass_test()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698