Skip to content

Handle all the macOS prerequisites (except NDK/SDK) via prerequisites.py #2594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ jobs:
run: |
source ci/osx_ci.sh
arm64_set_path_and_python_version 3.9.7
brew install autoconf automake libtool openssl pkg-config
make --file ci/makefiles/osx.mk
- name: Build multi-arch apk Python 3 (armeabi-v7a, arm64-v8a, x86_64, x86)
run: |
Expand Down Expand Up @@ -207,7 +206,6 @@ jobs:
run: |
source ci/osx_ci.sh
arm64_set_path_and_python_version 3.9.7
brew install autoconf automake libtool openssl pkg-config
make --file ci/makefiles/osx.mk
- name: Build multi-arch aab Python 3 (armeabi-v7a, arm64-v8a, x86_64, x86)
run: |
Expand Down Expand Up @@ -293,7 +291,6 @@ jobs:
run: |
source ci/osx_ci.sh
arm64_set_path_and_python_version 3.9.7
brew install autoconf automake libtool openssl pkg-config
make --file ci/makefiles/osx.mk
- name: Rebuild updated recipes
run: |
Expand Down
4 changes: 2 additions & 2 deletions ci/makefiles/osx.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# installs java 1.8, android's SDK/NDK, cython and p4a
# installs Android's SDK/NDK, cython

# The following variable/s can be override when running the file
ANDROID_HOME ?= $(HOME)/.android
Expand All @@ -10,4 +10,4 @@ upgrade_cython:

install_android_ndk_sdk:
mkdir -p $(ANDROID_HOME)
make -f ci/makefiles/android.mk JAVA_HOME=`/usr/libexec/java_home -v 13`
make -f ci/makefiles/android.mk
168 changes: 153 additions & 15 deletions pythonforandroid/prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
import platform
import os
import subprocess
import shutil
from pythonforandroid.logger import info, warning, error


class Prerequisite(object):
name = "Default"
mandatory = True
darwin_installer_is_supported = False
linux_installer_is_supported = False
mandatory = dict(linux=False, darwin=False)
installer_is_supported = dict(linux=False, darwin=False)

def is_valid(self):
if self.checker():
info(f"Prerequisite {self.name} is met")
return (True, "")
elif not self.mandatory:
elif not self.mandatory[sys.platform]:
warning(
f"Prerequisite {self.name} is not met, but is marked as non-mandatory"
)
Expand Down Expand Up @@ -73,10 +73,7 @@ def show_helper(self):
raise Exception("Unsupported platform")

def install_is_supported(self):
if sys.platform == "darwin":
return self.darwin_installer_is_supported
elif sys.platform == "linux":
return self.linux_installer_is_supported
return self.installer_is_supported[sys.platform]

def linux_checker(self):
raise Exception(f"Unsupported prerequisite check on linux for {self.name}")
Expand All @@ -96,11 +93,42 @@ def darwin_helper(self):
def linux_helper(self):
info(f"No helper available for prerequisite: {self.name} on linux")

