Skip to content

Commit

Permalink
Fix incorrect use of closure in loop causing all ABIs to be x86_64
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsmith committed Aug 13, 2023
1 parent cfede99 commit 096049e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
22 changes: 15 additions & 7 deletions product/gradle-plugin/src/test/integration/test_gradle_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,7 @@ def get_output(self, module, variant, ext):
def check_assets(self, apk_dir, kwargs):
# Top-level assets
asset_dir = join(apk_dir, "assets/chaquopy")
python_version = kwargs["python_version"]
abis = kwargs["abis"]
abi_suffixes = ["common"] + abis
self.test.assertCountEqual(
Expand Down Expand Up @@ -1700,11 +1701,11 @@ def check_assets(self, apk_dir, kwargs):
["java", "_ctypes.so", "_datetime.so", "_random.so", "_sha512.so",
"_struct.so", "binascii.so", "math.so", "mmap.so", "zlib.so"],
os.listdir(abi_dir))
self.check_dt_needed(join(abi_dir, "_ctypes.so"), kwargs)
self.check_python_so(join(abi_dir, "_ctypes.so"), python_version, abi)

java_dir = join(abi_dir, "java")
self.test.assertCountEqual(["chaquopy.so"], os.listdir(java_dir))
self.check_dt_needed(join(java_dir, "chaquopy.so"), kwargs)
self.check_python_so(join(java_dir, "chaquopy.so"), python_version, abi)

# Python stdlib
with ZipFile(join(asset_dir, "stdlib-common.imy")) as stdlib_zip:
Expand All @@ -1715,7 +1716,6 @@ def check_assets(self, apk_dir, kwargs):
self.check_pyc(stdlib_zip, "argparse.pyc", kwargs)

# Data files packaged with stdlib: see target/package_target.sh.
python_version = kwargs["python_version"]
for grammar_stem in ["Grammar", "PatternGrammar"]:
self.test.assertIn("lib2to3/{}{}.final.0.pickle".format(
grammar_stem, PYTHON_VERSIONS[python_version]),
Expand Down Expand Up @@ -1750,7 +1750,7 @@ def check_assets(self, apk_dir, kwargs):
with TemporaryDirectory() as tmp_dir:
test_module = "_asyncio.so"
stdlib_native_zip.extract(test_module, tmp_dir)
self.check_dt_needed(join(tmp_dir, test_module), kwargs)
self.check_python_so(join(tmp_dir, test_module), python_version, abi)

# build.json
with open(join(asset_dir, "build.json")) as build_json_file:
Expand Down Expand Up @@ -1783,6 +1783,7 @@ def check_pyc(self, zip_file, pyc_filename, kwargs):
pyc_file.read(4))

def check_lib(self, lib_dir, kwargs):
python_version = kwargs["python_version"]
abis = kwargs["abis"]
self.test.assertCountEqual(abis, os.listdir(lib_dir))
for abi in abis:
Expand All @@ -1792,17 +1793,24 @@ def check_lib(self, lib_dir, kwargs):
f"libpython{kwargs['python_version']}.so", "libssl_chaquopy.so",
"libsqlite3_chaquopy.so"],
os.listdir(abi_dir))
self.check_dt_needed(join(abi_dir, "libchaquopy_java.so"), kwargs)
self.check_python_so(join(abi_dir, "libchaquopy_java.so"), python_version, abi)

def check_dt_needed(self, so_filename, kwargs):
def check_python_so(self, so_filename, python_version, abi):
libpythons = []
with open(so_filename, "rb") as so_file:
ef = ELFFile(so_file)
self.test.assertEqual(
ef.header.e_machine,
{"arm64-v8a": "EM_AARCH64",
"armeabi-v7a": "EM_ARM",
"x86": "EM_386",
"x86_64": "EM_X86_64"}[abi])

for tag in ef.get_section_by_name(".dynamic").iter_tags():
if tag.entry.d_tag == "DT_NEEDED" and \
tag.needed.startswith("libpython"):
libpythons.append(tag.needed)
self.test.assertEqual([f"libpython{kwargs['python_version']}.so"], libpythons)
self.test.assertEqual([f"libpython{python_version}.so"], libpythons)

def dump_run(self, msg):
self.test.fail(msg + "\n" +
Expand Down
8 changes: 4 additions & 4 deletions product/runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ def proxyTask = tasks.register("generateStaticProxy", Exec) {
}
sourceSets.test.java.srcDir(proxyTask)

for (abi in ["host"] + Common.ABIS) {
(["host"] + Common.ABIS).each { abi ->
def pyLibSuffix = ".so"
def cmakeBuildSubdir = "$buildDir/cmake/$abi"
def cmakeBuildType = findProperty("cmakeBuildType") ?: "Debug"
def cmake = tasks.register("cmake-$abi", Exec) {
group = "build"
dependsOn cythonPython, cythonJava
dependsOn("cythonPython", "cythonJava")
inputs.files "CMakeLists.txt"
// This is not a complete list of the outputs, but it's enough to detect when the
// directory has been deleted. We can't declare the whole directory as an output,
Expand Down Expand Up @@ -323,7 +323,7 @@ for (abi in ["host"] + Common.ABIS) {
}

def hostConfig = {
dependsOn setupPythonPath, compileTestJava
dependsOn("setupPythonPath", "compileTestJava")
environment "CLASSPATH", sourceSets.test.runtimeClasspath.asPath

// Can't use -Djava.library.path because we need something which also works
Expand Down Expand Up @@ -391,7 +391,7 @@ for (abi in ["host"] + Common.ABIS) {

// Generates a script to start a Python REPL with Java and Python paths set up.
tasks.register("consoleScript") {
dependsOn setupPythonPath
dependsOn("setupPythonPath")
doLast {
def writer = new PrintWriter("$projectDir/console.sh")
writer.println "#!/bin/bash -e"
Expand Down

0 comments on commit 096049e

Please sign in to comment.