Commit 0b896e2b authored by carlosperate's avatar carlosperate

Update PyInstaller script for full Linux build automation.

parent 3d5dffe5
...@@ -89,6 +89,7 @@ cef_debug.log ...@@ -89,6 +89,7 @@ cef_debug.log
/arduexec /arduexec
/package/build /package/build
/ardublockly_run.bat /ardublockly_run.bat
/ardublockly_run.sh
# The documentation is built with the GitHub wiki data # The documentation is built with the GitHub wiki data
/Documentation /Documentation
......
...@@ -41,22 +41,37 @@ def remove_pyinstaller_temps(): ...@@ -41,22 +41,37 @@ def remove_pyinstaller_temps():
shutil.rmtree(build_dir) shutil.rmtree(build_dir)
def pyinstaller_build():
"""
Launches a subprocess running Python PyInstaller with the spec file from the
package folder. Captures the output streams and checks for errors.
:return: Boolean indicating the success state of the operation.
"""
process_args = ["python",
"package/pyinstaller/pyinstaller.py",
"package/pyinstaller.spec"]
print(script_tab + "Command: %s" % process_args)
pipe = subprocess.PIPE
pyinstaller_process = subprocess.Popen(
process_args) # stdout=pipe, stderr=pipe
std_op, std_err_op = pyinstaller_process.communicate()
if pyinstaller_process.returncode != 0:
print(script_tab + "ERROR: PyInstaller returned with exit code: %s" %
pyinstaller_process.returncode)
return False
return True
def remove_executable_folder(): def remove_executable_folder():
""" Removes the current ardublockly PyInstaller executable folder. """ """ Removes the current ardublockly PyInstaller executable folder. """
exec_dir = os.path.join(project_root_dir, "dist", exec_folder_name) exec_dir = os.path.join(project_root_dir, exec_folder_name)
if os.path.exists(exec_dir): if os.path.exists(exec_dir):
shutil.rmtree(exec_dir) shutil.rmtree(exec_dir)
def pyinstaller_build():
""" . """
process = ["python",
"package/pyinstaller/pyinstaller.py",
"package/pyinstaller.spec"]
print(script_tab + "Command: %s" % process)
subprocess.call(process)
def move_executable_folder(): def move_executable_folder():
""" Moves the PyInstaller executable folder from dist to project root. """ """ Moves the PyInstaller executable folder from dist to project root. """
original_exec_dir = os.path.join(project_root_dir, "dist", exec_folder_name) original_exec_dir = os.path.join(project_root_dir, "dist", exec_folder_name)
...@@ -68,13 +83,13 @@ def copy_cefpython_data_files(): ...@@ -68,13 +83,13 @@ def copy_cefpython_data_files():
""" Copies into the executable folder required cefpython files. """ """ Copies into the executable folder required cefpython files. """
cef_path = os.path.dirname(cefpython3.__file__) cef_path = os.path.dirname(cefpython3.__file__)
cef_exec_folder = os.path.join( cef_exec_folder = os.path.join(
project_root_dir, exec_folder_name, "cefpython3") project_root_dir, exec_folder_name, "cefpython3")
cef_exec_locales = os.path.join(cef_exec_folder, "locales") cef_exec_locales = os.path.join(cef_exec_folder, "locales")
data_files = [ data_files = [
"%s/libcef.so" % cef_path, "%s/libcef.so" % cef_path,
"%s/libffmpegsumo.so" % cef_path, "%s/libffmpegsumo.so" % cef_path,
"%s/subprocess" % cef_path] "%s/subprocess" % cef_path]
locales = glob(r"%s/locales/*.*" % cef_path) locales = glob(r"%s/locales/*.*" % cef_path)
...@@ -91,21 +106,57 @@ def copy_cefpython_data_files(): ...@@ -91,21 +106,57 @@ def copy_cefpython_data_files():
shutil.copy(f, cef_exec_locales) shutil.copy(f, cef_exec_locales)
def create_bash_file():
"""
Creates a bash file into the project root to be able to easily launch the
Ardublockly application.
"""
bash_text = '#!/bin/bash\n' \
'DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )\n' \
'echo "[Bash File] Running Ardublockly from: " $DIR\n' \
'./' + exec_folder_name + '/ardublockly $DIR\n'
try:
bash_file = open(
os.path.join(project_root_dir, "ardublockly_run.sh"), 'w')
bash_file.write(bash_text)
bash_file.close()
except Exception as e:
print(script_tab + "%s" % e)
print(script_tab + "ERROR: Bash file to launch the Ardublockly "
"application could not be created.")
def main(): def main():
print(script_tag + "Building Ardublockly for Linux.") print(script_tag + "Building Ardublockly for Linux.")
print(script_tag + "Project directory is: %s" % project_root_dir) print(script_tag + "Project directory is: %s" % project_root_dir)
print(script_tag + "Script working directory: %s" % os.getcwd()) print(script_tag + "Script working directory: %s" % os.getcwd())
print(script_tag + "Removing PyInstaller old temp directories.") print(script_tag + "Removing PyInstaller old temp directories.")
remove_pyinstaller_temps() remove_pyinstaller_temps()
print(script_tag + "Running PyInstaller process:") print(script_tag + "Running PyInstaller process:")
pyinstaller_build() success = pyinstaller_build()
if not success:
print(script_tag + "Removing PyInstaller recent temp directories.")
remove_pyinstaller_temps()
raise SystemExit(script_tag + "Exiting now as there was an error in "
"the PyInstaller execution.")
print(script_tag + "Removing old ardublockly executable directory.")
remove_executable_folder()
print(script_tag + "Moving executable folder to project root.") print(script_tag + "Moving executable folder to project root.")
move_executable_folder() move_executable_folder()
print(script_tag + "Coping cefpython data files into executable directory.") print(script_tag + "Coping cefpython data files into executable directory.")
copy_cefpython_data_files() copy_cefpython_data_files()
print(script_tag + "Removing PyInstaller recent temp directories.") print(script_tag + "Removing PyInstaller recent temp directories.")
remove_pyinstaller_temps() remove_pyinstaller_temps()
print(script_tag + "Creating bash file to easily execute Ardublockly.")
create_bash_file()
if __name__ == "__main__": if __name__ == "__main__":
main() main()
# -*- mode: python -*- # -*- mode: python -*-
# set up directories # This spec file counts on the PyInstaller script being executed from the
#this_file_dir = os.path.dirname(os.path.realpath(sys.argv[0])) # project root directory, otherwise the start_cef.py file path will have to
#this_file_parent = os.path.dirname(this_file_dir) # be updated.
#def get_cefpython_path():
# from cefpython3 import cefpython
# return "%s%s" % (os.path.dirname(cefpython.__file__), os.sep)
#cef_path = get_cefpython_path()
# Enable the ArdublocklyServer package access the sys path for pyinstaller to find
#sys.path.append(this_file_parent)
block_cipher = None block_cipher = None
...@@ -23,8 +15,10 @@ a = Analysis(['start_cef.py'], ...@@ -23,8 +15,10 @@ a = Analysis(['start_cef.py'],
runtime_hooks=None, runtime_hooks=None,
excludes=None, excludes=None,
cipher=block_cipher) cipher=block_cipher)
pyz = PYZ(a.pure, pyz = PYZ(a.pure,
cipher=block_cipher) cipher=block_cipher)
exe = EXE(pyz, exe = EXE(pyz,
a.scripts, a.scripts,
exclude_binaries=False, exclude_binaries=False,
...@@ -33,6 +27,7 @@ exe = EXE(pyz, ...@@ -33,6 +27,7 @@ exe = EXE(pyz,
strip=None, strip=None,
upx=True, upx=True,
console=False) console=False)
coll = COLLECT(exe, coll = COLLECT(exe,
a.binaries, a.binaries,
a.zipfiles, a.zipfiles,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment