Skip to content
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
12 changes: 12 additions & 0 deletions pythonforandroid/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,18 @@ def ensure_args(self, *args):
if arg not in self.extra_build_args:
self.extra_build_args.append(arg)

def get_recipe_env_command(self, command, env):
command_path = shutil.which(command, path=env["PATH"])
if command_path is None:
raise sh.CommandNotFound(command)
return sh.Command(command_path)

def get_meson_command(self, env):
return self.get_recipe_env_command("meson", env)

def get_ninja_command(self, env):
return self.get_recipe_env_command("ninja", env)

def build_arch(self, arch):
cross_file = join("/tmp", "android.meson.cross")
info("Writing cross file at: {}".format(cross_file))
Expand Down
14 changes: 11 additions & 3 deletions pythonforandroid/recipes/libcairo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def build_arch(self, arch):
_env=env
)

shprint(sh.meson, 'setup', 'builddir',
shprint(self.get_meson_command(env), 'setup', 'builddir',
'--cross-file', join("/tmp", "android.meson.cross"),
f'--prefix={install_dir}',
'-Dpng=enabled',
Expand All @@ -72,14 +72,22 @@ def build_arch(self, arch):
f'-Dfreetype_lib_dir={lib_dir}',
_env=env)

shprint(sh.ninja, '-C', 'builddir', '-j', str(cpu_count()), _env=env)
shprint(
self.get_ninja_command(env),
'-C', 'builddir', '-j', str(cpu_count()),
_env=env
)
# macOS fix: sometimes Ninja creates a dummy 'lib' file instead of a directory.
# So we remove and recreate the install directory using shell commands,
# since os.remove/os.makedirs behave inconsistently in this build env.
shprint(sh.rm, '-rf', install_dir)
shprint(sh.mkdir, install_dir)

shprint(sh.ninja, '-C', 'builddir', 'install', _env=env)
shprint(
self.get_ninja_command(env),
'-C', 'builddir', 'install',
_env=env
)


recipe = LibCairoRecipe()
14 changes: 11 additions & 3 deletions pythonforandroid/recipes/libthorvg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def build_arch(self, arch):
with current_directory(build_dir):

shprint(
sh.meson,
self.get_meson_command(env),
"setup",
"builddir",
"--cross-file",
Expand All @@ -72,10 +72,18 @@ def build_arch(self, arch):
_env=env,
)

shprint(sh.ninja, "-C", "builddir", "-j", str(cpu_count()), _env=env)
shprint(
self.get_ninja_command(env),
"-C", "builddir", "-j", str(cpu_count()),
_env=env,
)
shprint(sh.rm, "-rf", install_dir)
shprint(sh.mkdir, install_dir)
shprint(sh.ninja, "-C", "builddir", "install", _env=env)
shprint(
self.get_ninja_command(env),
"-C", "builddir", "install",
_env=env,
)

# copy libomp.so
arch_map = {
Expand Down
32 changes: 31 additions & 1 deletion tests/test_recipe.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import os
import pytest
import sh
import tempfile
import types
import unittest
import warnings
from unittest import mock

from pythonforandroid.build import Context
from pythonforandroid.recipe import Recipe, TargetPythonRecipe, import_recipe
from pythonforandroid.recipe import (
MesonRecipe, Recipe, TargetPythonRecipe, import_recipe
)
from pythonforandroid.archs import ArchAarch_64
from pythonforandroid.bootstrap import Bootstrap
from tests.test_bootstrap import BaseClassSetupBootstrap
Expand Down Expand Up @@ -198,6 +201,33 @@ class DummyTargetPythonRecipe(TargetPythonRecipe):
assert recipe.major_minor_version_string == '1.2'


class TestMesonRecipe(unittest.TestCase):

def test_get_recipe_env_command_uses_env_path(self):
"""
Meson commands can be installed in the hostpython environment without
being visible on the current Python process PATH.
"""
with tempfile.TemporaryDirectory() as temp_dir:
bin_dir = os.path.join(temp_dir, "bin")
os.mkdir(bin_dir)
meson_path = os.path.join(bin_dir, "meson")
with open(meson_path, "w") as file:
file.write("#!/bin/sh\necho fake meson\n")
os.chmod(meson_path, 0o755)

env = {"PATH": bin_dir}
recipe = MesonRecipe()

with mock.patch.dict(os.environ, {"PATH": os.devnull}):
with pytest.raises(sh.CommandNotFound):
sh.meson("--version", _env=env)

meson = recipe.get_meson_command(env)

assert meson("--version").strip() == "fake meson"


class TestLibraryRecipe(BaseClassSetupBootstrap, unittest.TestCase):
def setUp(self):
"""
Expand Down
Loading