diff --git a/pythonforandroid/bootstraps/sdl2/build/build.py b/pythonforandroid/bootstraps/sdl2/build/build.py index 73fbb94c24..9b398e420b 100755 --- a/pythonforandroid/bootstraps/sdl2/build/build.py +++ b/pythonforandroid/bootstraps/sdl2/build/build.py @@ -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. ''' @@ -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)] @@ -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): @@ -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] @@ -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:]