def _darwin_get_brew_formula_location_prefix(self, formula, installed=False):
opts = ["--installed"] if installed else []
p = subprocess.Popen(
["brew", "--prefix", formula, *opts],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
_stdout_res, _stderr_res = p.communicate()

if p.returncode != 0:
error(_stderr_res.decode("utf-8").strip())
return None
else:
return _stdout_res.decode("utf-8").strip()


class HomebrewPrerequisite(Prerequisite):
name = "homebrew"
mandatory = dict(linux=False, darwin=True)
installer_is_supported = dict(linux=False, darwin=False)

def darwin_checker(self):
return shutil.which("brew") is not None

def darwin_helper(self):
info(
"Installer for homebrew is not yet supported on macOS,"
"the nice news is that the installation process is easy!"
"See: https://brew.sh for further instructions."
)


class JDKPrerequisite(Prerequisite):
name = "JDK"
mandatory = True
darwin_installer_is_supported = True
mandatory = dict(linux=False, darwin=True)
installer_is_supported = dict(linux=False, darwin=True)
min_supported_version = 11

def darwin_checker(self):
Expand Down Expand Up @@ -216,13 +244,123 @@ def darwin_installer(self):
os.environ["JAVA_HOME"] = jdk_path


def check_and_install_default_prerequisites():
DEFAULT_PREREQUISITES = dict(darwin=[JDKPrerequisite()], linux=[], all_platforms=[])
class OpenSSLPrerequisite(Prerequisite):
name = "openssl@1.1"
mandatory = dict(linux=False, darwin=True)
installer_is_supported = dict(linux=False, darwin=True)

def darwin_checker(self):
return (
self._darwin_get_brew_formula_location_prefix("openssl@1.1", installed=True)
is not None
)

def darwin_installer(self):
info("Installing OpenSSL ...")
subprocess.check_output(["brew", "install", "openssl@1.1"])


class AutoconfPrerequisite(Prerequisite):
name = "autoconf"
mandatory = dict(linux=False, darwin=True)
installer_is_supported = dict(linux=False, darwin=True)

def darwin_checker(self):
return (
self._darwin_get_brew_formula_location_prefix("autoconf", installed=True)
is not None
)

def darwin_installer(self):
info("Installing Autoconf ...")
subprocess.check_output(["brew", "install", "autoconf"])


class AutomakePrerequisite(Prerequisite):
name = "automake"
mandatory = dict(linux=False, darwin=True)
installer_is_supported = dict(linux=False, darwin=True)

required_prerequisites = (
DEFAULT_PREREQUISITES["all_platforms"] + DEFAULT_PREREQUISITES[sys.platform]
def darwin_checker(self):
return (
self._darwin_get_brew_formula_location_prefix("automake", installed=True)
is not None
)

def darwin_installer(self):
info("Installing Automake ...")
subprocess.check_output(["brew", "install", "automake"])


class LibtoolPrerequisite(Prerequisite):
name = "libtool"
mandatory = dict(linux=False, darwin=True)
installer_is_supported = dict(linux=False, darwin=True)

def darwin_checker(self):
return (
self._darwin_get_brew_formula_location_prefix("libtool", installed=True)
is not None
)

def darwin_installer(self):
info("Installing Libtool ...")
subprocess.check_output(["brew", "install", "libtool"])


class PkgConfigPrerequisite(Prerequisite):
name = "pkg-config"
mandatory = dict(linux=False, darwin=True)
installer_is_supported = dict(linux=False, darwin=True)

def darwin_checker(self):
return (
self._darwin_get_brew_formula_location_prefix("pkg-config", installed=True)
is not None
)

def darwin_installer(self):
info("Installing Pkg-Config ...")
subprocess.check_output(["brew", "install", "pkg-config"])


class CmakePrerequisite(Prerequisite):
name = "cmake"
mandatory = dict(linux=False, darwin=True)
installer_is_supported = dict(linux=False, darwin=True)

def darwin_checker(self):
return (
self._darwin_get_brew_formula_location_prefix("cmake", installed=True)
is not None
)

def darwin_installer(self):
info("Installing cmake ...")
subprocess.check_output(["brew", "install", "cmake"])


def get_required_prerequisites(platform="linux"):
DEFAULT_PREREQUISITES = dict(
darwin=[
HomebrewPrerequisite(),
AutoconfPrerequisite(),
AutomakePrerequisite(),
LibtoolPrerequisite(),
PkgConfigPrerequisite(),
CmakePrerequisite(),
OpenSSLPrerequisite(),
JDKPrerequisite(),
],
linux=[],
all_platforms=[],
)

return DEFAULT_PREREQUISITES["all_platforms"] + DEFAULT_PREREQUISITES[platform]


def check_and_install_default_prerequisites():

prerequisites_not_met = []

warning(
Expand All @@ -232,7 +370,7 @@ def check_and_install_default_prerequisites():

# Phase 1: Check if all prerequisites are met and add the ones
# which are not to `prerequisites_not_met`
for prerequisite in required_prerequisites:
for prerequisite in get_required_prerequisites(sys.platform):
if not prerequisite.is_valid():
prerequisites_not_met.append(prerequisite)

Expand Down
3 changes: 2 additions & 1 deletion pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def check_python_dependencies():
exit(1)


check_and_install_default_prerequisites()
if not environ.get('SKIP_PREREQUISITES_CHECK', '0') == '1':
check_and_install_default_prerequisites()
check_python_dependencies()


Expand Down
Loading