aboutsummaryrefslogtreecommitdiffstats
path: root/python/servo/bootstrap.py
diff options
context:
space:
mode:
authorUK992 <urbankrajnc92@gmail.com>2017-01-26 01:27:25 +0100
committerUK992 <urbankrajnc92@gmail.com>2017-02-08 19:53:48 +0100
commitf21d448530609b2c0144fee7e6e439498b748ce9 (patch)
tree4419b0968fae12cd99223f8577e274234e09f38b /python/servo/bootstrap.py
parentc48a326fb37976ec9e808825c9641602bccefa56 (diff)
downloadservo-f21d448530609b2c0144fee7e6e439498b748ce9.tar.gz
servo-f21d448530609b2c0144fee7e6e439498b748ce9.zip
Mach bootstrap: Improve and support more platforms
Diffstat (limited to 'python/servo/bootstrap.py')
-rw-r--r--python/servo/bootstrap.py44
1 files changed, 38 insertions, 6 deletions
diff --git a/python/servo/bootstrap.py b/python/servo/bootstrap.py
index 54862a885bd..f65cd7208e5 100644
--- a/python/servo/bootstrap.py
+++ b/python/servo/bootstrap.py
@@ -10,12 +10,44 @@ import os
import platform
import shutil
import subprocess
+from subprocess import PIPE
import servo.packages as packages
from servo.util import extract, download_file, host_triple
+def run_as_root(command):
+ if os.geteuid() != 0:
+ command.insert(0, 'sudo')
+ return subprocess.call(command)
+
+
+def install_salt_dependencies(context, force):
+ install = False
+ if context.distro == 'Ubuntu':
+ pkgs = ['build-essential', 'libssl-dev', 'libffi-dev', 'python-dev']
+ command = ['apt-get', 'install']
+ if subprocess.call(['dpkg', '-s'] + pkgs, stdout=PIPE, stderr=PIPE) != 0:
+ install = True
+ elif context.distro in ['CentOS', 'CentOS Linux', 'Fedora']:
+ installed_pkgs = str(subprocess.check_output(['rpm', '-qa'])).replace('\n', '|')
+ pkgs = ['gcc', 'libffi-devel', 'python-devel', 'openssl-devel']
+ for p in pkgs:
+ command = ['dnf', 'install']
+ if "|{}".format(p) not in installed_pkgs:
+ install = True
+ break
+
+ if install:
+ if force:
+ command.append('-y')
+ print("Installing missing Salt dependencies...")
+ run_as_root(command + pkgs)
+
+
def salt(context, force=False):
+ # Ensure Salt dependencies are installed
+ install_salt_dependencies(context, force)
# Ensure Salt is installed in the virtualenv
# It's not instaled globally because it's a large, non-required dependency,
# and the installation fails on Windows
@@ -23,8 +55,8 @@ def salt(context, force=False):
reqs_path = os.path.join(context.topdir, 'python', 'requirements-salt.txt')
process = subprocess.Popen(
["pip", "install", "-q", "-I", "-r", reqs_path],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE
+ stdout=PIPE,
+ stderr=PIPE
)
process.wait()
if process.returncode:
@@ -86,7 +118,6 @@ def salt(context, force=False):
pillar_file.write(json.dumps(pillar[filename]) + '\n')
cmd = [
- 'sudo',
# sudo escapes from the venv, need to use full path
find_executable('salt-call'),
'--local',
@@ -106,7 +137,7 @@ def salt(context, force=False):
# the actual highstate.
# Hence `--retcode-passthrough` is not helpful in dry-run mode,
# so only detect failures of the actual salt-call binary itself.
- retcode = subprocess.call(cmd + ['test=True'])
+ retcode = run_as_root(cmd + ['test=True'])
if retcode != 0:
print('Something went wrong while bootstrapping')
return retcode
@@ -120,7 +151,7 @@ def salt(context, force=False):
print('')
print('Running Salt bootstrap')
- retcode = subprocess.call(cmd + ['--retcode-passthrough'])
+ retcode = run_as_root(cmd + ['--retcode-passthrough'])
if retcode == 0:
print('Salt bootstrapping complete')
else:
@@ -219,7 +250,8 @@ def bootstrap(context, force=False):
bootstrapper = windows_msvc
elif "linux-gnu" in host_triple():
distro, version, _ = platform.linux_distribution()
- if distro == 'Ubuntu' and version == '14.04':
+ if distro in ['CentOS', 'CentOS Linux', 'Fedora', 'Ubuntu']:
+ context.distro = distro
bootstrapper = salt
if bootstrapper is None: