Skip to content

Commit

Permalink
Integrate r-install-deps to mx_fastr
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Marek committed Sep 28, 2021
1 parent 7e61c59 commit 593c9eb
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 63 deletions.
11 changes: 2 additions & 9 deletions mx.fastr/mx_fastr.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import mx_fastr_dists
import mx_subst
from mx_fastr_dists import FastRReleaseProject #pylint: disable=unused-import
import mx_fastr_install_deps
import mx_fastr_edinclude
import mx_unittest

Expand Down Expand Up @@ -954,21 +955,13 @@ def generate_parser(args=None, out=None):
postprocess=lambda content: cast_pattern.sub("(_localctx,", content),
args=args, out=out)


def install_deps(args=None):
'''Installs all the dependencies for FastR and GNU-R, so that FastR can be built from sources. '''
sys.path.append(join(_fastr_suite.dir, 'mx.fastr'))
from install_dependencies import install_dependencies
install_dependencies()


mx_register_dynamic_suite_constituents = mx_fastr_dists.mx_register_dynamic_suite_constituents # pylint: disable=C0103


mx_unittest.add_config_participant(_unittest_config_participant)

_commands = {
'r-install-deps' : [install_deps],
'r-install-deps' : [mx_fastr_install_deps.install_dependencies, '[options]'],
'r' : [rshell, '[options]'],
'R' : [rshell, '[options]'],
'rscript' : [rscript, '[options]'],
Expand Down
126 changes: 72 additions & 54 deletions mx.fastr/install_dependencies.py → mx.fastr/mx_fastr_install_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
- Ubuntu 18.04 and newer.
- Fedora 34 and newer.
"""
from argparse import ArgumentParser, RawTextHelpFormatter

import mx
import os
import subprocess

SUPPORTED_DISTROS = ["Oracle Linux Server 8", "Ubuntu 18.04 and newer", "Fedora 34 and newer"]
DRY_RUN = False

UBUNTU_PACKAGES = [
# Dependencies for Sulong and FastR:
Expand Down Expand Up @@ -88,60 +90,63 @@
"libcurl-devel",
]

UBUNTU_INSTALL_COMMAND = ["sudo", "apt-get", "install"] + UBUNTU_PACKAGES
FEDORA_INSTALL_COMMAND = ["sudo", "dnf", "install"] + FEDORA_PACKAGES
OL_INSTALL_COMMAND = ["sudo", "yum", "install"] + FEDORA_PACKAGES

UBUNTU_DISTR_NAME = "Ubuntu"
FEDORA_DISTR_NAME = "Fedora"
OL_DISTR_NAME = "Oracle Linux Server"

# Packages are the same for Fedora 34 and OL 8.
OL_PACKAGES = FEDORA_PACKAGES

class _LinuxDistribution:
def __init__(self, name, version):
self.name = name
self.version = version
self.major_int_version = 0
if name == UBUNTU_DISTR_NAME:
self.major_int_version = int(version.split(".")[0])
elif name == FEDORA_DISTR_NAME:
self.major_int_version = int(version)
elif name == OL_DISTR_NAME:
self.major_int_version = int(version)

def __repr__(self):
return self.name + " " + self.version

# Minimal version of supported distributions
MIN_SUPPORTED_DISTROS = [
_LinuxDistribution("Ubuntu", "18.04"),
_LinuxDistribution("Fedora", "34"),
_LinuxDistribution("Oracle Linux Server", "8"),
]

def _unsupported_distribution(distr):
print("Unsupported Linux distribution: %s %s" % (distr.name, distr.version)) # pylint: disable=superfluous-parens
print("Supported distros are: %s" % ", ".join(SUPPORTED_DISTROS)) # pylint: disable=superfluous-parens
exit(1)

def _install_ubuntu_dependencies(distr):
major_version = int(distr.version.split(".")[0])
if major_version < 18:
print("Ubuntu is supported in version 18.04 or newer, current version is %s", distr.version) # pylint: disable=superfluous-parens
exit(1)
cmd = ["sudo", "apt-get", "install"] + UBUNTU_PACKAGES
print("Running " + " ".join(cmd)) # pylint: disable=superfluous-parens
ret = subprocess.call(cmd)
if ret != 0:
print("Ubuntu dependencies installation failed") # pylint: disable=superfluous-parens
exit(1)
pass

def _install_fedora_dependencies(distr):
if int(distr.version) < 34:
print("Fedora is supported in version 34 or newer, current version is %s" % distr.version) # pylint: disable=superfluous-parens
exit(1)
cmd = ["sudo", "dnf", "install"] + FEDORA_PACKAGES
print("Running " + " ".join(cmd)) # pylint: disable=superfluous-parens
ret = subprocess.call(cmd)
def print_info(distr):
msg = "Current distro is %s" % str(distr) + "\n"
msg += " Supported distros are: %s" % ", ".join([str(supported_distro) for supported_distro in MIN_SUPPORTED_DISTROS]) + "\n"
msg += " On Debian-based systems, packages would be installed with `" + " ".join(UBUNTU_INSTALL_COMMAND) + "`\n"
msg += " On RedHat-based systems, packages would be installed with `" + " ".join(FEDORA_INSTALL_COMMAND) + "`\n"
mx.log(msg)

def _is_distr_supported(linux_distr):
for supported_distro in MIN_SUPPORTED_DISTROS:
supported_distr_name = supported_distro.name
min_supported_distr_version = supported_distro.major_int_version
if linux_distr.name == supported_distr_name and linux_distr.major_int_version >= min_supported_distr_version:
return True
return False

def _install_distr_dependencies(distr, cmds):
mx.log("Running: " + " ".join(cmds))
ret = subprocess.call(cmds)
if ret != 0:
print("Fedora dependencies installation failed") # pylint: disable=superfluous-parens
exit(1)

def _install_ol_dependencies(distr):
major_version = int(distr.version.split(".")[0])
if major_version < 8:
print("Oracle Linux Server is supported in version 8 or newer, current version is %s" % distr.version) # pylint: disable=superfluous-parens
exit(1)
# dnf command is available from OL 8.
cmd = ["sudo", "dnf", "install"] + FEDORA_PACKAGES
print("Running " + " ".join(cmd)) # pylint: disable=superfluous-parens
ret = subprocess.call(cmd)
if ret != 0:
print("oraclelinux dependencies installation failed") # pylint: disable=superfluous-parens
exit(1)
mx.abort("Installation of dependencies on %s failed" % distr)

def _get_distribution():
if not os.path.exists("/etc/os-release"):
print("Unknown Linux distribution - /etc/os-release does not exist") # pylint: disable=superfluous-parens
exit(1)
mx.abort("Unknown Linux distribution - /etc/os-release does not exist")
assert os.path.exists("/etc/os-release")
with open("/etc/os-release", "r") as os_release_file:
for line in os_release_file.readlines():
Expand All @@ -155,15 +160,28 @@ def _get_distribution():
return _LinuxDistribution(distr_name, distr_version)


def install_dependencies():
distr = _get_distribution()
print("Current distribution is %s:%s" % (distr.name, distr.version)) # pylint: disable=superfluous-parens
if distr.name == "Ubuntu":
_install_ubuntu_dependencies(distr)
elif distr.name == "Fedora":
_install_fedora_dependencies(distr)
elif distr.name == "Oracle Linux Server":
_install_ol_dependencies(distr)
else:
_unsupported_distribution(distr)
def install_dependencies(args):
"""Installs all the dependencies for FastR and GNU-R, so that FastR can be built from sources.
Currently, only Ubuntu, Fedora and Oracle Linux Server are supported. There are no plans to
support MacOS.
"""
parser = ArgumentParser(prog='mx r-install-deps', description=install_dependencies.__doc__, formatter_class=RawTextHelpFormatter)
parser.add_argument('-i', '--info', action='store_true', default=False,
help="Only print info about what would be run for Debian-based and RedHat-based systems, do not run anything")
parsed_args = parser.parse_args(args)

distr = _get_distribution()
if parsed_args.info:
print_info(distr)
return

if not _is_distr_supported(distr):
mx.abort("Unsupported Linux distribution: %s, run again with `--info`\n" % distr)

if distr.name == UBUNTU_DISTR_NAME:
_install_distr_dependencies(distr, UBUNTU_INSTALL_COMMAND)
elif distr.name == FEDORA_DISTR_NAME:
_install_distr_dependencies(distr, FEDORA_INSTALL_COMMAND)
elif distr.name == OL_DISTR_NAME:
_install_distr_dependencies(distr, OL_INSTALL_COMMAND)

0 comments on commit 593c9eb

Please sign in to comment.