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

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

Issue 664383004: Merge ARM sysroot install script with existing x86/amd64 one. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 # 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
11 # platforms. 11 # platforms.
12 12
13 # The sysroot image could be constructed from scratch based on the current 13 # The sysroot image could be constructed from scratch based on the current
14 # state or Debian Wheezy but for consistency we currently use a pre-built root 14 # state or Debian Wheezy but for consistency we currently use a pre-built root
15 # image. The image will normally need to be rebuilt every time chrome's build 15 # image. The image will normally need to be rebuilt every time chrome's build
16 # dependancies are changed. 16 # dependancies are changed.
17 17
18 import hashlib 18 import hashlib
19 import platform 19 import platform
20 import optparse 20 import optparse
21 import os 21 import os
22 import re 22 import re
23 import shutil 23 import shutil
24 import subprocess 24 import subprocess
25 import sys 25 import sys
26 26
27 27
28 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 28 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
29 URL_PREFIX = 'https://commondatastorage.googleapis.com' 29 URL_PREFIX = 'http://storage.googleapis.com'
30 URL_PATH = 'chrome-linux-sysroot/toolchain' 30 URL_PATH = 'chrome-linux-sysroot/toolchain'
31 REVISION = 264817 31 REVISION = 264817
32 ARM_REVISION = 285950
32 TARBALL_AMD64 = 'debian_wheezy_amd64_sysroot.tgz' 33 TARBALL_AMD64 = 'debian_wheezy_amd64_sysroot.tgz'
33 TARBALL_I386 = 'debian_wheezy_i386_sysroot.tgz' 34 TARBALL_I386 = 'debian_wheezy_i386_sysroot.tgz'
35 TARBALL_ARM = 'debian_wheezy_arm_sysroot.tgz'
34 TARBALL_AMD64_SHA1SUM = '74b7231e12aaf45c5c5489d9aebb56bd6abb3653' 36 TARBALL_AMD64_SHA1SUM = '74b7231e12aaf45c5c5489d9aebb56bd6abb3653'
35 TARBALL_I386_SHA1SUM = 'fe3d284926839683b00641bc66c9023f872ea4b4' 37 TARBALL_I386_SHA1SUM = 'fe3d284926839683b00641bc66c9023f872ea4b4'
38 TARBALL_ARM_SHA1SUM = 'fc2f54db168887c5190c4c6686c869bedf668b4e'
36 SYSROOT_DIR_AMD64 = 'debian_wheezy_amd64-sysroot' 39 SYSROOT_DIR_AMD64 = 'debian_wheezy_amd64-sysroot'
37 SYSROOT_DIR_I386 = 'debian_wheezy_i386-sysroot' 40 SYSROOT_DIR_I386 = 'debian_wheezy_i386-sysroot'
41 SYSROOT_DIR_ARM = 'debian_wheezy_arm-sysroot'
38 42
39 43
40 def get_sha1(filename): 44 def get_sha1(filename):
41 sha1 = hashlib.sha1() 45 sha1 = hashlib.sha1()
42 with open(filename, 'rb') as f: 46 with open(filename, 'rb') as f:
43 while True: 47 while True:
44 # Read in 1mb chunks, so it doesn't all have to be loaded into memory. 48 # Read in 1mb chunks, so it doesn't all have to be loaded into memory.
45 chunk = f.read(1024*1024) 49 chunk = f.read(1024*1024)
46 if not chunk: 50 if not chunk:
47 break 51 break
48 sha1.update(chunk) 52 sha1.update(chunk)
49 return sha1.hexdigest() 53 return sha1.hexdigest()
50 54
51 55
52 def main(args): 56 def main(args):
53 if options.arch not in ['amd64', 'i386']: 57 if options.arch not in ['amd64', 'i386', 'arm']:
54 print 'Unknown architecture: %s' % options.arch 58 print 'Unknown architecture: %s' % options.arch
55 return 1 59 return 1
56 60
57 if options.linux_only: 61 if options.linux_only:
58 # This argument is passed when run from the gclient hooks. 62 # This argument is passed when run from the gclient hooks.
59 # In this case we return early on non-linux platforms. 63 # In this case we return early on non-linux platforms.
60 if not sys.platform.startswith('linux'): 64 if not sys.platform.startswith('linux'):
61 return 0 65 return 0
62 66
63 # Only install the sysroot for an Official Chrome Linux build.
64 defined = ['branding=Chrome', 'buildtype=Official']
65 undefined = ['chromeos=1']
66 gyp_defines = os.environ.get('GYP_DEFINES', '') 67 gyp_defines = os.environ.get('GYP_DEFINES', '')
67 for option in defined: 68
68 if option not in gyp_defines: 69 # Only install the sysroot for an Official Chrome Linux build, except
69 return 0 70 # for ARM where we always use a sysroot.
70 for option in undefined: 71 if options.arch != 'arm':
71 if option in gyp_defines: 72 defined = ['branding=Chrome', 'buildtype=Official']
72 return 0 73 undefined = ['chromeos=1']
74 for option in defined:
75 if option not in gyp_defines:
76 return 0
77 for option in undefined:
78 if option in gyp_defines:
79 return 0
73 80
74 # Check for optional target_arch and only install for that architecture. 81 # Check for optional target_arch and only install for that architecture.
75 # If target_arch is not specified, then only install for the host 82 # If target_arch is not specified, then only install for the host
76 # architecture. 83 # architecture.
77 host_arch = '' 84 target_arch = ''
78 if 'target_arch=x64' in gyp_defines: 85 if 'target_arch=x64' in gyp_defines:
79 host_arch = 'amd64' 86 target_arch = 'amd64'
80 elif 'target_arch=ia32' in gyp_defines: 87 elif 'target_arch=ia32' in gyp_defines:
81 host_arch = 'i386' 88 target_arch = 'i386'
89 elif 'target_arch=arm' in gyp_defines:
90 target_arch = 'arm'
82 else: 91 else:
83 # Figure out host arch using build/detect_host_arch.py. 92 # Figure out host arch using build/detect_host_arch.py and
93 # set target_arch to host arch
84 SRC_DIR = os.path.abspath( 94 SRC_DIR = os.path.abspath(
85 os.path.join(SCRIPT_DIR, '..', '..', '..', '..')) 95 os.path.join(SCRIPT_DIR, '..', '..', '..', '..'))
86 sys.path.append(os.path.join(SRC_DIR, 'build')) 96 sys.path.append(os.path.join(SRC_DIR, 'build'))
87 import detect_host_arch 97 import detect_host_arch
88 98
89 detected_host_arch = detect_host_arch.HostArch() 99 detected_host_arch = detect_host_arch.HostArch()
90 if detected_host_arch == 'x64': 100 if detected_host_arch == 'x64':
91 host_arch = 'amd64' 101 target_arch = 'amd64'
92 elif detected_host_arch == 'ia32': 102 elif detected_host_arch == 'ia32':
93 host_arch = 'i386' 103 target_arch = 'i386'
94 if host_arch != options.arch: 104 elif detected_host_arch == 'arm':
105 target_arch = 'arm'
106
107 if target_arch != options.arch:
95 return 0 108 return 0
96 109
97 # The sysroot directory should match the one specified in build/common.gypi. 110 # The sysroot directory should match the one specified in build/common.gypi.
98 # TODO(thestig) Consider putting this else where to avoid having to recreate 111 # TODO(thestig) Consider putting this else where to avoid having to recreate
99 # it on every build. 112 # it on every build.
100 linux_dir = os.path.dirname(SCRIPT_DIR) 113 linux_dir = os.path.dirname(SCRIPT_DIR)
101 if options.arch == 'amd64': 114 if options.arch == 'amd64':
102 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64) 115 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64)
103 tarball_filename = TARBALL_AMD64 116 tarball_filename = TARBALL_AMD64
104 tarball_sha1sum = TARBALL_AMD64_SHA1SUM 117 tarball_sha1sum = TARBALL_AMD64_SHA1SUM
105 else: 118 revision = REVISION
119 elif options.arch == 'arm':
Lei Zhang 2014/10/21 22:16:55 nit: also do it in the order of: amd64, i386, arm?
Sam Clegg 2014/10/21 22:41:03 Done.
120 sysroot = os.path.join(linux_dir, SYSROOT_DIR_ARM)
121 tarball_filename = TARBALL_ARM
122 tarball_sha1sum = TARBALL_ARM_SHA1SUM
123 revision = ARM_REVISION
124 elif options.arch == 'i386':
106 sysroot = os.path.join(linux_dir, SYSROOT_DIR_I386) 125 sysroot = os.path.join(linux_dir, SYSROOT_DIR_I386)
107 tarball_filename = TARBALL_I386 126 tarball_filename = TARBALL_I386
108 tarball_sha1sum = TARBALL_I386_SHA1SUM 127 tarball_sha1sum = TARBALL_I386_SHA1SUM
109 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, REVISION, tarball_filename) 128 revision = REVISION
129 else:
130 assert(false)
131
132
133 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, revision, tarball_filename)
110 134
111 stamp = os.path.join(sysroot, '.stamp') 135 stamp = os.path.join(sysroot, '.stamp')
112 if os.path.exists(stamp): 136 if os.path.exists(stamp):
113 with open(stamp) as s: 137 with open(stamp) as s:
114 if s.read() == url: 138 if s.read() == url:
115 print 'Debian Wheezy %s root image already up-to-date: %s' % \ 139 print 'Debian Wheezy %s root image already up-to-date: %s' % \
116 (options.arch, sysroot) 140 (options.arch, sysroot)
117 return 0 141 return 0
118 142
119 print 'Installing Debian Wheezy %s root image: %s' % (options.arch, sysroot) 143 print 'Installing Debian Wheezy %s root image: %s' % (options.arch, sysroot)
120 if os.path.isdir(sysroot): 144 if os.path.isdir(sysroot):
121 shutil.rmtree(sysroot) 145 shutil.rmtree(sysroot)
122 os.mkdir(sysroot) 146 os.mkdir(sysroot)
123 tarball = os.path.join(sysroot, tarball_filename) 147 tarball = os.path.join(sysroot, tarball_filename)
124 subprocess.check_call(['curl', '-L', url, '-o', tarball]) 148 print 'Downloading %s' % url
149 sys.stdout.flush()
150 sys.stderr.flush()
151 subprocess.check_call(['curl', '--fail', '-L', url, '-o', tarball])
125 sha1sum = get_sha1(tarball) 152 sha1sum = get_sha1(tarball)
126 if sha1sum != tarball_sha1sum: 153 if sha1sum != tarball_sha1sum:
127 print 'Tarball sha1sum is wrong.' 154 print 'Tarball sha1sum is wrong.'
128 print 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum) 155 print 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum)
129 return 1 156 return 1
130 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot]) 157 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot])
131 os.remove(tarball) 158 os.remove(tarball)
132 159
133 with open(stamp, 'w') as s: 160 with open(stamp, 'w') as s:
134 s.write(url) 161 s.write(url)
135 return 0 162 return 0
136 163
137 164
138 if __name__ == '__main__': 165 if __name__ == '__main__':
139 parser = optparse.OptionParser('usage: %prog [OPTIONS]') 166 parser = optparse.OptionParser('usage: %prog [OPTIONS]')
140 parser.add_option('', '--linux-only', dest='linux_only', action='store_true', 167 parser.add_option('--linux-only', action='store_true',
141 default=False, help='Only install sysroot for official ' 168 default=False, help='Only install sysroot for official '
142 'Linux builds') 169 'Linux builds')
143 parser.add_option('', '--arch', dest='arch', 170 parser.add_option('--arch', help='Sysroot architecture: i386, amd64 or arm')
144 help='Sysroot architecture, i386 or amd64')
145 options, args = parser.parse_args() 171 options, args = parser.parse_args()
146 sys.exit(main(options)) 172 sys.exit(main(args))
OLDNEW
« build/linux/install-arm-sysroot.py ('K') | « build/linux/install-arm-sysroot.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698