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

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

Issue 843683003: Revert of 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')
45 44
46 45 def get_sha1(filename):
47 def GetSha1(filename):
48 sha1 = hashlib.sha1() 46 sha1 = hashlib.sha1()
49 with open(filename, 'rb') as f: 47 with open(filename, 'rb') as f:
50 while True: 48 while True:
51 # Read in 1mb chunks, so it doesn't all have to be loaded into memory. 49 # Read in 1mb chunks, so it doesn't all have to be loaded into memory.
52 chunk = f.read(1024*1024) 50 chunk = f.read(1024*1024)
53 if not chunk: 51 if not chunk:
54 break 52 break
55 sha1.update(chunk) 53 sha1.update(chunk)
56 return sha1.hexdigest() 54 return sha1.hexdigest()
57 55
58 56
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
88 def main(): 57 def main():
89 gyp_defines = os.environ.get('GYP_DEFINES', '') 58 if options.arch not in ['amd64', 'i386', 'arm']:
90 59 print 'Unknown architecture: %s' % options.arch
91 if options.arch: 60 return 1
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
98 61
99 if options.linux_only: 62 if options.linux_only:
100 # This argument is passed when run from the gclient hooks. 63 # This argument is passed when run from the gclient hooks.
101 # In this case we return early on non-linux platforms. 64 # In this case we return early on non-linux platforms.
102 if not sys.platform.startswith('linux'): 65 if not sys.platform.startswith('linux'):
103 return 0 66 return 0
104 67
68 gyp_defines = os.environ.get('GYP_DEFINES', '')
69
105 # Only install the sysroot for an Official Chrome Linux build, except 70 # Only install the sysroot for an Official Chrome Linux build, except
106 # for ARM where we always use a sysroot. 71 # for ARM where we always use a sysroot.
107 if target_arch != 'arm': 72 if options.arch != 'arm':
108 defined = ['branding=Chrome', 'buildtype=Official'] 73 defined = ['branding=Chrome', 'buildtype=Official']
109 undefined = ['chromeos=1'] 74 undefined = ['chromeos=1']
110 for option in defined: 75 for option in defined:
111 if option not in gyp_defines: 76 if option not in gyp_defines:
112 return 0 77 return 0
113 for option in undefined: 78 for option in undefined:
114 if option in gyp_defines: 79 if option in gyp_defines:
115 return 0 80 return 0
116 81
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
117 # The sysroot directory should match the one specified in build/common.gypi. 111 # The sysroot directory should match the one specified in build/common.gypi.
118 # TODO(thestig) Consider putting this else where to avoid having to recreate 112 # TODO(thestig) Consider putting this else where to avoid having to recreate
119 # it on every build. 113 # it on every build.
120 linux_dir = os.path.dirname(SCRIPT_DIR) 114 linux_dir = os.path.dirname(SCRIPT_DIR)
121 if target_arch == 'amd64': 115 if options.arch == 'amd64':
122 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64) 116 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64)
123 tarball_filename = TARBALL_AMD64 117 tarball_filename = TARBALL_AMD64
124 tarball_sha1sum = TARBALL_AMD64_SHA1SUM 118 tarball_sha1sum = TARBALL_AMD64_SHA1SUM
125 revision = REVISION_AMD64 119 revision = REVISION_AMD64
126 elif target_arch == 'arm': 120 elif options.arch == 'arm':
127 sysroot = os.path.join(linux_dir, SYSROOT_DIR_ARM) 121 sysroot = os.path.join(linux_dir, SYSROOT_DIR_ARM)
128 tarball_filename = TARBALL_ARM 122 tarball_filename = TARBALL_ARM
129 tarball_sha1sum = TARBALL_ARM_SHA1SUM 123 tarball_sha1sum = TARBALL_ARM_SHA1SUM
130 revision = REVISION_ARM 124 revision = REVISION_ARM
131 elif target_arch == 'i386': 125 elif options.arch == 'i386':
132 sysroot = os.path.join(linux_dir, SYSROOT_DIR_I386) 126 sysroot = os.path.join(linux_dir, SYSROOT_DIR_I386)
133 tarball_filename = TARBALL_I386 127 tarball_filename = TARBALL_I386
134 tarball_sha1sum = TARBALL_I386_SHA1SUM 128 tarball_sha1sum = TARBALL_I386_SHA1SUM
135 revision = REVISION_I386 129 revision = REVISION_I386
136 else: 130 else:
137 print 'Unknown architecture: %s' % target_arch
138 assert(False) 131 assert(False)
139 132
133
140 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, revision, tarball_filename) 134 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, revision, tarball_filename)
141 135
142 stamp = os.path.join(sysroot, '.stamp') 136 stamp = os.path.join(sysroot, '.stamp')
143 if os.path.exists(stamp): 137 if os.path.exists(stamp):
144 with open(stamp) as s: 138 with open(stamp) as s:
145 if s.read() == url: 139 if s.read() == url:
146 print 'Debian Wheezy %s root image already up-to-date: %s' % \ 140 print 'Debian Wheezy %s root image already up-to-date: %s' % \
147 (target_arch, sysroot) 141 (options.arch, sysroot)
148 return 0 142 return 0
149 143
150 print 'Installing Debian Wheezy %s root image: %s' % (target_arch, sysroot) 144 print 'Installing Debian Wheezy %s root image: %s' % (options.arch, sysroot)
151 if os.path.isdir(sysroot): 145 if os.path.isdir(sysroot):
152 shutil.rmtree(sysroot) 146 shutil.rmtree(sysroot)
153 os.mkdir(sysroot) 147 os.mkdir(sysroot)
154 tarball = os.path.join(sysroot, tarball_filename) 148 tarball = os.path.join(sysroot, tarball_filename)
155 print 'Downloading %s' % url 149 print 'Downloading %s' % url
156 sys.stdout.flush() 150 sys.stdout.flush()
157 sys.stderr.flush() 151 sys.stderr.flush()
158 subprocess.check_call(['curl', '--fail', '-L', url, '-o', tarball]) 152 subprocess.check_call(['curl', '--fail', '-L', url, '-o', tarball])
159 sha1sum = GetSha1(tarball) 153 sha1sum = get_sha1(tarball)
160 if sha1sum != tarball_sha1sum: 154 if sha1sum != tarball_sha1sum:
161 print 'Tarball sha1sum is wrong.' 155 print 'Tarball sha1sum is wrong.'
162 print 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum) 156 print 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum)
163 return 1 157 return 1
164 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot]) 158 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot])
165 os.remove(tarball) 159 os.remove(tarball)
166 160
167 with open(stamp, 'w') as s: 161 with open(stamp, 'w') as s:
168 s.write(url) 162 s.write(url)
169 return 0 163 return 0
170 164
171 165
172 if __name__ == '__main__': 166 if __name__ == '__main__':
173 parser = optparse.OptionParser('usage: %prog [OPTIONS]') 167 parser = optparse.OptionParser('usage: %prog [OPTIONS]')
174 parser.add_option('--linux-only', action='store_true', 168 parser.add_option('--linux-only', action='store_true',
175 default=False, help='Only install sysroot for official ' 169 default=False, help='Only install sysroot for official '
176 'Linux builds') 170 'Linux builds')
177 parser.add_option('--arch', type='choice', choices=valid_archs, 171 parser.add_option('--arch', help='Sysroot architecture: i386, amd64 or arm')
178 help='Sysroot architecture: %s' % ', '.join(valid_archs)) 172 options, args = parser.parse_args()
179 options, _ = parser.parse_args()
180 sys.exit(main()) 173 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