Skip to content

Commit

Permalink
Added --no-optimize-python option to remove -OO in sdl2 bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
inclement committed Jan 20, 2018
1 parent 84bbbc7 commit c626a19
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pythonforandroid/bootstraps/sdl2/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def select(fn):
zf.close()


def make_tar(tfn, source_dirs, ignore_path=[]):
def make_tar(tfn, source_dirs, ignore_path=[], optimize_python=True):
'''
Make a zip file `fn` from the contents of source_dis.
'''
Expand All @@ -179,7 +179,7 @@ def select(fn):
files = []
for sd in source_dirs:
sd = realpath(sd)
compile_dir(sd)
compile_dir(sd, optimize_python=optimize_python)
files += [(x, relpath(realpath(x), sd)) for x in listfiles(sd)
if select(x)]

Expand Down Expand Up @@ -208,14 +208,17 @@ def select(fn):
tf.close()


def compile_dir(dfn):
def compile_dir(dfn, optimize_python=True):
'''
Compile *.py in directory `dfn` to *.pyo
'''
# -OO = strip docstrings
if PYTHON is None:
return
subprocess.call([PYTHON, '-OO', '-m', 'compileall', '-f', dfn])
args = [PYTHON, '-m', 'compileall', '-f', dfn]
if optimize_python:
args.insert(1, '-OO')
subprocess.call(args)


def make_package(args):
Expand Down Expand Up @@ -245,7 +248,8 @@ def make_package(args):
tar_dirs.append('crystax_python')

if args.private:
make_tar('src/main/assets/private.mp3', tar_dirs, args.ignore_path)
make_tar('src/main/assets/private.mp3', tar_dirs, args.ignore_path,
optimize_python=args.optimize_python)
elif args.launcher:
# clean 'None's as a result of main.py path absence
tar_dirs = [tdir for tdir in tar_dirs if tdir]
Expand Down Expand Up @@ -512,6 +516,10 @@ def parse_args(args=None):
'the appropriate environment variables.'))
ap.add_argument('--add-activity', dest='add_activity', action='append',
help='Add this Java class as an Activity to the manifest.')
ap.add_argument('--no-optimize-python', dest='optimize_python',
action='store_false', default=True,
help=('Whether to compile to optimised .pyo files, using -OO '
'(strips docstrings and asserts)'))

if args is None:
args = sys.argv[1:]
Expand Down

0 comments on commit c626a19

Please sign in to comment.