From a0029ed4c65bb2e8d34e079fd108d2fe4e3469c8 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Fri, 28 Jun 2024 11:21:45 -0400 Subject: [PATCH] build: Use separate cmd to build DataStreamSuite/QueryAnalyzer.sln The DataStreamSuite.sln builds the new webapp now, which will (eventually) replace DSQA. We'll keep it around for now, but with a clean separation from the main build. --- .vscode/launch.json | 4 +- .vscode/tasks.json | 57 ++++++++- tools/build_data_stream_query_analyzer.cmd | 29 +++++ tools/py/build_data_stream.py | 12 +- tools/py/build_data_stream_query_analyzer.py | 118 +++++++++++++++++++ 5 files changed, 204 insertions(+), 16 deletions(-) create mode 100644 tools/build_data_stream_query_analyzer.cmd create mode 100644 tools/py/build_data_stream_query_analyzer.py diff --git a/.vscode/launch.json b/.vscode/launch.json index bbfd70fa3..447d0b320 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -77,7 +77,7 @@ "name": "DataStreamQueryAnalyzer", "type": "coreclr", "request": "launch", - //"preLaunchTask": "Build DataStreamQueryAnalyzer (Debug)", + "preLaunchTask": "Build DataStreamQueryAnalyzer (Debug)", "program": "", "windows": { "program": "DataStreamQueryAnalyzer.exe", @@ -194,4 +194,4 @@ "default": "http://localhost:8000/config", }, ] -} \ No newline at end of file +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 100dfead1..d01a759fd 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -121,6 +121,57 @@ "color": "terminal.ansiCyan" }, }, + { + "label": "Build DataStreamQueryAnalyzer", + "group": "build", + "type": "process", + "command": "", + "windows": { + "command": "tools/build_data_stream_query_analyzer.cmd", + }, + "args": [ + "--configuration", + "${input:buildConfiguration}", + ], + "icon": { + "id": "terminal", + "color": "terminal.ansiCyan" + }, + }, + { + "label": "Build DataStreamQueryAnalyzer (Debug)", + "group": "build", + "type": "process", + "command": "", + "windows": { + "command": "tools/build_data_stream_query_analyzer.cmd", + }, + "args": [ + "--configuration", + "Debug", + ], + "icon": { + "id": "terminal", + "color": "terminal.ansiCyan" + }, + }, + { + "label": "Build DataStreamQueryAnalyzer (Release)", + "group": "build", + "type": "process", + "command": "", + "windows": { + "command": "tools/build_data_stream_query_analyzer.cmd", + }, + "args": [ + "--configuration", + "Release", + ], + "icon": { + "id": "terminal", + "color": "terminal.ansiCyan" + }, + }, { "label": "Build DataStream WebApp", "group": "build", @@ -409,7 +460,7 @@ }, { "label": "Run DataStreamQueryAnalyzer", - "dependsOn": "Build DataStream", + "dependsOn": "Build DataStreamQueryAnalyzer", "type": "process", "command": "", "windows": { @@ -429,7 +480,7 @@ }, { "label": "Run DataStreamQueryAnalyzer (Debug)", - "dependsOn": "Build DataStream (Debug)", + "dependsOn": "Build DataStreamQueryAnalyzer (Debug)", "type": "process", "command": "", "windows": { @@ -449,7 +500,7 @@ }, { "label": "Run DataStreamQueryAnalyzer (Release)", - "dependsOn": "Build DataStream (Release)", + "dependsOn": "Build DataStreamQueryAnalyzer (Release)", "type": "process", "command": "", "windows": { diff --git a/tools/build_data_stream_query_analyzer.cmd b/tools/build_data_stream_query_analyzer.cmd new file mode 100644 index 000000000..9c8829216 --- /dev/null +++ b/tools/build_data_stream_query_analyzer.cmd @@ -0,0 +1,29 @@ +@echo off +setlocal + +set VS_DEV_CMD_BAT="C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\VsDevCmd.bat" +if exist %VS_DEV_CMD_BAT% ( + call %VS_DEV_CMD_BAT% +) + +set NODEVARS_BAT="C:\\Program Files\\nodejs\\nodevars.bat" +if exist %NODEVARS_BAT% ( + call %NODEVARS_BAT% +) + +set TOOLS_DIR=%~dp0 +set REPO_DIR=%~dp0.. +set BUILD_PY=%TOOLS_DIR%\py\build_data_stream_query_analyzer.py + +if DEFINED VIRTUAL_ENV ( + @REM We're already in a venv, just run build_data_stream_query_analyzer.py (whether or not it is + @REM the 'right' venv is the caller's responsibility) + echo "Building in the current venv '%VIRTUAL_ENV'" + @call python %BUILD_PY% %* +) else ( + @REM Ensure the (default) venv is created, then run build_data_stream_query_analyzer.py in it + @call %TOOLS_DIR%\ensure_venv.cmd + @call %TOOLS_DIR%\venv_exec.cmd python %BUILD_PY% %* +) + +EXIT /B %ERRORLEVEL% diff --git a/tools/py/build_data_stream.py b/tools/py/build_data_stream.py index 94538e3e4..377691855 100644 --- a/tools/py/build_data_stream.py +++ b/tools/py/build_data_stream.py @@ -80,16 +80,6 @@ def _cmake_build_preset(configuration): raise ValueError(f'Unsupported platform {sys.platform}') -def _dotnet_sln_name(): - match sys.platform: - case 'win32': - return 'DataStreamQueryAnalyzer' - case 'linux': - return 'DataStreamSuite' - case _: - raise ValueError(f'Unsupported platform {sys.platform}') - - def _main(): parser = _get_arg_parser() args = parser.parse_args() @@ -104,7 +94,7 @@ def _main(): sln = SparkPaths.root().joinpath( 'src', 'DataStreamSuite', - f'{_dotnet_sln_name()}.sln', + 'DataStreamSuite.sln', ) return ' '.join([ f'dotnet {action} {sln}', diff --git a/tools/py/build_data_stream_query_analyzer.py b/tools/py/build_data_stream_query_analyzer.py new file mode 100644 index 000000000..7c207326b --- /dev/null +++ b/tools/py/build_data_stream_query_analyzer.py @@ -0,0 +1,118 @@ +import argparse +import os +import subprocess +import sys + +from core.file_utils import SparkPaths +from core.iter_utils import at_bounded + + +def _get_arg_parser(): + parser = argparse.ArgumentParser(description="Build DataStreamQueryAnalyzer.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 _cmake_preset(): + match sys.platform: + case "win32": + return "data-stream-suite-windows" + case "linux": + return "data-stream-suite-linux" + case _: + raise ValueError(f"Unsupported platform {sys.platform}") + + +def _cmake_build_preset(configuration): + match sys.platform: + case "win32": + return f"data-stream-suite-windows-{configuration}" + case "linux": + return f"data-stream-suite-linux-{configuration}" + case _: + raise ValueError(f"Unsupported platform {sys.platform}") + + +def _main(): + parser = _get_arg_parser() + args = parser.parse_args() + + def run(cmd): + print(cmd) + if args.dry_run: + return + subprocess.run(cmd, shell=True).check_returncode() + + def dotnet_cmd(action): + sln = SparkPaths.root().joinpath( + "src", "DataStreamSuite", "DataStreamQueryAnalyzer.sln" + ) + cfg = args.configuration.title() + verbosity = _dotnet_verbosity(args.verbosity) + return f"dotnet {action} {sln} --configuration {cfg} --verbosity {verbosity}" + + os.chdir(SparkPaths.root()) + cmake_configure_cmd = f"cmake --preset {_cmake_preset()} -DCMAKE_MESSAGE_LOG_LEVEL={_cmake_verbosity(args.verbosity)}" + cmake_build_cmd = ( + f"cmake --build --preset {_cmake_build_preset(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_query_analyzer.py failed: {e}")