Merge "Use embedded launcher for python binaries"

This commit is contained in:
Inseob Kim 2022-07-27 00:10:57 +00:00 committed by Gerrit Code Review
commit 52ffc6fe2a
3 changed files with 56 additions and 12 deletions

View file

@ -43,6 +43,11 @@ python_binary_host {
srcs: [
"treble_sepolicy_tests.py",
],
version: {
py3: {
embedded_launcher: true,
},
},
libs: [
"mini_cil_parser",
"pysepolwrap",
@ -55,6 +60,11 @@ python_binary_host {
srcs: [
"sepolicy_tests.py",
],
version: {
py3: {
embedded_launcher: true,
},
},
libs: ["pysepolwrap"],
data: [":libsepolwrap"],
}

View file

@ -15,9 +15,12 @@
from optparse import OptionParser
from optparse import Option, OptionValueError
import os
import pkgutil
import policy
import re
import shutil
import sys
import tempfile
SHARED_LIB_EXTENSION = '.dylib' if sys.platform == 'darwin' else '.so'
@ -146,7 +149,11 @@ Tests = [
"TestDmaHeapDevTypeViolations",
]
if __name__ == '__main__':
def do_main(libpath):
"""
Args:
libpath: string, path to libsepolwrap.so
"""
usage = "sepolicy_tests -f vendor_file_contexts -f "
usage +="plat_file_contexts -p policy [--test test] [--help]"
parser = OptionParser(option_class=MultipleOption, usage=usage)
@ -158,11 +165,6 @@ if __name__ == '__main__':
(options, args) = parser.parse_args()
libpath = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"libsepolwrap" + SHARED_LIB_EXTENSION)
if not os.path.exists(libpath):
sys.exit("Error: libsepolwrap does not exist. Is this binary corrupted?\n")
if not options.policy:
sys.exit("Must specify monolithic policy file\n" + parser.usage)
if not os.path.exists(options.policy):
@ -207,3 +209,17 @@ if __name__ == '__main__':
if len(results) > 0:
sys.exit(results)
if __name__ == '__main__':
temp_dir = tempfile.mkdtemp()
try:
libname = "libsepolwrap" + SHARED_LIB_EXTENSION
libpath = os.path.join(temp_dir, libname)
with open(libpath, "wb") as f:
blob = pkgutil.get_data("sepolicy_tests", libname)
if not blob:
sys.exit("Error: libsepolwrap does not exist. Is this binary corrupted?\n")
f.write(blob)
do_main(libpath)
finally:
shutil.rmtree(temp_dir)

View file

@ -16,10 +16,13 @@ from optparse import OptionParser
from optparse import Option, OptionValueError
import os
import mini_parser
import pkgutil
import policy
from policy import MatchPathPrefix
import re
import shutil
import sys
import tempfile
DEBUG=False
SHARED_LIB_EXTENSION = '.dylib' if sys.platform == 'darwin' else '.so'
@ -341,7 +344,13 @@ Tests = {"CoredomainViolations": TestCoredomainViolations,
"TrebleCompatMapping": TestTrebleCompatMapping,
"ViolatorAttributes": TestViolatorAttributes}
if __name__ == '__main__':
def do_main(libpath):
"""
Args:
libpath: string, path to libsepolwrap.so
"""
global pol, FakeTreble
usage = "treble_sepolicy_tests "
usage += "-f nonplat_file_contexts -f plat_file_contexts "
usage += "-p curr_policy -b base_policy -o old_policy "
@ -374,11 +383,6 @@ if __name__ == '__main__':
sys.exit("Error: File_contexts file " + f + " does not exist\n" +
parser.usage)
libpath = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"libsepolwrap" + SHARED_LIB_EXTENSION)
if not os.path.exists(libpath):
sys.exit("Error: libsepolwrap does not exist. Is this binary corrupted?\n")
# Mapping files and public platform policy are only necessary for the
# TrebleCompatMapping test.
if options.tests is None or options.tests == "TrebleCompatMapping":
@ -428,3 +432,17 @@ if __name__ == '__main__':
if len(results) > 0:
sys.exit(results)
if __name__ == '__main__':
temp_dir = tempfile.mkdtemp()
try:
libname = "libsepolwrap" + SHARED_LIB_EXTENSION
libpath = os.path.join(temp_dir, libname)
with open(libpath, "wb") as f:
blob = pkgutil.get_data("treble_sepolicy_tests", libname)
if not blob:
sys.exit("Error: libsepolwrap does not exist. Is this binary corrupted?\n")
f.write(blob)
do_main(libpath)
finally:
shutil.rmtree(temp_dir)