This patch adds an ability to download all necessary packages on Ubuntu
x86_64 host to support cross-compiling the aarch64 version of OSv
kernel.

In essence we add new shell script - download_ubuntu_aarch64_deb_package.sh -
that downloads a debian-style package (*deb) from either main or
universe Ubuntu ports repository.

We also enhance download_aarch64_packages.py (renamed from
download_fedora_aarch64_packages.py) to support detecting Ubuntu
host and delegating to download individual *deb packages.

Please note that unlike Fedora, the Ubuntu package g++-aarch64-linux-gnu
does come with C++ headers and all other gcc libraries' binaries
like libstdc++.so.6 and libgcc_s.so, so we only need to download the
aarch64 versions of the boost libraries.

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
---
 scripts/download_aarch64_packages.py          | 78 +++++++++++++++++++
 scripts/download_fedora_aarch64_packages.py   | 38 ---------
 ...=> download_fedora_aarch64_rpm_package.sh} |  0
 .../download_ubuntu_aarch64_deb_package.sh    | 31 ++++++++
 4 files changed, 109 insertions(+), 38 deletions(-)
 create mode 100755 scripts/download_aarch64_packages.py
 delete mode 100755 scripts/download_fedora_aarch64_packages.py
 rename scripts/{download_rpm_package.sh => 
download_fedora_aarch64_rpm_package.sh} (100%)
 create mode 100755 scripts/download_ubuntu_aarch64_deb_package.sh

diff --git a/scripts/download_aarch64_packages.py 
b/scripts/download_aarch64_packages.py
new file mode 100755
index 00000000..947dff47
--- /dev/null
+++ b/scripts/download_aarch64_packages.py
@@ -0,0 +1,78 @@
+#!/usr/bin/python3
+
+import subprocess, os, string, sys
+from distro import linux_distribution
+import re
+
+osv_root = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
+destination = '%s/build/downloaded_packages/aarch64' % osv_root
+
+def fedora_download_commands(fedora_version):
+    gcc_packages = ['gcc',
+                    'glibc',
+                    'glibc-devel',
+                    'libgcc',
+                    'libstdc++',
+                    'libstdc++-devel',
+                    'libstdc++-static']
+    boost_packages = ['boost-devel',
+                      'boost-static',
+                      'boost-system',
+                      'boost-filesystem',
+                      'boost-test',
+                      'boost-chrono',
+                      'boost-timer']
+    script_path = '%s/scripts/download_fedora_aarch64_rpm_package.sh' % 
osv_root
+
+    install_commands = ['%s %s %s %s/gcc' % (script_path, package, 
fedora_version, destination) for package in gcc_packages]
+    install_commands += ['%s %s %s %s/boost' % (script_path, package, 
fedora_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)
+
+def ubuntu_download_commands(boost_version):
+    boost_packages = ['libboost%s-dev' % boost_version,
+                      'libboost-system%s' % boost_version,
+                      'libboost-system%s-dev' % boost_version,
+                      'libboost-filesystem%s' % boost_version,
+                      'libboost-filesystem%s-dev' % boost_version,
+                      'libboost-test%s' % boost_version,
+                      'libboost-test%s-dev' % boost_version,
+                      'libboost-timer%s' % boost_version,
+                      'libboost-timer%s-dev' % boost_version,
+                      'libboost-chrono%s' % boost_version,
+                      'libboost-chrono%s-dev' % boost_version]
+
+    script_path = '%s/scripts/download_ubuntu_aarch64_deb_package.sh' % 
osv_root
+
+    install_commands = ['%s boost%s %s %s/boost' % (script_path, 
boost_version, package, destination) for package in boost_packages]
+    install_commands = ['rm -rf %s/boost/install' % destination] + 
install_commands
+    return ' && '.join(install_commands)
+
+def ubuntu_identify_boost_version(codename, index):
+    packages = subprocess.check_output(['wget', '-t', '1', '-qO-', 
'http://ports.ubuntu.com/indices/override.%s.%s' % (codename, 
'main')]).decode('utf-8')
+    libboost_system_package = re.search("libboost-system\d+\.\d+-dev", 
packages)
+    if libboost_system_package:
+       libboost_system_package_name = libboost_system_package.group()
+       return re.search('\d+\.\d+', libboost_system_package_name).group()
+    else:
+       return ''
+
+(name, version, codename) = linux_distribution()
+if name.lower() == 'fedora':
+    commands_to_download = fedora_download_commands(version)
+elif name.lower() == 'ubuntu':
+    boost_version = ubuntu_identify_boost_version(codename, 'main')
+    if boost_version == '':
+        boost_version = ubuntu_identify_boost_version(codename, 'universe')
+    if boost_version == '':
+        print("Cound not find boost version from neither main nor universe 
ports index!")
+        sys.exit(1)
+    commands_to_download = ubuntu_download_commands(boost_version)
+else:
+    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(commands_to_download, shell=True)
+print('Downloaded all aarch64 packages!')
diff --git a/scripts/download_fedora_aarch64_packages.py 
b/scripts/download_fedora_aarch64_packages.py
deleted file mode 100755
index 77f37420..00000000
--- a/scripts/download_fedora_aarch64_packages.py
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/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',
-                      'boost-filesystem',
-                      'boost-test',
-                      'boost-chrono',
-                      'boost-timer']
-    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/download_rpm_package.sh 
b/scripts/download_fedora_aarch64_rpm_package.sh
similarity index 100%
rename from scripts/download_rpm_package.sh
rename to scripts/download_fedora_aarch64_rpm_package.sh
diff --git a/scripts/download_ubuntu_aarch64_deb_package.sh 
b/scripts/download_ubuntu_aarch64_deb_package.sh
new file mode 100755
index 00000000..8f72393d
--- /dev/null
+++ b/scripts/download_ubuntu_aarch64_deb_package.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+package_directory="$1"
+package="$2"
+out_dir=$3
+
+arch=arm64
+
+letter=${package_directory:0:1}
+
+ports_main_repo_url="http://ports.ubuntu.com/pool/main/$letter/$package_directory/";
+ports_universe_repo_url="http://ports.ubuntu.com/pool/universe/$letter/$package_directory/";
+
+package_file_name=$(wget -t 1 -qO- $ports_main_repo_url | grep -Po 
"href=\"[^\"]*\"" | grep ${arch} | grep -Po "${package}[^\"]*" | tail -n 1)
+if [[ "${package_file_name}" == "" ]]; then
+   package_file_name=$(wget -t 1 -qO- $ports_universe_repo_url | grep -Po 
"href=\"[^\"]*\"" | grep ${arch} | grep -Po "${package}[^\"]*" | tail -n 1)
+   package_url="${ports_universe_repo_url}${package_file_name}"
+else
+   package_url="${ports_main_repo_url}${package_file_name}"
+fi
+echo $package_url
+
+if [[ "${package_file_name}" == "" ]]; then
+  echo "Could not find $package under $ports_main_repo_url nor 
$ports_universe_repo_url!"
+  exit 1
+fi
+
+mkdir -p ${out_dir}/upstream
+wget -c -O ${out_dir}/upstream/${package_file_name} $package_url
+mkdir -p ${out_dir}/install
+dpkg --extract ${out_dir}/upstream/${package_file_name} ${out_dir}/install
-- 
2.27.0

-- 
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/20210105150317.181630-1-jwkozaczuk%40gmail.com.

Reply via email to