From: Waldemar Kozaczuk <jwkozac...@gmail.com> Committer: Waldemar Kozaczuk <jwkozac...@gmail.com> Branch: master
scripts/setup.py: move code to download aarch64 packages to its own script Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com> --- diff --git a/scripts/download_fedora_aarch64_packages.py b/scripts/download_fedora_aarch64_packages.py --- a/scripts/download_fedora_aarch64_packages.py +++ b/scripts/download_fedora_aarch64_packages.py @@ -0,0 +1,34 @@ +#!/usr/bin/python3 + +import subprocess, os, string, sys +from linux_distro import linux_distribution + +def aarch64_download(version): + gcc_packages = ['gcc', + 'glibc', + 'glibc-devel', + 'libgcc', + 'libstdc++', + 'libstdc++-devel', + 'libstdc++-static'] + boost_packages = ['boost-devel', + 'boost-static', + 'boost-system'] + osv_root = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..') + script_path = '%s/scripts/download_rpm_package.sh' % osv_root + destination = '%s/build/downloaded_packages/aarch64' % osv_root + + install_commands = ['%s %s %s %s/gcc' % (script_path, package, version, destination) for package in gcc_packages] + install_commands += ['%s %s %s %s/boost' % (script_path, package, version, destination) for package in boost_packages] + install_commands = ['rm -rf %s/gcc/install' % destination, + 'rm -rf %s/boost/install' % destination] + install_commands + return ' && '.join(install_commands) + +(name, version) = linux_distribution() +if name.lower() != 'fedora': + print("The distribution %s is not supported for cross-compiling aarch64 version of OSv" % name) + sys.exit(1) + +print('Downloading aarch64 packages to cross-compile ARM version ...') +subprocess.check_call(aarch64_download(version), shell=True) +print('Downloaded all aarch64 packages!') diff --git a/scripts/linux_distro.py b/scripts/linux_distro.py --- a/scripts/linux_distro.py +++ b/scripts/linux_distro.py @@ -0,0 +1,22 @@ +#!/usr/bin/python3 + +def linux_distribution(): + def parse_file(f): + res = {} + for line in f: + k, v = line.rstrip().split('=') + res[k] = v.strip('"') + return res + + try: + with open('/etc/os-release') as f: + info = parse_file(f) + return (info['NAME'], info['VERSION_ID']) + except FileNotFoundError: + try: + with open('/etc/lsb-release') as f: + info = parse_file(f) + return (info['DISTRIB_ID'], info['DISTRIB_RELEASE']) + except FileNotFoundError: + print('Could not find linux distribution file!') + return ('Unknown', 'Unknown') diff --git a/scripts/setup.py b/scripts/setup.py --- a/scripts/setup.py +++ b/scripts/setup.py @@ -4,6 +4,7 @@ import sys, argparse import subprocess, os +from linux_distro import linux_distribution standard_ec2_packages = ['python-pip', 'wget'] standard_ec2_post_install = ['pip install awscli &&' @@ -69,40 +70,6 @@ class Fedora(object): test_packages = ['openssl-devel'] ec2_post_install = standard_ec2_post_install - def aarch64_download(self, version): - gcc_packages = ['gcc', - 'glibc', - 'glibc-devel', - 'libgcc', - 'libstdc++', - 'libstdc++-devel', - 'libstdc++-static'] - boost_packages = ['boost-devel', - 'boost-static', - 'boost-system'] - osv_root = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..') - script_path = '%s/scripts/download_rpm_package.sh' % osv_root - destination = '%s/downloaded_packages/aarch64' % osv_root - ## - # The setup.py is typically run as root to allow yum properly install packages - # This however would cause all files downloaded to downloaded_packages/aarch64 directory - # get created and owned by the root user which in most cases is not desirable - # To prevent that let us compare current process user id with the owner id of osv root - # directory and if different run all download command with the same user as the one owning - # the root directory - current_user_id = os.getuid() - osv_root_owner_id = os.stat(osv_root).st_uid - if current_user_id != osv_root_owner_id and current_user_id == 0: - command_prefix = "sudo -u '#%d'" % osv_root_owner_id # Most likely setup.py is run by root so let us use sudo - else: - command_prefix = '' - - install_commands = ['%s %s %s %s %s/gcc' % (command_prefix, script_path, package, version, destination) for package in gcc_packages] - install_commands += ['%s %s %s %s %s/boost' % (command_prefix, script_path, package, version, destination) for package in boost_packages] - install_commands = ['%s rm -rf %s/gcc/install' % (command_prefix, destination), - '%s rm -rf %s/boost/install' % (command_prefix, destination)] + install_commands - return ' && '.join(install_commands) - class Fedora_25(object): packages = [] ec2_packages = [] @@ -351,27 +318,6 @@ class LinuxMint_19(object): versions = [LinuxMint_18_03, LinuxMint_19] -def linux_distribution(): - def parse_file(f): - res = {} - for line in f: - k, v = line.rstrip().split('=') - res[k] = v.strip('"') - return res - - try: - with open('/etc/os-release') as f: - info = parse_file(f) - return (info['NAME'], info['VERSION_ID']) - except FileNotFoundError: - try: - with open('/etc/lsb-release') as f: - info = parse_file(f) - return (info['DISTRIB_ID'], info['DISTRIB_RELEASE']) - except FileNotFoundError: - print('Could not find linux distribution file!') - return ('Unknown', 'Unknown') - distros = [ Debian(), Fedora(), @@ -408,10 +354,6 @@ def parse_file(f): if cmdargs.test: pkg += distro.test_packages + dver.test_packages subprocess.check_call(distro.install + ' ' + str.join(' ', pkg), shell=True) - if 'aarch64_download' in dir(distro): - print('Downloading aarch64 packages to cross-compile ARM version ...') - subprocess.check_call(distro.aarch64_download(dver.version), shell=True) - print('Downloaded all aarch64 packages!') if cmdargs.ec2: if distro.ec2_post_install: subprocess.check_call(distro.ec2_post_install, shell=True) -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/000000000000d2e223059fdedbbd%40google.com.