Skip to content
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

reproducible apks: strip file path prefix from .pyc files #3066

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion pythonforandroid/bootstraps/common/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,14 @@ def compile_py_file(python_file, optimize_python=True):
if PYTHON is None:
return

args = [PYTHON, '-m', 'compileall', '-b', '-f', python_file]
path_prefix = os.path.commonpath([python_file, os.getcwd()])
args = [
PYTHON, '-m', 'compileall',
'-b',
'-s', path_prefix, # for reproducible builds, do not leak paths into pyc
'-f',
python_file,
]
if optimize_python:
# -OO = strip docstrings
args.insert(1, '-OO')
Expand Down
9 changes: 8 additions & 1 deletion pythonforandroid/recipes/python3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,14 @@ def compile_python_files(self, dir):
longer used...uses .pyc (https://www.python.org/dev/peps/pep-0488)
'''
args = [self.ctx.hostpython]
args += ['-OO', '-m', 'compileall', '-b', '-f', dir]
args += [
'-OO',
'-m', 'compileall',
'-b',
'-s', dir, # for reproducible builds, do not leak paths into pyc
'-f',
dir,
]
subprocess.call(args)

def create_python_bundle(self, dirn, arch):
Expand Down
2 changes: 1 addition & 1 deletion tests/recipes/test_python3.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_compile_python_files(self, mock_subprocess):
hostpy = self.recipe.ctx.hostpython = '/fake/hostpython3'
self.recipe.compile_python_files(fake_compile_dir)
mock_subprocess.assert_called_once_with(
[hostpy, '-OO', '-m', 'compileall', '-b', '-f', fake_compile_dir],
[hostpy, '-OO', '-m', 'compileall', '-b', '-s', fake_compile_dir, '-f', fake_compile_dir],
)

@mock.patch("pythonforandroid.recipe.Recipe.check_recipe_choices")
Expand Down
Loading