Make windows build scripts read file for version number

This commit is contained in:
Vasily
2019-04-19 22:28:46 +02:00
parent e91c22d20a
commit cd1522b9e2
+53 -48
View File
@@ -8,10 +8,15 @@ import subprocess
import shutil import shutil
import distutils.dir_util import distutils.dir_util
def get_version_string():
dir_path = os.path.dirname(os.path.realpath(__file__))
with open(dir_path + "/../compile_version_string.txt", "r") as file:
contents = file.readline()
return contents
#Const globals #Const globals
#Version string must be bumped every release. VERSION_STRING = get_version_string()
#TODO: See developer documentation.
VERSION_STRING = "3-1-0-dev"
EXIT_CODE_SUCCESS = 0 EXIT_CODE_SUCCESS = 0
EXIT_CODE_FAILURE_BUILD_APP = 1 EXIT_CODE_FAILURE_BUILD_APP = 1
@@ -62,17 +67,17 @@ def say(message: str):
""" """
global current_activity global current_activity
print(current_activity + ": " + message) print(current_activity + ": " + message)
def say_error(message: str): def say_error(message: str):
""" """
Prints an error message to the console. Prints an error message to the console.
Not currently different from say, but put in incase somebody wanted to Not currently different from say, but put in incase somebody wanted to
do something fancy with outputting to stderr or something instead. do something fancy with outputting to stderr or something instead.
""" """
global current_activity global current_activity
print(current_activity + ": " + message) print(current_activity + ": " + message)
def is_env_var_set(env_var_name: str): def is_env_var_set(env_var_name: str):
""" """
Returns whether or not an environment variable is set. Returns whether or not an environment variable is set.
@@ -81,7 +86,7 @@ def is_env_var_set(env_var_name: str):
if var is None: if var is None:
return False return False
return True return True
def add_line_to_run_bat_file(line: str): def add_line_to_run_bat_file(line: str):
""" """
Adds a line ended by a newline to the batch file. Adds a line ended by a newline to the batch file.
@@ -92,7 +97,7 @@ def add_line_to_run_bat_file(line: str):
def add_error_handling_line_to_bat_file(): def add_error_handling_line_to_bat_file():
""" """
Adds an error handling line to the batch file. Adds an error handling line to the batch file.
This is because some applications don't cause the script to error out This is because some applications don't cause the script to error out
even if they exit with an error. even if they exit with an error.
""" """
@@ -117,23 +122,23 @@ def get_required_env_var_path(env_var_name: str, default_env_var_value: str):
exit_on_error(EXIT_CODE_FAILURE_BUILD_LOCATION) exit_on_error(EXIT_CODE_FAILURE_BUILD_LOCATION)
say(f"{env_var_name} exists.") say(f"{env_var_name} exists.")
return path return path
def create_batch_file(): def create_batch_file():
""" """
Creates a batch file in the dir. Must be called by another outside batch file. Creates a batch file in the dir. Must be called by another outside batch file.
""" """
file = open(get_project_dir() + "\\build_scripts\\win\\current_build.bat", "w+") file = open(get_project_dir() + "\\build_scripts\\win\\current_build.bat", "w+")
file.write(bat_file_contents) file.write(bat_file_contents)
file.close() file.close()
def exit_on_error(error_number): def exit_on_error(error_number):
"""Wrapper around sys.exit.""" """Wrapper around sys.exit."""
sys.exit(error_number) sys.exit(error_number)
def set_dirs(): def set_dirs():
""" """
Sets up the directories. Sets up the directories.
We know that the project dir will always be two dirs up from the dir the file is in. We know that the project dir will always be two dirs up from the dir the file is in.
""" """
global ORIGINAL_DIR global ORIGINAL_DIR
@@ -142,50 +147,50 @@ def set_dirs():
ORIGINAL_DIR = os.path.dirname(__file__) ORIGINAL_DIR = os.path.dirname(__file__)
PROJECT_DIR = os.path.abspath(os.path.join(ORIGINAL_DIR, r"..\..")) PROJECT_DIR = os.path.abspath(os.path.join(ORIGINAL_DIR, r"..\.."))
DEPLOY_DIR = DEPLOY_DIR = PROJECT_DIR + OUTPUT_DIR DEPLOY_DIR = DEPLOY_DIR = PROJECT_DIR + OUTPUT_DIR
print(ORIGINAL_DIR) print(ORIGINAL_DIR)
def get_project_dir(): def get_project_dir():
return PROJECT_DIR return PROJECT_DIR
def get_original_dir(): def get_original_dir():
return ORIGINAL_DIR return ORIGINAL_DIR
def get_deploy_dir(): def get_deploy_dir():
return DEPLOY_DIR return DEPLOY_DIR
def copy_file(src, dest): def copy_file(src, dest):
"""Copies a file and outputs status to console.""" """Copies a file and outputs status to console."""
say(f"Copying {src} to {dest}") say(f"Copying {src} to {dest}")
shutil.copy(src, dest) shutil.copy(src, dest)
say(f"{src} to {dest} copied.") say(f"{src} to {dest} copied.")
def copy_folder(src, dest): def copy_folder(src, dest):
"""Copies a folder and outputs status to console.""" """Copies a folder and outputs status to console."""
say(f"Copying {src} to {dest}") say(f"Copying {src} to {dest}")
distutils.dir_util.copy_tree(src, dest) distutils.dir_util.copy_tree(src, dest)
say(f"{src} to {dest} copied.") say(f"{src} to {dest} copied.")