Skip to content

Commit

Permalink
Merge branch 'apk-integrity-checking'
Browse files Browse the repository at this point in the history
  • Loading branch information
jensstein committed Nov 24, 2018
2 parents 5986123 + 80465b8 commit 6e9b36c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.iml
*.pyc
*.swp
.gradle
.idea
Expand Down
24 changes: 24 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,27 @@ clean {
}
}
}

gradle.taskGraph.whenReady { graph ->
def lastTask = graph.allTasks.last()
if(lastTask.name ==~ /(assemble|build).*/) {
lastTask.doLast {
def pythonExists = false
try {
Runtime r = Runtime.getRuntime()
Process p = r.exec("python3 --version")
p.waitFor()
pythonExists = p.exitValue() == 0 ? true : false
} catch(IOException e) {
logger.warn("no python - not running apk integrity checks")
}
if(pythonExists) {
exec {
environment "GRADLE_BUILD_DIR", "$buildDir"
executable = "python3"
args = ["-m", "unittest", "discover", "-s", "tests"]
}
}
}
}
}
35 changes: 35 additions & 0 deletions tests/test_apk_integrity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3

import os
import unittest
import zipfile

BUILD_DIR = os.getenv("GRADLE_BUILD_DIR", "build-dir-not-set")

flavor_asset_dict = {
"arm": ["assets/armeabi-v7a/oab-utils"],
"arm64": ["assets/arm64-v8a/oab-utils"],
"x86": ["assets/x86/oab-utils"],
"x86_64": ["assets/x86_64/oab-utils"],
"universal": ["assets/armeabi-v7a/oab-utils",
"assets/arm64-v8a/oab-utils", "assets/x86/oab-utils",
"assets/x86_64/oab-utils"]
}

class ApkTest(unittest.TestCase):
def test_assets(self):
self.assertEqual(os.path.exists(BUILD_DIR), True)
for root, dirs, files in os.walk(BUILD_DIR):
for filename in files:
if filename[-4:] == ".apk":
self.assert_apk_asset_contains(os.path.join(root,
filename))

def assert_apk_asset_contains(self, filename):
for flavor, assets in flavor_asset_dict.items():
if os.sep + flavor + os.sep in filename:
with zipfile.ZipFile(filename, "r") as z:
for asset in assets:
self.assertEqual(asset in z.namelist(), True,
"checking flavor {} failed for asset {}".format(
flavor, asset))

0 comments on commit 6e9b36c

Please sign in to comment.