A lot of server-side changes were just merged as part of the Brandon project (crypto). Many of those changes were in libspark (a lib on which both the client and server depend), and upgrades to its external dependencies. As a result, windows counterparts of several upgraded external libs needed to be similarly upgraded (or added for the first time). These libs include: boost, btree, catch, curl, fmt, nlohmann json, openssl, range, rxcpp, websocketpp This change also makes protobuf generation compatible with python3, and thus eliminates the build's dependency on python2
189 lines
5.1 KiB
Python
189 lines
5.1 KiB
Python
import argparse
|
|
import os
|
|
import subprocess
|
|
import shutil
|
|
|
|
|
|
def _workspace_root():
|
|
tools_dir = os.path.dirname(os.path.realpath(__file__))
|
|
return os.path.abspath(f'{tools_dir}\\{os.path.pardir}')
|
|
|
|
|
|
def _add_toggle_opt(parser, name, **kwargs):
|
|
parser.add_argument(f'--{name}', action=f'store_true', dest=name, **kwargs)
|
|
parser.add_argument(f'--no-{name}', action=f'store_false', dest=name)
|
|
return parser
|
|
|
|
|
|
class SparkPaths:
|
|
@staticmethod
|
|
def root():
|
|
return _workspace_root()
|
|
|
|
@staticmethod
|
|
def spark_proj():
|
|
return fr'{_workspace_root()}\src\client\spark\Spark.csproj'
|
|
|
|
@staticmethod
|
|
def libspark_proj(build_dir):
|
|
return fr'{build_dir}\ALL_BUILD.vcxproj'
|
|
|
|
@staticmethod
|
|
def tools():
|
|
return fr'{_workspace_root()}\tools'
|
|
|
|
@staticmethod
|
|
def default_build():
|
|
return fr'{_workspace_root()}\build'
|
|
|
|
@staticmethod
|
|
def externals():
|
|
return fr'{_workspace_root()}\externals'
|
|
|
|
@staticmethod
|
|
def msbuild():
|
|
# Wrap in quotes so spaces don't need to be escaped
|
|
return r'"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe"'
|
|
|
|
@staticmethod
|
|
def vs_prompt():
|
|
# Wrap in quotes so spaces don't need to be escaped
|
|
return r'"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat"'
|
|
|
|
|
|
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(
|
|
f'{SparkPaths.vs_prompt()} && cmake.exe -G "Visual Studio 16 2019" {SparkPaths.root()}'
|
|
)
|
|
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')
|
|
|
|
_add_toggle_opt(
|
|
parser, 'restore', help='Whether or not to run msbuild /t:restore')
|
|
|
|
_add_toggle_opt(
|
|
parser,
|
|
'clean',
|
|
help=
|
|
'Whether or not to delete and overwrite an existing build directory')
|
|
|
|
parser.set_defaults(restore=True)
|
|
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, clean):
|
|
if not os.path.exists(build_dir):
|
|
os.makedirs(build_dir)
|
|
elif clean:
|
|
_rmdir_or_unlink(build_dir)
|
|
os.makedirs(build_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
|
|
|
|
|
|
def _msbuild_prop_arg(key, value):
|
|
return f'/property:{key}={value}'
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = _get_arg_parser()
|
|
args = parser.parse_args()
|
|
|
|
args_dict = vars(args)
|
|
build_dir = _get_arg(args_dict, 'output_dir') or SparkPaths.default_build()
|
|
clean = args.clean
|
|
restore = args.restore
|
|
if build_dir is None:
|
|
print(args)
|
|
exit(1)
|
|
|
|
try:
|
|
build_dir = os.path.realpath(build_dir)
|
|
_create_and_link_build_dir(build_dir, clean)
|
|
_configure_libspark(build_dir)
|
|
except Exception as e:
|
|
_exit(e)
|
|
|
|
build_cmd_steps = [SparkPaths.vs_prompt()]
|
|
base_output_path_arg = _msbuild_prop_arg(
|
|
'BaseOutputPath', f'{build_dir}\\{args.configuration}')
|
|
|
|
# restore build (downloads nuget package deps)
|
|
if restore or clean:
|
|
restore_cmd_prefix = (
|
|
f'{SparkPaths.msbuild()} /m /p:debugtype=portable /p:platform=x64 '
|
|
f'/clp:verbosity=minimal /clp:summary '
|
|
f'/p:Configuration={args.configuration} /t:restore')
|
|
build_cmd_steps.append(
|
|
f'{restore_cmd_prefix} {SparkPaths.libspark_proj(build_dir)}')
|
|
build_cmd_steps.append(
|
|
f'{restore_cmd_prefix} {base_output_path_arg} {SparkPaths.spark_proj()}'
|
|
)
|
|
|
|
# main build
|
|
build_cmd_prefix = (
|
|
f'{SparkPaths.msbuild()} /m /p:debugtype=portable /p:platform=x64 '
|
|
f'/p:GenerateFullPaths=true /clp:verbosity=minimal '
|
|
f'/p:Configuration={args.configuration} /clp:summary')
|
|
build_cmd_steps.append(
|
|
f'{build_cmd_prefix} {SparkPaths.libspark_proj(build_dir)}')
|
|
build_cmd_steps.append(
|
|
f'{build_cmd_prefix} {base_output_path_arg} {SparkPaths.spark_proj()}')
|
|
|
|
build_cmd = ' && '.join(build_cmd_steps)
|
|
subprocess.run(build_cmd)
|