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

Side by Side Diff: chrome/installer/linux/sysroot_scripts/install-debian.wheezy.sysroot.py

Issue 834133003: Only run install-debian.wheezy.sysroot.py once during runhooks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « DEPS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # Script to install a Debian Wheezy sysroot for making official Google Chrome 6 # Script to install a Debian Wheezy sysroot for making official Google Chrome
7 # Linux builds. 7 # Linux builds.
8 # The sysroot is needed to make Chrome work for Debian Wheezy. 8 # The sysroot is needed to make Chrome work for Debian Wheezy.
9 # This script can be run manually but is more often run as part of gclient 9 # This script can be run manually but is more often run as part of gclient
10 # hooks. When run from hooks this script should be a no-op on non-linux 10 # hooks. When run from hooks this script should be a no-op on non-linux
(...skipping 23 matching lines...) Expand all
34 TARBALL_AMD64 = 'debian_wheezy_amd64_sysroot.tgz' 34 TARBALL_AMD64 = 'debian_wheezy_amd64_sysroot.tgz'
35 TARBALL_I386 = 'debian_wheezy_i386_sysroot.tgz' 35 TARBALL_I386 = 'debian_wheezy_i386_sysroot.tgz'
36 TARBALL_ARM = 'debian_wheezy_arm_sysroot.tgz' 36 TARBALL_ARM = 'debian_wheezy_arm_sysroot.tgz'
37 TARBALL_AMD64_SHA1SUM = '74b7231e12aaf45c5c5489d9aebb56bd6abb3653' 37 TARBALL_AMD64_SHA1SUM = '74b7231e12aaf45c5c5489d9aebb56bd6abb3653'
38 TARBALL_I386_SHA1SUM = 'fe3d284926839683b00641bc66c9023f872ea4b4' 38 TARBALL_I386_SHA1SUM = 'fe3d284926839683b00641bc66c9023f872ea4b4'
39 TARBALL_ARM_SHA1SUM = 'fc2f54db168887c5190c4c6686c869bedf668b4e' 39 TARBALL_ARM_SHA1SUM = 'fc2f54db168887c5190c4c6686c869bedf668b4e'
40 SYSROOT_DIR_AMD64 = 'debian_wheezy_amd64-sysroot' 40 SYSROOT_DIR_AMD64 = 'debian_wheezy_amd64-sysroot'
41 SYSROOT_DIR_I386 = 'debian_wheezy_i386-sysroot' 41 SYSROOT_DIR_I386 = 'debian_wheezy_i386-sysroot'
42 SYSROOT_DIR_ARM = 'debian_wheezy_arm-sysroot' 42 SYSROOT_DIR_ARM = 'debian_wheezy_arm-sysroot'
43 43
44 valid_archs = ('arm', 'i386', 'amd64')
44 45
45 def get_sha1(filename): 46
47 def GetSha1(filename):
46 sha1 = hashlib.sha1() 48 sha1 = hashlib.sha1()
47 with open(filename, 'rb') as f: 49 with open(filename, 'rb') as f:
48 while True: 50 while True:
49 # Read in 1mb chunks, so it doesn't all have to be loaded into memory. 51 # Read in 1mb chunks, so it doesn't all have to be loaded into memory.
50 chunk = f.read(1024*1024) 52 chunk = f.read(1024*1024)
51 if not chunk: 53 if not chunk:
52 break 54 break
53 sha1.update(chunk) 55 sha1.update(chunk)
54 return sha1.hexdigest() 56 return sha1.hexdigest()
55 57
56 58
59 def DetectArch(gyp_defines):
60 # Check for optional target_arch and only install for that architecture.
61 # If target_arch is not specified, then only install for the host
62 # architecture.
63 if 'target_arch=x64' in gyp_defines:
64 return 'amd64'
65 elif 'target_arch=ia32' in gyp_defines:
66 return 'i386'
67 elif 'target_arch=arm' in gyp_defines:
68 return 'arm'
69 else:
70 # Figure out host arch using build/detect_host_arch.py and
71 # set target_arch to host arch
72 SRC_DIR = os.path.abspath(
73 os.path.join(SCRIPT_DIR, '..', '..', '..', '..'))
74 sys.path.append(os.path.join(SRC_DIR, 'build'))
75 import detect_host_arch
76
77 detected_host_arch = detect_host_arch.HostArch()
78 if detected_host_arch == 'x64':
79 return 'amd64'
80 elif detected_host_arch == 'ia32':
81 return 'i386'
82 elif detected_host_arch == 'arm':
83 return 'arm'
84
85 return None
86
87
57 def main(): 88 def main():
58 if options.arch not in ['amd64', 'i386', 'arm']: 89 gyp_defines = os.environ.get('GYP_DEFINES', '')
59 print 'Unknown architecture: %s' % options.arch 90
60 return 1 91 if options.arch:
92 target_arch = options.arch
93 else:
94 target_arch = DetectArch(gyp_defines)
95 if not target_arch:
96 print 'Unable to detect desired architecture'
97 return 1
61 98
62 if options.linux_only: 99 if options.linux_only:
63 # This argument is passed when run from the gclient hooks. 100 # This argument is passed when run from the gclient hooks.
64 # In this case we return early on non-linux platforms. 101 # In this case we return early on non-linux platforms.
65 if not sys.platform.startswith('linux'): 102 if not sys.platform.startswith('linux'):
66 return 0 103 return 0
67 104
68 gyp_defines = os.environ.get('GYP_DEFINES', '')
69
70 # Only install the sysroot for an Official Chrome Linux build, except 105 # Only install the sysroot for an Official Chrome Linux build, except
71 # for ARM where we always use a sysroot. 106 # for ARM where we always use a sysroot.
72 if options.arch != 'arm': 107 if target_arch != 'arm':
73 defined = ['branding=Chrome', 'buildtype=Official'] 108 defined = ['branding=Chrome', 'buildtype=Official']
74 undefined = ['chromeos=1'] 109 undefined = ['chromeos=1']
75 for option in defined: 110 for option in defined:
76 if option not in gyp_defines: 111 if option not in gyp_defines:
77 return 0 112 return 0
78 for option in undefined: 113 for option in undefined:
79 if option in gyp_defines: 114 if option in gyp_defines:
80 return 0 115 return 0
81 116
82 # Check for optional target_arch and only install for that architecture.
83 # If target_arch is not specified, then only install for the host
84 # architecture.
85 target_arch = ''
86 if 'target_arch=x64' in gyp_defines:
87 target_arch = 'amd64'
88 elif 'target_arch=ia32' in gyp_defines:
89 target_arch = 'i386'
90 elif 'target_arch=arm' in gyp_defines:
91 target_arch = 'arm'
92 else:
93 # Figure out host arch using build/detect_host_arch.py and
94 # set target_arch to host arch
95 SRC_DIR = os.path.abspath(
96 os.path.join(SCRIPT_DIR, '..', '..', '..', '..'))
97 sys.path.append(os.path.join(SRC_DIR, 'build'))
98 import detect_host_arch
99
100 detected_host_arch = detect_host_arch.HostArch()
101 if detected_host_arch == 'x64':
102 target_arch = 'amd64'
103 elif detected_host_arch == 'ia32':
104 target_arch = 'i386'
105 elif detected_host_arch == 'arm':
106 target_arch = 'arm'
107
108 if target_arch != options.arch:
109 return 0
110
111 # The sysroot directory should match the one specified in build/common.gypi. 117 # The sysroot directory should match the one specified in build/common.gypi.
112 # TODO(thestig) Consider putting this else where to avoid having to recreate 118 # TODO(thestig) Consider putting this else where to avoid having to recreate
113 # it on every build. 119 # it on every build.
114 linux_dir = os.path.dirname(SCRIPT_DIR) 120 linux_dir = os.path.dirname(SCRIPT_DIR)
115 if options.arch == 'amd64': 121 if target_arch == 'amd64':
116 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64) 122 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64)
117 tarball_filename = TARBALL_AMD64 123 tarball_filename = TARBALL_AMD64
118 tarball_sha1sum = TARBALL_AMD64_SHA1SUM 124 tarball_sha1sum = TARBALL_AMD64_SHA1SUM
119 revision = REVISION_AMD64 125 revision = REVISION_AMD64
120 elif options.arch == 'arm': 126 elif target_arch == 'arm':
121 sysroot = os.path.join(linux_dir, SYSROOT_DIR_ARM) 127 sysroot = os.path.join(linux_dir, SYSROOT_DIR_ARM)
122 tarball_filename = TARBALL_ARM 128 tarball_filename = TARBALL_ARM
123 tarball_sha1sum = TARBALL_ARM_SHA1SUM 129 tarball_sha1sum = TARBALL_ARM_SHA1SUM
124 revision = REVISION_ARM 130 revision = REVISION_ARM
125 elif options.arch == 'i386': 131 elif target_arch == 'i386':
126 sysroot = os.path.join(linux_dir, SYSROOT_DIR_I386) 132 sysroot = os.path.join(linux_dir, SYSROOT_DIR_I386)
127 tarball_filename = TARBALL_I386 133 tarball_filename = TARBALL_I386
128 tarball_sha1sum = TARBALL_I386_SHA1SUM 134 tarball_sha1sum = TARBALL_I386_SHA1SUM
129 revision = REVISION_I386 135 revision = REVISION_I386
130 else: 136 else:
137 print 'Unknown architecture: %s' % target_arch
131 assert(False) 138 assert(False)
132 139
133
134 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, revision, tarball_filename) 140 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, revision, tarball_filename)
135 141
136 stamp = os.path.join(sysroot, '.stamp') 142 stamp = os.path.join(sysroot, '.stamp')
137 if os.path.exists(stamp): 143 if os.path.exists(stamp):
138 with open(stamp) as s: 144 with open(stamp) as s:
139 if s.read() == url: 145 if s.read() == url:
140 print 'Debian Wheezy %s root image already up-to-date: %s' % \ 146 print 'Debian Wheezy %s root image already up-to-date: %s' % \
141 (options.arch, sysroot) 147 (target_arch, sysroot)
142 return 0 148 return 0
143 149
144 print 'Installing Debian Wheezy %s root image: %s' % (options.arch, sysroot) 150 print 'Installing Debian Wheezy %s root image: %s' % (target_arch, sysroot)
145 if os.path.isdir(sysroot): 151 if os.path.isdir(sysroot):
146 shutil.rmtree(sysroot) 152 shutil.rmtree(sysroot)
147 os.mkdir(sysroot) 153 os.mkdir(sysroot)
148 tarball = os.path.join(sysroot, tarball_filename) 154 tarball = os.path.join(sysroot, tarball_filename)
149 print 'Downloading %s' % url 155 print 'Downloading %s' % url
150 sys.stdout.flush() 156 sys.stdout.flush()
151 sys.stderr.flush() 157 sys.stderr.flush()
152 subprocess.check_call(['curl', '--fail', '-L', url, '-o', tarball]) 158 subprocess.check_call(['curl', '--fail', '-L', url, '-o', tarball])
153 sha1sum = get_sha1(tarball) 159 sha1sum = GetSha1(tarball)
154 if sha1sum != tarball_sha1sum: 160 if sha1sum != tarball_sha1sum:
155 print 'Tarball sha1sum is wrong.' 161 print 'Tarball sha1sum is wrong.'
156 print 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum) 162 print 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum)
157 return 1 163 return 1
158 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot]) 164 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot])
159 os.remove(tarball) 165 os.remove(tarball)
160 166
161 with open(stamp, 'w') as s: 167 with open(stamp, 'w') as s:
162 s.write(url) 168 s.write(url)
163 return 0 169 return 0
164 170
165 171
166 if __name__ == '__main__': 172 if __name__ == '__main__':
167 parser = optparse.OptionParser('usage: %prog [OPTIONS]') 173 parser = optparse.OptionParser('usage: %prog [OPTIONS]')
168 parser.add_option('--linux-only', action='store_true', 174 parser.add_option('--linux-only', action='store_true',
169 default=False, help='Only install sysroot for official ' 175 default=False, help='Only install sysroot for official '
170 'Linux builds') 176 'Linux builds')
171 parser.add_option('--arch', help='Sysroot architecture: i386, amd64 or arm') 177 parser.add_option('--arch', type='choice', choices=valid_archs,
172 options, args = parser.parse_args() 178 help='Sysroot architecture: %s' % ', '.join(valid_archs))
179 options, _ = parser.parse_args()
173 sys.exit(main()) 180 sys.exit(main())
OLDNEW
« no previous file with comments | « DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698