From fd9eaa65ed1d42ae434efc307cc1ea82ab15dc78 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sat, 30 Sep 2023 13:54:58 -0400 Subject: [PATCH] build: Add script to build DataStreamSuite and cpp deps --- tools/py/build_data_stream.py | 107 ++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 tools/py/build_data_stream.py diff --git a/tools/py/build_data_stream.py b/tools/py/build_data_stream.py new file mode 100644 index 000000000..c7c9a38a4 --- /dev/null +++ b/tools/py/build_data_stream.py @@ -0,0 +1,107 @@ +import argparse +import os +import subprocess + +from core.file_utils import SparkPaths +from core.iter_utils import at_bounded + + +def _get_arg_parser(): + parser = argparse.ArgumentParser(description='Build DataStreamSuite.sln') + parser.add_argument( + '--configuration', + metavar='debug|release', + help='The build configuration', + ) + parser.add_argument( + '--clean', + action='store_true', + help='Perform a clean build (remove artifacts from previous build)', + ) + parser.add_argument( + '--verbosity', + metavar='{0-5}', + choices=range(0, 6), + type=int, + help='The output verbosity level', + ) + parser.add_argument( + '--dry-run', + action='store_true', + help='Preview the build commands without running them', + ) + parser.set_defaults( + configuration='debug', + clean=False, + verbosity=1, + ) + return parser + + +def _dotnet_verbosity(level): + names = ['quiet', 'minimal', 'normal', 'detailed', 'diagnostic'] + return at_bounded(names, level) + + +def _cmake_verbosity(level): + # Skip 'WARNING' and 'NOTICE' levels, since the default CMake verbosity, + # 'STATUS', doesn't produce that much output. This also better normalizes + # numeric representation of verbosity w/ dotnet, which only has 5 levels. + names = [ + 'ERROR', + # 'WARNING', + # 'NOTICE', + 'STATUS', + 'VERBOSE', + 'DEBUG', + 'TRACE', + ] + return at_bounded(names, level) + + +def _main(): + parser = _get_arg_parser() + args = parser.parse_args() + + def run(cmd): + print(cmd) + if args.dry_run: + return + subprocess.run(cmd).check_returncode() + + def dotnet_cmd(action='build'): + sln = SparkPaths.root().joinpath( + 'src', + 'DataStreamSuite', + 'DataStreamSuite.sln', + ) + return ' '.join([ + f'dotnet {action} {sln}', + f'--configuration {args.configuration.title()}', + f'--verbosity {_dotnet_verbosity(args.verbosity)}', + ]) + + os.chdir(SparkPaths.root()) + cmake_configure_cmd = ' '.join([ + f'cmake', + f'--preset data-stream-suite', + f'-DCMAKE_MESSAGE_LOG_LEVEL={_cmake_verbosity(args.verbosity)}', + ]) + cmake_build_cmd = ' '.join([ + f'cmake', + f'--build', + f'--preset data-stream-suite-{args.configuration.lower()}', + ]) + if args.clean: + run(f'{cmake_build_cmd} --target clean') + run(dotnet_cmd('clean')) + run(cmake_configure_cmd) + run(cmake_build_cmd) + run(dotnet_cmd('build')) + + +if __name__ == "__main__": + try: + _main() + except Exception as e: + print(f'build_data_stream.py failed: {e}')