169 lines
4.4 KiB
Python
169 lines
4.4 KiB
Python
from msilib.schema import Error
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import argparse
|
|
import shutil
|
|
import pygit2
|
|
|
|
|
|
def _root():
|
|
tools_dir = os.path.dirname(os.path.realpath(__file__))
|
|
return os.path.abspath(f'{tools_dir}\\{os.path.pardir}')
|
|
|
|
|
|
class SparkPaths:
|
|
@staticmethod
|
|
def root():
|
|
return _root()
|
|
|
|
@staticmethod
|
|
def tools():
|
|
return f'{_root()}\\tools'
|
|
|
|
@staticmethod
|
|
def default_build():
|
|
return f'{_root()}\\build'
|
|
|
|
@staticmethod
|
|
def externals():
|
|
return f'{_root()}\\externals'
|
|
|
|
|
|
class CWD:
|
|
def __init__(self, push_path, pop_path=os.getcwd()):
|
|
self.push_path = push_path
|
|
self.pop_path = pop_path
|
|
|
|
def __enter__(self):
|
|
if self.push_path is not None:
|
|
os.chdir(self.push_path)
|
|
|
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
if self.pop_path is not None:
|
|
os.chdir(self.pop_path)
|
|
|
|
|
|
def _configure_libspark(build_dir):
|
|
with CWD(build_dir):
|
|
subprocess.call('cmake.exe -G "Visual Studio 16 2019" ..')
|
|
shutil.copy(
|
|
f'{SparkPaths.tools()}\\cpp.build.props', 'Directory.Build.Props')
|
|
|
|
|
|
def _get_arg_parser():
|
|
parser = argparse.ArgumentParser(description='Build spark_client.sln')
|
|
|
|
parser.add_argument(
|
|
'--configuration',
|
|
metavar='debug|release',
|
|
type=str,
|
|
nargs='?',
|
|
help='The build configuration',
|
|
default='Debug')
|
|
|
|
parser.add_argument(
|
|
'-o',
|
|
'--output-dir',
|
|
metavar='path',
|
|
type=str,
|
|
nargs='?',
|
|
help='The directory in which to put build files')
|
|
|
|
parser.add_argument(
|
|
'--cache-branch',
|
|
help='Whether or not to build in a directory named ' +
|
|
"'build.<branch_name>' (which is then symlinked to the normal " +
|
|
"'build' directory)",
|
|
action='store_true',
|
|
required=False)
|
|
|
|
parser.add_argument(
|
|
'--clean',
|
|
help=
|
|
'Whether or not to delete and overwrite an existing build directory directory',
|
|
action='store_true',
|
|
required=False)
|
|
return parser
|
|
|
|
|
|
def _rmdir_or_unlink(dir):
|
|
if not os.path.exists(dir):
|
|
return
|
|
if os.path.islink(dir):
|
|
os.unlink(dir)
|
|
else:
|
|
shutil.rmtree(dir)
|
|
|
|
|
|
def _create_and_link_build_dir(build_dir, dbuild_dir, clean):
|
|
if not os.path.exists(build_dir):
|
|
os.makedirs(build_dir)
|
|
elif clean:
|
|
shutil.rmtree(build_dir)
|
|
os.makedirs(build_dir)
|
|
|
|
if build_dir != dbuild_dir:
|
|
if clean:
|
|
_rmdir_or_unlink(dbuild_dir)
|
|
elif os.path.islink(dbuild_dir):
|
|
os.unlink(dbuild_dir)
|
|
os.symlink(build_dir, dbuild_dir)
|
|
|
|
|
|
def _exit(code=0, msg=None):
|
|
if msg is not None:
|
|
print(msg)
|
|
exit(code)
|
|
|
|
|
|
def _get_arg(args, name, value_or=None):
|
|
if name in args:
|
|
return args[name]
|
|
return value_or
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = _get_arg_parser()
|
|
args = parser.parse_args()
|
|
|
|
os.environ[
|
|
'spark_build_python_path'] = fr'{SparkPaths.tools()}\..\externals\windows\bin\python'
|
|
|
|
repo = pygit2.Repository(SparkPaths.root())
|
|
args_dict = vars(args)
|
|
print(os.getcwd())
|
|
build_dir = _get_arg(args_dict, 'output_dir')
|
|
if build_dir is None:
|
|
if _get_arg(args_dict, 'cache_branch'):
|
|
branch_name = os.path.basename(repo.head.name)
|
|
build_dir = f'build.{branch_name}'
|
|
else:
|
|
build_dir = SparkPaths.default_build()
|
|
print(os.getcwd())
|
|
force = args.clean
|
|
if build_dir is None:
|
|
print(args)
|
|
exit(1)
|
|
|
|
try:
|
|
build_dir = os.path.realpath(build_dir)
|
|
dbuild_dir = SparkPaths.default_build()
|
|
_create_and_link_build_dir(build_dir, dbuild_dir, force)
|
|
_configure_libspark(build_dir)
|
|
except Exception as e:
|
|
_exit(e)
|
|
|
|
print('activating venv27')
|
|
activate_venv_cmd = fr'{SparkPaths.root()}\.venv27\Scripts\activate.bat'
|
|
msbuild_restore_cmd = (
|
|
f'msbuild /m /p:debugtype=portable /p:platform=x64 '
|
|
f'/clp:verbosity=minimal /clp:summary '
|
|
f'/p:Configuration={args.configuration} /t:restore spark_client.sln')
|
|
msbuild_cmd = (
|
|
f'msbuild /m /p:debugtype=portable /p:platform=x64 '
|
|
f'/p:GenerateFullPaths=true /clp:verbosity=minimal '
|
|
f'/p:Configuration={args.configuration} /clp:summary spark_client.sln')
|
|
subprocess.run(
|
|
f'''{activate_venv_cmd} && {msbuild_restore_cmd} && {msbuild_cmd}''')
|