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

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

Issue 843643003: Only run install-debian.wheezy.sysroot.py once during runhooks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sysroot_download
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
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 else:
85 print "Unknown host arch: %s" % detected_host_arch
86
87 return None
88
89
57 def main(): 90 def main():
58 if options.arch not in ['amd64', 'i386', 'arm']:
59 print 'Unknown architecture: %s' % options.arch
60 return 1
61
62 if options.linux_only: 91 if options.linux_only:
63 # This argument is passed when run from the gclient hooks. 92 # This argument is passed when run from the gclient hooks.
64 # In this case we return early on non-linux platforms. 93 # In this case we return early on non-linux platforms.
65 if not sys.platform.startswith('linux'): 94 if not sys.platform.startswith('linux'):
66 return 0 95 return 0
67 96
68 gyp_defines = os.environ.get('GYP_DEFINES', '') 97 gyp_defines = os.environ.get('GYP_DEFINES', '')
69 98
70 # Only install the sysroot for an Official Chrome Linux build, except 99 if options.arch:
71 # for ARM where we always use a sysroot. 100 target_arch = options.arch
72 if options.arch != 'arm': 101 else:
73 defined = ['branding=Chrome', 'buildtype=Official'] 102 target_arch = DetectArch(gyp_defines)
74 undefined = ['chromeos=1'] 103 if not target_arch:
75 for option in defined: 104 print 'Unable to detect host architecture'
76 if option not in gyp_defines: 105 return 1
77 return 0
78 for option in undefined:
79 if option in gyp_defines:
80 return 0
81 106
82 # Check for optional target_arch and only install for that architecture. 107 if options.linux_only and target_arch != 'arm':
83 # If target_arch is not specified, then only install for the host 108 # When run from runhooks, only install the sysroot for an Official Chrome
84 # architecture. 109 # Linux build, except on ARM where we always use a sysroot.
85 target_arch = '' 110 defined = ['branding=Chrome', 'buildtype=Official']
86 if 'target_arch=x64' in gyp_defines: 111 undefined = ['chromeos=1']
87 target_arch = 'amd64' 112 for option in defined:
88 elif 'target_arch=ia32' in gyp_defines: 113 if option not in gyp_defines:
89 target_arch = 'i386' 114 return 0
90 elif 'target_arch=arm' in gyp_defines: 115 for option in undefined:
91 target_arch = 'arm' 116 if option in gyp_defines:
92 else: 117 return 0
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 118
111 # The sysroot directory should match the one specified in build/common.gypi. 119 # 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 120 # TODO(thestig) Consider putting this else where to avoid having to recreate
113 # it on every build. 121 # it on every build.
114 linux_dir = os.path.dirname(SCRIPT_DIR) 122 linux_dir = os.path.dirname(SCRIPT_DIR)
115 if options.arch == 'amd64': 123 if target_arch == 'amd64':
116 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64) 124 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64)
117 tarball_filename = TARBALL_AMD64 125 tarball_filename = TARBALL_AMD64
118 tarball_sha1sum = TARBALL_AMD64_SHA1SUM 126 tarball_sha1sum = TARBALL_AMD64_SHA1SUM
119 revision = REVISION_AMD64 127 revision = REVISION_AMD64
120 elif options.arch == 'arm': 128 elif target_arch == 'arm':
121 sysroot = os.path.join(linux_dir, SYSROOT_DIR_ARM) 129 sysroot = os.path.join(linux_dir, SYSROOT_DIR_ARM)
122 tarball_filename = TARBALL_ARM 130 tarball_filename = TARBALL_ARM
123 tarball_sha1sum = TARBALL_ARM_SHA1SUM 131 tarball_sha1sum = TARBALL_ARM_SHA1SUM
124 revision = REVISION_ARM 132 revision = REVISION_ARM
125 elif options.arch == 'i386': 133 elif target_arch == 'i386':
126 sysroot = os.path.join(linux_dir, SYSROOT_DIR_I386) 134 sysroot = os.path.join(linux_dir, SYSROOT_DIR_I386)
127 tarball_filename = TARBALL_I386 135 tarball_filename = TARBALL_I386
128 tarball_sha1sum = TARBALL_I386_SHA1SUM 136 tarball_sha1sum = TARBALL_I386_SHA1SUM
129 revision = REVISION_I386 137 revision = REVISION_I386
130 else: 138 else:
139 print 'Unknown architecture: %s' % target_arch
131 assert(False) 140 assert(False)
132 141
133
134 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, revision, tarball_filename) 142 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, revision, tarball_filename)
135 143
136 stamp = os.path.join(sysroot, '.stamp') 144 stamp = os.path.join(sysroot, '.stamp')
137 if os.path.exists(stamp): 145 if os.path.exists(stamp):
138 with open(stamp) as s: 146 with open(stamp) as s:
139 if s.read() == url: 147 if s.read() == url:
140 print 'Debian Wheezy %s root image already up-to-date: %s' % \ 148 print 'Debian Wheezy %s root image already up-to-date: %s' % \
141 (options.arch, sysroot) 149 (target_arch, sysroot)
142 return 0 150 return 0
143 151
144 print 'Installing Debian Wheezy %s root image: %s' % (options.arch, sysroot) 152 print 'Installing Debian Wheezy %s root image: %s' % (target_arch, sysroot)
145 if os.path.isdir(sysroot): 153 if os.path.isdir(sysroot):
146 shutil.rmtree(sysroot) 154 shutil.rmtree(sysroot)
147 os.mkdir(sysroot) 155 os.mkdir(sysroot)
148 tarball = os.path.join(sysroot, tarball_filename) 156 tarball = os.path.join(sysroot, tarball_filename)
149 print 'Downloading %s' % url 157 print 'Downloading %s' % url
150 sys.stdout.flush() 158 sys.stdout.flush()
151 sys.stderr.flush() 159 sys.stderr.flush()
152 subprocess.check_call(['curl', '--fail', '-L', url, '-o', tarball]) 160 subprocess.check_call(['curl', '--fail', '-L', url, '-o', tarball])
153 sha1sum = get_sha1(tarball) 161 sha1sum = GetSha1(tarball)
154 if sha1sum != tarball_sha1sum: 162 if sha1sum != tarball_sha1sum:
155 print 'Tarball sha1sum is wrong.' 163 print 'Tarball sha1sum is wrong.'
156 print 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum) 164 print 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum)
157 return 1 165 return 1
158 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot]) 166 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot])
159 os.remove(tarball) 167 os.remove(tarball)
160 168
161 with open(stamp, 'w') as s: 169 with open(stamp, 'w') as s:
162 s.write(url) 170 s.write(url)
163 return 0 171 return 0
164 172
165 173
166 if __name__ == '__main__': 174 if __name__ == '__main__':
167 parser = optparse.OptionParser('usage: %prog [OPTIONS]') 175 parser = optparse.OptionParser('usage: %prog [OPTIONS]')
168 parser.add_option('--linux-only', action='store_true', 176 parser.add_option('--linux-only', action='store_true',
169 default=False, help='Only install sysroot for official ' 177 default=False, help='Only install sysroot for official '
170 'Linux builds') 178 'Linux builds')
171 parser.add_option('--arch', help='Sysroot architecture: i386, amd64 or arm') 179 parser.add_option('--arch', type='choice', choices=valid_archs,
172 options, args = parser.parse_args() 180 help='Sysroot architecture: %s' % ', '.join(valid_archs))
181 options, _ = parser.parse_args()
173 sys.exit(main()) 182 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