build: Use CMakePresets in build_spark.py
This commit is contained in:
1 parent
cb47177b8e
commit
e3cd910acd
1 file changed
+31
-74
+31
-74
@@ -5,60 +5,11 @@ import subprocess
|
||||
import shutil
|
||||
|
||||
from core.argparse_utils import add_toggle_opt, get_arg
|
||||
from core.cmake_utils import CMakeConfigureCommand
|
||||
from core.file_utils import CWD, SparkPaths, create_dir, link_dir, unlink
|
||||
from core.file_utils import CWD, SparkPaths, create_dir
|
||||
from core.logging import exit_msg
|
||||
from core.str_utils import wrap_dquotes
|
||||
from typing import Optional, Tuple
|
||||
|
||||
|
||||
def _get_cmake_opts():
|
||||
cxx_flags = [
|
||||
'/MP',
|
||||
'/WX',
|
||||
'/wd4250',
|
||||
'/wd4251',
|
||||
'/wd4244',
|
||||
'/wd4267',
|
||||
'/wd4355',
|
||||
'/wd4275',
|
||||
'/wd4345',
|
||||
'/bigobj',
|
||||
'/EHsc',
|
||||
'/DCURL_STATICLIB',
|
||||
'/D_WINSOCK_DEPRECATED_NO_WARNINGS',
|
||||
'/D__TBB_NO_IMPLICIT_LINKAGE',
|
||||
'/DBOOST_ALL_NO_LIB',
|
||||
'/std:c++17',
|
||||
'/D_SCL_SECURE_NO_WARNINGS',
|
||||
'/D_CRT_SECURE_NO_WARNINGS',
|
||||
'/D_WIN32_WINNT=0x0600',
|
||||
]
|
||||
linker_flags = [
|
||||
'/DEBUG',
|
||||
'/OPT:REF',
|
||||
'/OPT:ICF',
|
||||
'/LTCG',
|
||||
]
|
||||
cxx_flags_debug = cxx_flags + [
|
||||
'/MTd',
|
||||
]
|
||||
cxx_flags_release = cxx_flags + [
|
||||
'/MT',
|
||||
]
|
||||
opts = {
|
||||
'CMAKE_CXX_FLAGS':
|
||||
wrap_dquotes(' '.join(cxx_flags)),
|
||||
'CMAKE_CXX_FLAGS_DEBUG':
|
||||
wrap_dquotes(' '.join(cxx_flags_debug)),
|
||||
'CMAKE_CXX_FLAGS_RELEASE':
|
||||
wrap_dquotes(' '.join(cxx_flags_release)),
|
||||
'CMAKE_SHARED_LINKER_FLAGS_RELEASE':
|
||||
wrap_dquotes(' '.join(linker_flags))
|
||||
}
|
||||
return opts
|
||||
|
||||
|
||||
class VisualStudioContext:
|
||||
def __init__(
|
||||
self,
|
||||
@@ -77,27 +28,6 @@ class VisualStudioContext:
|
||||
def prompt_cmd(self):
|
||||
return f'{self.prompt_path} -arch=x64 -host_arch=x64'
|
||||
|
||||
def configure_libspark(
|
||||
self,
|
||||
build_dir: PathLike,
|
||||
source_dir: Optional[PathLike] = None,
|
||||
) -> subprocess.CompletedProcess:
|
||||
source_dir = source_dir or SparkPaths.root()
|
||||
cmd = CMakeConfigureCommand(
|
||||
source_dir=source_dir,
|
||||
build_dir=build_dir,
|
||||
generator=f'"Visual Studio {self.version} {self.year}"')
|
||||
opts = _get_cmake_opts()
|
||||
cmd.add_opts(opts)
|
||||
|
||||
print(f'configure_cmd: {cmd}')
|
||||
with CWD(build_dir):
|
||||
res = subprocess.run(str(cmd))
|
||||
shutil.copy(
|
||||
SparkPaths.tools().joinpath('cpp.build.props'),
|
||||
'Directory.Build.Props')
|
||||
return res
|
||||
|
||||
def msbuild_flag(self, flag):
|
||||
return f'{self._msbuild_arg_prefix}{flag}'
|
||||
|
||||
@@ -330,13 +260,37 @@ def _get_arg_parser():
|
||||
return parser
|
||||
|
||||
|
||||
def configure_libspark(
|
||||
build_dir: PathLike = SparkPaths.default_build(),
|
||||
source_dir: Optional[PathLike] = None,
|
||||
preset: Optional[str] = 'spark',
|
||||
) -> subprocess.CompletedProcess:
|
||||
source_dir = source_dir or SparkPaths.root()
|
||||
cmd_parts = ['cmake']
|
||||
if preset is not None:
|
||||
cmd_parts.append(f'--preset {preset}')
|
||||
if source_dir is not None:
|
||||
cmd_parts.append(f'-S {source_dir}')
|
||||
if build_dir is not None:
|
||||
cmd_parts.append(f'-B {build_dir}')
|
||||
cmd = ' '.join(cmd_parts)
|
||||
print(f'configure_cmd: {cmd}')
|
||||
with CWD(build_dir):
|
||||
res = subprocess.run(cmd)
|
||||
shutil.copy(
|
||||
SparkPaths.tools().joinpath('cpp.build.props'),
|
||||
'Directory.Build.Props')
|
||||
return res
|
||||
|
||||
|
||||
def build(
|
||||
configuration: str | None = None,
|
||||
restore: bool = True,
|
||||
clean: bool = False,
|
||||
build_dir: Path | None = None,
|
||||
targets: list[str] | None = None,
|
||||
verbosity: str | None = None) -> list[subprocess.CompletedProcess]:
|
||||
verbosity: str | None = None,
|
||||
preset: str | None = 'spark') -> list[subprocess.CompletedProcess]:
|
||||
'''Builds the spark client'''
|
||||
|
||||
# check if explicit no-op
|
||||
@@ -359,8 +313,11 @@ def build(
|
||||
try:
|
||||
build_dir = build_dir.absolute()
|
||||
create_dir(build_dir, clean)
|
||||
cfg_res = vs_context.configure_libspark(
|
||||
build_dir=build_dir, source_dir=SparkPaths.root())
|
||||
cfg_res = configure_libspark(
|
||||
preset=preset,
|
||||
build_dir=build_dir,
|
||||
source_dir=SparkPaths.root(),
|
||||
)
|
||||
proc_results.append(cfg_res)
|
||||
except Exception as e:
|
||||
exit_msg(1, e)
|
||||
|
||||
Reference in new issue
Block a user