blob: 1687b94b10336941d0a8db0cb8774f11aecd2806 [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
import operator
import os
import platform
import re
import subprocess
import sys
{'number': '12.04', 'codename': 'precise'},
{'number': '14.04', 'codename': 'trusty'},
{'number': '14.10', 'codename': 'utopic'},
{'number': '15.04', 'codename': 'vivid'},
{'number': '15.10', 'codename': 'wily'},
# Packages needed for chromeos only.
_packages_chromeos_dev = (
# Packages needed for development.
_packages_dev = (
# Run-time libraries required by chromeos only.
_packages_chromeos_lib = (
# Full list of required run-time libraries.
_packages_lib = (
# Debugging symbols for all of the run-time libraries.
_packages_dbg = (
# 32-bit libraries needed e.g. to compile V8 snapshot for Android or armhf.
_packages_lib32 = (
# arm cross toolchain packages needed to build chrome on armhf.
_packages_arm = (
# Packages to build NaCl, its toolchains, and its ports.
_packages_naclports = (
_packages_nacl = (
def is_userland_64_bit():
return platform.architecture()[0] == '64bit'
def package_exists(pkg):
return pkg in subprocess.check_output(['apt-cache', 'pkgnames']).splitlines()
def lsb_release_short_codename():
return subprocess.check_output(
['lsb_release', '--codename', '--short']).strip()
def write_error(message):
sys.stderr.write('ERROR: %s\n' % message)
def nonfatal_get_output(*popenargs, **kwargs):
process = subprocess.Popen(
stdout=subprocess.PIPE, stderr=subprocess.PIPE, *popenargs, **kwargs)
stdout, stderr = process.communicate()
retcode = process.poll()
return retcode, stdout, stderr
def compute_dynamic_package_lists():
global _packages_arm
global _packages_dbg
global _packages_dev
global _packages_lib
global _packages_lib32
global _packages_nacl
if is_userland_64_bit():
# 64-bit systems need a minimum set of 32-bit compat packages
# for the pre-built NaCl binaries.
_packages_dev += (
# When cross building for arm/Android on 64-bit systems the host binaries
# that are part of v8 need to be compiled with -m32 which means
# that basic multilib support is needed.
# gcc-multilib conflicts with the arm cross compiler (at least in trusty)
# but g++-X.Y-multilib gives us the 32-bit support that we need. Find out
# the appropriate value of X and Y by seeing what version the current
# distribution's g++-multilib package depends on.
output = subprocess.check_output(['apt-cache', 'depends', 'g++-multilib'])
multilib_package ='g\+\+-[0-9.]+-multilib', output).group()
_packages_lib32 += (multilib_package,)
lsb_codename = lsb_release_short_codename()
# Find the proper version of libstdc++6-4.x-dbg.
if lsb_codename == 'precise':
_packages_dbg += ('libstdc++6-4.6-dbg',)
elif lsb_codename == 'trusty':
_packages_dbg += ('libstdc++6-4.8-dbg',)
_packages_dbg += ('libstdc++6-4.9-dbg',)
# Work around for dependency issue Ubuntu/Trusty: .
if lsb_codename == 'trusty':
_packages_arm += (
# Find the proper version of libgbm-dev. We can't just install libgbm-dev as
# it depends on mesa, and only one version of mesa can exists on the system.
# Hence we must match the same version or this entire script will fail.
mesa_variant = ''
for variant in ('-lts-trusty', '-lts-utopic'):
rc, stdout, stderr = nonfatal_get_output(
['dpkg-query', '-Wf\'{Status}\'', 'libgl1-mesa-glx' + variant])
if 'ok installed' in output:
mesa_variant = variant
_packages_dev += (
'libgbm-dev' + mesa_variant,
'libgl1-mesa-dev' + mesa_variant,
'libgles2-mesa-dev' + mesa_variant,
'mesa-common-dev' + mesa_variant,
if package_exists('ttf-mscorefonts-installer'):
_packages_dev += ('ttf-mscorefonts-installer',)
_packages_dev += ('msttcorefonts',)
if package_exists('libnspr4-dbg'):
_packages_dbg += ('libnspr4-dbg', 'libnss3-dbg')
_packages_lib += ('libnspr4', 'libnss3')
_packages_dbg += ('libnspr4-0d-dbg', 'libnss3-1d-dbg')
_packages_lib += ('libnspr4-0d', 'libnss3-1d')
if package_exists('libjpeg-dev'):
_packages_dev += ('libjpeg-dev',)
_packages_dev += ('libjpeg62-dev',)
if package_exists('libudev1'):
_packages_dev += ('libudev1',)
_packages_nacl += ('libudev1:i386',)
_packages_dev += ('libudev0',)
_packages_nacl += ('libudev0:i386',)
if package_exists('libbrlapi0.6'):
_packages_dev += ('libbrlapi0.6',)
_packages_dev += ('libbrlapi0.5',)
if package_exists('apache2-bin'):
_packages_dev += ('apache2-bin',)
_packages_dev += ('apache2.2-bin',)
if package_exists('xfonts-mathml'):
_packages_dev += ('xfonts-mathml',)
# Some packages are only needed if the distribution actually supports
# installing them.
if package_exists('appmenu-gtk'):
_packages_lib += ('appmenu-gtk',)
_packages_dev += _packages_chromeos_dev
_packages_lib += _packages_chromeos_lib
_packages_nacl += _packages_naclports
def quick_check(packages):
rc, stdout, stderr = nonfatal_get_output([
'dpkg-query', '-W', '-f', '${PackageSpec}:${Status}\n'] + list(packages))
if rc == 0 and not stderr:
return 0
print stderr
return 1
def main(argv):
parser = argparse.ArgumentParser()
parser.add_argument('--quick-check', action='store_true',
help='quickly try to determine if dependencies are '
'installed (this avoids interactive prompts and '
'sudo commands so might not be 100% accurate)')
parser.add_argument('--unsupported', action='store_true',
help='attempt installation even on unsupported systems')
args = parser.parse_args(argv)
lsb_codename = lsb_release_short_codename()
if not args.unsupported and not args.quick_check:
if lsb_codename not in map(
operator.itemgetter('codename'), SUPPORTED_UBUNTU_VERSIONS):
supported_ubuntus = ['%(number)s (%(codename)s)' % v
write_error('Only Ubuntu %s are currently supported.' %
', '.join(supported_ubuntus))
return 1
if platform.machine() not in ('i686', 'x86_64'):
write_error('Only x86 architectures are currently supported.')
return 1
if os.geteuid() != 0 and not args.quick_check:
print 'Running as non-root user.'
print 'You might have to enter your password one or more times'
print 'for \'sudo\'.'
packages = (_packages_dev + _packages_lib + _packages_dbg + _packages_lib32 +
_packages_arm + _packages_nacl)
def packages_key(pkg):
s = pkg.rsplit(':', 1)
if len(s) == 1:
return (s, '')
return s
packages = sorted(set(packages), key=packages_key)
if args.quick_check:
return quick_check(packages)
return 0
if __name__ == '__main__':