diff --git a/BdeBuildSystem/BdeTestDriverUtils.cmake b/BdeBuildSystem/BdeTestDriverUtils.cmake index fc124357..a21450cb 100644 --- a/BdeBuildSystem/BdeTestDriverUtils.cmake +++ b/BdeBuildSystem/BdeTestDriverUtils.cmake @@ -129,6 +129,17 @@ function(bbs_add_component_tests target) get_filename_component(test_target_name ${test_src} NAME_WLE) get_filename_component(test_target_name ${test_target_name} NAME_WLE) add_executable(${test_target_name}.t EXCLUDE_FROM_ALL ${test_src}) + set_target_properties( + ${test_target_name}.t + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests") + add_custom_command(TARGET ${test_target_name}.t + POST_BUILD + COMMAND + ${CMAKE_COMMAND} -E create_hardlink + "$" + "$/${test_target_name}${CMAKE_EXECUTABLE_SUFFIX}" + ) # Explicitely adding flags here because we do not want those flags to be # PUBLIC for standalone libraries. @@ -268,6 +279,10 @@ function(bbs_add_component_tests target) add_custom_target(${split_target_name}.t SOURCES ${td_output_dir}/${split_test}) else() add_executable(${split_target_name}.t EXCLUDE_FROM_ALL ${td_output_dir}/${split_test}) + set_target_properties( + ${split_target_name}.t + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests") bbs_add_target_bde_flags(${split_target_name}.t PRIVATE) bbs_add_target_thread_flags(${split_target_name}.t PRIVATE) diff --git a/CMakeLists.txt b/CMakeLists.txt index 219ae090..7e44d3fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.22) project(bde-tools NONE) -# bbs-tools +# bbs-tools install(DIRECTORY BdeBuildSystem DESTINATION share/cmake COMPONENT bbs-cmake-module) @@ -15,6 +15,7 @@ install(PROGRAMS BdeBuildSystem/scripts/sim_cpp11_features.pl # bbs shell wrappers install(PROGRAMS bin/bbs_build bin/bbs_build_env + bin/bbs_make_vscode bin/get_dependers DESTINATION libexec/bde-tools/bin COMPONENT bde-tools) @@ -27,11 +28,13 @@ install(FILES bin/bbs_build.py # bde-tools # keep pylibinit when removing old bde-tools install rules(!) -install(PROGRAMS bin/bde_build_env.py +install(PROGRAMS bin/bbs_make_vscode.py + bin/bde_build_env.py bin/bde_runtest.py bin/bde_input_limiter.pl bin/cmake_build.py bin/get_dependers.py + bin/bde_get_changed_components.sh DESTINATION libexec/bde-tools/bin COMPONENT bde-tools) @@ -45,6 +48,11 @@ install(DIRECTORY bin/pylibinit COMPONENT bde-tools PATTERN "__pycache__" EXCLUDE) +# Install vscode templates +install(DIRECTORY share/templates/vscode + DESTINATION libexec/bde-tools/templates + COMPONENT bde-tools) + # Install rules for bde-gdb-printers install(FILES contrib/gdb-printers/bde_printer.py DESTINATION libexec/bde-gdb-printers diff --git a/bin/bbs_build.py b/bin/bbs_build.py index 37f53c07..416725d6 100644 --- a/bin/bbs_build.py +++ b/bin/bbs_build.py @@ -69,18 +69,20 @@ def get_msvc_env(version, bitness): result = {} bat_file = find_vcvars(version) - host_arch = platform.machine().lower() # typically amd64 or arm64 + host_arch = platform.machine().lower() # typically amd64 or arm64 if "arm" in host_arch: target_arch = "arm" if bitness == 32 else "arm64" else: target_arch = "x86" if bitness == 32 else "amd64" - arch_arg = host_arch if host_arch == target_arch else f"{host_arch}_{target_arch}" + arch_arg = ( + host_arch if host_arch == target_arch else f"{host_arch}_{target_arch}" + ) process = subprocess.Popen( [bat_file, arch_arg, "&&", "set"], stdout=subprocess.PIPE, shell=True ) - (out, err) = process.communicate() + (out, _) = process.communicate() if sys.version_info > (3, 0): out = out.decode("ascii", errors="ignore") @@ -196,6 +198,7 @@ def __init__(self, args): self.cpp11_verify_no_change = args.cpp11_verify_no_change self.recover_sanitizer = args.recover_sanitizer self.dump_cmake_flags = args.dump_cmake_flags + self.known_env = args.known_env self.generator = args.generator self.config = args.config @@ -255,7 +258,11 @@ def generator(options): @staticmethod def generator_env(options): host_platform = platform.system() - if options.generator != "msvc" and "Windows" == host_platform: + if ( + options.generator != "msvc" + and "Windows" == host_platform + and not options.known_env + ): return get_msvc_env( Platform.msvcVersionMap[options.compiler].version, 64 if options.ufid and "64" in options.ufid else 32, @@ -298,26 +305,26 @@ def ctest_jobs_arg(options): raise RuntimeError() + def wrapper(): description = """ bbs_build is a CMake/CTest wrapper that provides a simpler interface for the CMake/CTest invocation. """ - parser = argparse.ArgumentParser(prog="bbs_build", - description=description) + parser = argparse.ArgumentParser(prog="bbs_build", description=description) parser.add_argument( "cmd", nargs="+", choices=["configure", "build", "install"] ) parser.add_argument( "--build_dir", - help = ''' + help=""" Path to the build directory. If not specified, the build system generates the name using the current platform, compiler, and ufid. The generated build directory looks like this: "./_build/unix-linux-x86_64-2.6.32-gcc-11.0.0-opt_64_cpp20" - ''' + """, ) parser.add_argument( @@ -333,18 +340,18 @@ def wrapper(): "--verbose", action="count", default=0, - help ="Produce verbose output (including compiler " "command lines).", + help="Produce verbose output (including compiler " "command lines).", ) parser.add_argument( "--prefix", - default = "/opt/bb", - help = ''' + default="/opt/bb", + help=""" The path prefix in which to look for dependencies for this build. If "--refroot" is specified, this prefix is relative to the refroot (default="/opt/bb"). - ''' + """, ) group = parser.add_argument_group( @@ -353,10 +360,10 @@ def wrapper(): group.add_argument( "-u", "--ufid", - help = ''' + help=""" Unified Flag IDentifier (e.g. "opt_dbg_64_cpp20"). See bde-tools documentation. - ''' + """, ) group.add_argument("--toolchain", help="Path to the CMake toolchain file.") @@ -374,7 +381,7 @@ def wrapper(): group.add_argument( "--compiler", help="Specify version of MSVC (Windows only). " - 'Currently supported versions are: ' + "Currently supported versions are: " '"msvc-2022", "msvc-2019", and "msvc-2017". Latest ' "installed version will be default.", ) @@ -415,6 +422,13 @@ def wrapper(): help="Dump CMake flags and exit.", ) + group.add_argument( + "--known-env", + action="store_true", + default=False, + help="(MSVC Only) Do not set the environment via vcvarsall.bat.", + ) + genChoices = Platform.generator_choices() if len(genChoices) > 1: group.add_argument( @@ -434,7 +448,7 @@ def wrapper(): target_group.add_argument( "--targets", type=lambda x: x.split(","), - help='''Comma-separated list of build system targets. + help="""Comma-separated list of build system targets. The build system targets include the targets for libraries and test drivers for package groups ("bsl"/"bsl.t"), packages ("bslma"/"bslma.t"), @@ -443,7 +457,7 @@ def wrapper(): cycle checks ("check_cycles"/"bsl.check_cycles") and cleanup ("clean"). Supplying a target of "help" will list all of the available targets. - ''', + """, ) target_group.add_argument( @@ -713,8 +727,19 @@ def configure(options): if options.refroot: flags.append("-DDISTRIBUTION_REFROOT:PATH=" + options.refroot) + generator_env = Platform.generator_env(options) + if options.dump_cmake_flags: - print(*flags, sep="\n") + cmakeFlags = {} + for arg in flags: + key, value = arg.split("=") + + # Remove -D and the type + key = key.replace("-D", "").split(":")[0] + + cmakeFlags[key] = value + + print(json.dumps({"flags": cmakeFlags, "env": dict(generator_env)})) return configure_cmd = ( @@ -734,7 +759,7 @@ def configure(options): subprocess.check_call( configure_cmd, cwd=options.build_dir, - env=Platform.generator_env(options), + env=generator_env, ) @@ -817,8 +842,12 @@ def build(options): # the dependers of the specified components. If '--test' was # specified, build the test driver dependers. Otherwise, build the # packages that the dependers belong to. - target_list = get_dependers(options.dependers_of, options.tests, - options.no_missing_target_warning) + target_list = get_dependers( + options.dependers_of, + options.tests, + options.no_missing_target_warning, + options.build_dir, + ) if target_list: print("Dependers found: " + " ".join(target_list)) diff --git a/bin/bbs_make_vscode.py b/bin/bbs_make_vscode.py index 951e004b..638799bf 100644 --- a/bin/bbs_make_vscode.py +++ b/bin/bbs_make_vscode.py @@ -5,10 +5,7 @@ import pathlib import json import shutil - - -def removeBuildType(ufid: str): - return "_".join([x for x in ufid.split("_") if not x in ["opt", "dbg"]]) +from collections import namedtuple def backup(path: pathlib.Path): @@ -24,6 +21,16 @@ def backup(path: pathlib.Path): bdeToolsDir = binDir.parent isGitBash = shutil.which("cygpath") is not None +isWSL = not isGitBash and "WSL" in os.uname().release + + +def cygpath(opt, file): + return subprocess.run( + ["cygpath", opt, file], + stdout=subprocess.PIPE, + text=True, + ).stdout.strip() + if not isGitBash: bbsBuildExecutable = [binDir / "bbs_build"] @@ -32,47 +39,38 @@ def backup(path: pathlib.Path): # 'bbs_build_env.py' using its Windows path (as opposed to its cygwin path) bbsBuildExecutable = [ sys.executable, - subprocess.run( - ["cygpath", "-w", binDir / "bbs_build.py"], - stdout=subprocess.PIPE, - text=True, - ).stdout.strip(), + cygpath("-w", binDir / "bbs_build.py"), ] + bashExecutable = cygpath("-w", shutil.which("bash")) + +buildArea = os.getenv("BDE_BUILD_AREA", "${workspaceFolder}") +projectCache = os.getenv("BDE_PROJECT_CACHE", f"{buildArea}/.vscode") + uplid = os.getenv("BDE_CMAKE_UPLID") ufid = os.getenv("BDE_CMAKE_UFID") +buildDir = os.getenv("BDE_CMAKE_BUILD_DIR") -if not uplid or not ufid: +if not uplid or not ufid or not buildDir: print("Please set the BBS build environment using 'bbs_build_env'.") sys.exit(1) -buildDir = f"_build/{uplid}-{removeBuildType(ufid)}-vscode-${{buildType}}" - if not os.path.exists("CMakeLists.txt"): print("Error: CMakeLists.txt not found.") sys.exit(1) -# Parse CMake flags -cmakeFlagsList = subprocess.run( - [ - *bbsBuildExecutable, - "configure", - "--dump-cmake-flags", - ] - + sys.argv[1:], - capture_output=True, -).stdout.decode() - -cmakeFlags = {} -for arg in cmakeFlagsList.split(): - key, value = arg.split("=") - - # Remove -D and the type - key = key.replace("-D", "").split(":")[0] - - cmakeFlags[key] = value - -cmakeFlags.pop("CMAKE_BUILD_TYPE") +# Parse CMake flags and environment +cmakeSettings = json.loads( + subprocess.run( + [ + *bbsBuildExecutable, + "configure", + "--dump-cmake-flags", + ] + + sys.argv[1:], + capture_output=True, + ).stdout.decode() +) print(f"Generating .vscode folder...") print(f" BDE tools directory: {bdeToolsDir}") @@ -80,12 +78,50 @@ def backup(path: pathlib.Path): os.makedirs(".vscode", exist_ok=True) -templatesPath = binDir / "vscode_templates" +# Find vscode templates path +templatesLocations = [ + location + for location in [ + bdeToolsDir / "share" / "templates" / "vscode", + pathlib.Path(os.getenv("DISTRIBUTION_REFROOT", "/")) + / "opt" + / "bb" + / "libexec" + / "bde-tools" + / "templates" + / "vscode", + ] + if location.exists() +] + +if not templatesLocations: + print("Error: vscode templates location not found.") + sys.exit(1) + +templatesPath = templatesLocations[0] # settings.json settings = json.loads((templatesPath / "settings.json").read_text()) -settings["cmake.buildDirectory"] = "${workspaceFolder}/" + buildDir -settings["cmake.configureSettings"] = cmakeFlags + +settings["cmake.copyCompileCommands"] = f"{projectCache}/compile_commands.json" +settings["clangd.arguments"].append(f"--compile-commands-dir={projectCache}") +settings["cmake.buildDirectory"] = buildDir +settings["cmake.configureSettings"] = cmakeSettings["flags"] +settings["cmake.environment"] = cmakeSettings["env"] + +# Under WSL, vscode has problems downloading extensions behind proxy. +# Downloading on the host system helps. +if isWSL: + settings["remote.downloadExtensionsLocally"] = True + +platform = {"linux": "linux", "darwin": "osx", "win32": "windows"}[ + sys.platform +] +settings[f"terminal.integrated.env.{platform}"] = { + key: value + for key, value in cmakeSettings["env"].items() + if "BDE" in key or "BBS" in key or key in ["CC", "CXX"] +} def setCompiler(envVar, cmakeVar): @@ -101,28 +137,105 @@ def setCompiler(envVar, cmakeVar): json.dumps(settings, indent=4) ) +# cmake-variants.yaml +pathlib.Path(".vscode/cmake-variants.yaml").write_text( + f"""\ +buildType: + default: {ufid} + choices: + {ufid}: + short: {ufid} + buildType: {cmakeSettings["flags"]["CMAKE_BUILD_TYPE"]} +""" +) + +# cmake-kits.json +pathlib.Path(".vscode/cmake-kits.json").write_text( + """\ +[ + { + "name": "bbs_build", + "compilers": {}, + "isTrusted": true + } +] +""" +) + + # c_cpp_properties.json backup(pathlib.Path(".vscode/c_cpp_properties.json")) shutil.copy(templatesPath / "c_cpp_properties.json", ".vscode") -# extensions.json -backup(pathlib.Path(".vscode/extensions.json")) -shutil.copy(templatesPath / "extensions.json", ".vscode") +# tasks.json +tasksPath = pathlib.Path(".vscode/tasks.json") +tasks = json.loads( + (templatesPath / "tasks.json") + .read_text() + .replace("$$projectCachePath$$", projectCache) +) + +# Under WSL, we need the host code executable to install extensions +# behind proxy. +codepath = "code" +if isWSL: + codepath = shutil.which("code").replace(" ", "\\ ") +for task in tasks["tasks"]: + task["command"] = task["command"].replace("$$codepath$$", codepath) + +if isGitBash: + tasks.setdefault("options", dict()).setdefault("shell", dict()).update( + { + "executable": bashExecutable, + "args": ["-l", "-c"], + } + ) + + for task in tasks["tasks"]: + if "bbs_build " in task["command"]: + task.setdefault("options", dict()).setdefault( + "env", dict() + ).update(cmakeSettings["env"]) + +backup(tasksPath).write_text(json.dumps(tasks, indent=4)) # launch.json -commonLaunchArgs = json.loads( - (templatesPath / "common_launch_args.json").read_text() +Debugger = namedtuple("Debugger", ["extension"]) +debuggers = dict( + filter( + lambda item: shutil.which(item[0]) is not None, + { + "udb": Debugger("undo.udb"), + "gdb": Debugger(None), + "lldb": Debugger("llvm-vs-code-extensions.lldb-dap"), + }.items(), + ) ) -launchConfigNames = ( - ["gdb_launch", "udb_launch"] if not isGitBash else ["cppvsdbg_launch"] +if isGitBash: + debuggers["cppvsdbg"] = Debugger(None) + +commonLaunchArgs = json.loads( + (templatesPath / "common_launch_args.json") + .read_text() + .replace("$$executableSuffix$$", ".exe" if isGitBash else "") ) +installBdePrettyPrinters = False launchConfigs = [] -for configName in launchConfigNames: - config = json.loads((templatesPath / f"{configName}.json").read_text()) - config.update(commonLaunchArgs) - launchConfigs.append(config) +for debuggerName in debuggers.keys(): + for name, launchArgs in commonLaunchArgs.items(): + configText = ( + templatesPath / f"{debuggerName}_launch.json" + ).read_text() + installBdePrettyPrinters = ( + installBdePrettyPrinters + or "init-bde-pretty-printers" in configText + ) + config = json.loads(configText) + config["name"] = config["name"] + name + config.update(launchArgs) + launchConfigs.append(config) launch = json.loads((templatesPath / "launch.json").read_text()) launch["configurations"] = launchConfigs @@ -130,6 +243,37 @@ def setCompiler(envVar, cmakeVar): json.dumps(launch, indent=4) ) +# extensions.json +extensions = json.loads((templatesPath / "extensions.json").read_text()) +extensions["recommendations"].extend( + [ + debugger.extension + for debugger in debuggers.values() + if debugger.extension is not None + ] +) + +backup(pathlib.Path(".vscode/extensions.json")).write_text( + json.dumps(extensions, indent=4) +) + + +# pretty-printers +gdbinit = f"""\ +python +## Import bde pretty printers +import sys + +sys.path.append("{binDir.parent / "contrib" / "gdb-printers"}") +import bde_printer + +bde_printer.reload() +end +""" + +if installBdePrettyPrinters: + pathlib.Path(".vscode/init-bde-pretty-printers").write_text(gdbinit) + # ----------------------------------------------------------------------------- # Copyright 2022 Bloomberg Finance L.P. diff --git a/bin/bde_get_changed_components.sh b/bin/bde_get_changed_components.sh new file mode 100755 index 00000000..7983050a --- /dev/null +++ b/bin/bde_get_changed_components.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +origPwd=$PWD +if [ $# -gt 0 ] ; then + cd $1 +fi +git diff --name-only $(git merge-base $(git branch --show-current) main) | xargs -r -L1 basename | sed 's/\.[^.]*$//' | paste -sd "," - +if [ $# -gt 0 ] ; then + cd $origPwd +fi \ No newline at end of file diff --git a/bin/get_dependers.py b/bin/get_dependers.py index 6a2c247f..a2e20a4d 100644 --- a/bin/get_dependers.py +++ b/bin/get_dependers.py @@ -176,12 +176,13 @@ def update_depender_names(self, components: Dict[str, Component], def get_dependers(targets: List[str], output_targets: bool, - no_missing_target_warning: bool = False) -> List[str]: + no_missing_target_warning: bool = False, + buildDir: Optional[str] = None) -> List[str]: '''Returns a list of components that depend on the specified targets. If 'output_targets' is True, returns a list of targets. If 'no_missing_target_warning' is True, suppresses warnings when some targets are invalid. If no dependers are found, returns an empty list.''' - compile_commands_json_path = locate_compile_commands_json() + compile_commands_json_path = locate_compile_commands_json(buildDir) if not compile_commands_json_path: return [] @@ -206,11 +207,11 @@ def get_dependers(targets: List[str], output_targets: bool, return sorted(depender_names) -def locate_compile_commands_json() -> Optional[Path]: +def locate_compile_commands_json(buildDir : Optional[str]) -> Optional[Path]: '''Locates the 'compile_commands.json' file in the build directory and returns its absolute path. If 'BDE_CMAKE_BUILD_DIR' is not set or the file is not found, prints an error and returns None.''' - bde_cmake_build_dir = os.environ.get("BDE_CMAKE_BUILD_DIR") + bde_cmake_build_dir = os.environ.get("BDE_CMAKE_BUILD_DIR") if buildDir is None else buildDir if bde_cmake_build_dir: json_path = Path.cwd() / bde_cmake_build_dir / "compile_commands.json" if not json_path.exists(): @@ -306,10 +307,20 @@ def main(): help="Suppress warnings when invalid targets are given." ) + parser.add_argument( + "--build_dir", + help = ''' + Path to the build directory. If not specified, + the use one specified in BDE_CMAKE_BUILD_DIR environment + variable. + ''' + ) + args = parser.parse_args() dependers = get_dependers(args.targets, args.output_targets, - args.no_missing_target_warning) + args.no_missing_target_warning, + args.build_dir) # combine dependencies into a comma separated list in string and print if dependers: diff --git a/bin/vscode_templates/common_launch_args.json b/bin/vscode_templates/common_launch_args.json deleted file mode 100644 index 427871b2..00000000 --- a/bin/vscode_templates/common_launch_args.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "request": "launch", - "program": "${command:cmake.launchTargetPath}", - "args": [ - "${input:args}" - ], - "stopAtEntry": true, - "cwd": "${command:cmake.getLaunchTargetDirectory}", - "environment": [] -} \ No newline at end of file diff --git a/bin/vscode_templates/extensions.json b/bin/vscode_templates/extensions.json deleted file mode 100644 index 7d6b2118..00000000 --- a/bin/vscode_templates/extensions.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. - // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp - // List of extensions which should be recommended for users of this workspace. - "recommendations": [ - // C++ - "ms-vscode.cpptools-extension-pack", // includes cmake and C++ plugins - "llvm-vs-code-extensions.vscode-clangd", // clangd - "xaver.clang-format", // clang-format plugin for bde-format - "undo.udb", // UDB - ], -} \ No newline at end of file diff --git a/lib/python/bbs/env/main.py b/lib/python/bbs/env/main.py index a82cdff9..1d32df6f 100644 --- a/lib/python/bbs/env/main.py +++ b/lib/python/bbs/env/main.py @@ -267,7 +267,13 @@ def print_envs(args, ufid, profile): build_path = Path(args.build_dir).resolve() print(f'export BDE_CMAKE_BUILD_DIR="{build_path}"') else: - build_path = Path(f"_build/{uplid}-{ufid}").resolve() + # BDE_BUILD_AREA is set by bde_docker to reduce the number of queries + # to the host file system + build_path = ( + Path(os.getenv("BDE_BUILD_AREA", os.getcwd())) + / "_build" + / f"{uplid}-{ufid}" + ) print(f'export BDE_CMAKE_BUILD_DIR="{build_path}"') if os_type == "windows": @@ -284,7 +290,6 @@ def print_envs(args, ufid, profile): else: print(f'unset BDE_CMAKE_TOOLCHAIN') - install_dir = args.install_dir if args.install_dir else "_install" print("Using install directory: %s" % os.path.abspath(install_dir), diff --git a/bin/vscode_templates/c_cpp_properties.json b/share/templates/vscode/c_cpp_properties.json similarity index 100% rename from bin/vscode_templates/c_cpp_properties.json rename to share/templates/vscode/c_cpp_properties.json diff --git a/share/templates/vscode/common_launch_args.json b/share/templates/vscode/common_launch_args.json new file mode 100644 index 00000000..30caafb3 --- /dev/null +++ b/share/templates/vscode/common_launch_args.json @@ -0,0 +1,19 @@ +{ + "Launch Current Component Test": { + "request": "launch", + "program": "${command:cmake.buildDirectory}/tests/${fileBasenameNoExtension}$$executableSuffix$$", + "args": [ + "${input:args}" + ], + "cwd": "${command:cmake.buildDirectory}/tests", + "preLaunchTask": "Build current component test" + }, + "Launch CMake Launch Target": { + "request": "launch", + "program": "${command:cmake.launchTargetPath}", + "args": [ + "${input:args}" + ], + "cwd": "${command:cmake.getLaunchTargetDirectory}" + } +} \ No newline at end of file diff --git a/bin/vscode_templates/cppvsdbg_launch.json b/share/templates/vscode/cppvsdbg_launch.json similarity index 65% rename from bin/vscode_templates/cppvsdbg_launch.json rename to share/templates/vscode/cppvsdbg_launch.json index 452387de..2b926277 100644 --- a/bin/vscode_templates/cppvsdbg_launch.json +++ b/share/templates/vscode/cppvsdbg_launch.json @@ -1,5 +1,5 @@ { - "name": "(Windows) Launch", + "name": "(Windows) ", "type": "cppvsdbg", "console": "externalTerminal" } \ No newline at end of file diff --git a/share/templates/vscode/extensions.json b/share/templates/vscode/extensions.json new file mode 100644 index 00000000..bc535215 --- /dev/null +++ b/share/templates/vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "ms-vscode.cpptools-extension-pack", + "llvm-vs-code-extensions.vscode-clangd", + "xaver.clang-format" + ] +} diff --git a/bin/vscode_templates/gdb_launch.json b/share/templates/vscode/gdb_launch.json similarity index 68% rename from bin/vscode_templates/gdb_launch.json rename to share/templates/vscode/gdb_launch.json index 15c544d4..d83da1c5 100644 --- a/bin/vscode_templates/gdb_launch.json +++ b/share/templates/vscode/gdb_launch.json @@ -1,5 +1,5 @@ { - "name": "(gdb) Launch", + "name": "(gdb) ", "type": "cppdbg", "externalConsole": false, "MIMode": "gdb", @@ -8,6 +8,9 @@ "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true + }, + { + "text": "source ${workspaceFolder}/.vscode/init-bde-pretty-printers" } ] } \ No newline at end of file diff --git a/bin/vscode_templates/launch.json b/share/templates/vscode/launch.json similarity index 100% rename from bin/vscode_templates/launch.json rename to share/templates/vscode/launch.json diff --git a/share/templates/vscode/lldb_launch.json b/share/templates/vscode/lldb_launch.json new file mode 100644 index 00000000..2031ae4d --- /dev/null +++ b/share/templates/vscode/lldb_launch.json @@ -0,0 +1,4 @@ +{ + "name": "(lldb) ", + "type": "lldb-dap" +} diff --git a/bin/vscode_templates/settings.json b/share/templates/vscode/settings.json similarity index 79% rename from bin/vscode_templates/settings.json rename to share/templates/vscode/settings.json index 45be0df2..fb05650f 100644 --- a/bin/vscode_templates/settings.json +++ b/share/templates/vscode/settings.json @@ -9,7 +9,8 @@ "cmake.ctest.allowParallelJobs": true, "cmake.ctestArgs": [ "-L", - "^${command:cmake.buildTargetName}$" + "^${command:cmake.buildTargetName}$", + "--no-label-summary" ], "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", "files.associations": { @@ -30,8 +31,8 @@ "--background-index", "-j=4", "--enable-config", - "--header-insertion=never", - "--compile-commands-dir=${workspaceFolder}/.vscode" + "--header-insertion=never" ], - "cmake.copyCompileCommands": "${workspaceFolder}/.vscode/compile_commands.json" + "cmake.options.statusBarVisibility": "compact", + "terminal.integrated.scrollback": 20000 } diff --git a/share/templates/vscode/tasks.json b/share/templates/vscode/tasks.json new file mode 100644 index 00000000..5a02650d --- /dev/null +++ b/share/templates/vscode/tasks.json @@ -0,0 +1,290 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "buildenv", + "type": "shell", + "command": "eval `bbs_build_env ${input:params}` && bbs_make_vscode && touch .promptinput", + "problemMatcher": [], + "hide": true, + "presentation": { + "showReuseMessage": false + } + }, + { + "label": "promptbarrier", + "type": "shell", + "command": "if [ -f .promptinput ]; then rm -f .promptinput; else echo 'Prompt cancelled' && exit 1; fi", + "problemMatcher": [], + "hide": true, + "presentation": { + "showReuseMessage": false + } + }, + { + "label": "configure", + "type": "cmake", + "command": "configure", + "problemMatcher": [], + "hide": true, + "presentation": { + "showReuseMessage": false + } + }, + { + "label": "Set up BDE Environment", + "type": "shell", + "command": "cp", + "args": [ + "${command:cmake.buildDirectory}/compile_commands.json", + "$$projectCachePath$$" + ], + "problemMatcher": [], + "dependsOrder": "sequence", + "dependsOn": [ + "buildenv", + "promptbarrier", + "configure" + ], + "presentation": { + "echo": false, + "showReuseMessage": false + } + }, + { + "label": "Run bde_verify on current file", + "type": "shell", + "command": "bde_verify", + "args": [ + "-config", + "${env:BDE_VERIFY_CFG}", + "-cl", + "\"check function-contract off\"", + "-w", + "-p", + "${command:cmake.buildDirectory}", + "${file}" + ], + "problemMatcher": { + "source": "bde_verify", + "base": "$gcc" + }, + "presentation": { + "revealProblems": "onProblem", + "panel": "dedicated", + "showReuseMessage": false, + "clear": true + } + }, + { + "label": "Test current component", + "type": "shell", + "command": "bbs_build build --known-env --target $(echo ${fileBasenameNoExtension} | cut -f 1 -d '.') --test run -v", + "problemMatcher": [ + "$gcc", + { + "owner": "CTest", + "fileLocation": [ + "absolute" + ], + "source": "CTest", + "pattern": [ + { + "regexp": "^(.*)$", + "message": 1 + }, + { + "regexp": "^Error (.*)\\((\\d+)\\): (.*)$", + "file": 1, + "line": 2, + "message": 3 + } + ] + } + ], + "presentation": { + "showReuseMessage": false, + "clear": true, + "revealProblems": "onProblem" + } + }, + { + "label": "Test current package", + "type": "shell", + "command": "bbs_build build --known-env --target $(echo ${fileBasenameNoExtension} | sed -n 's/\\([^_]*\\).*/\\1/p') --test run -v", + "problemMatcher": [ + "$gcc", + { + "owner": "CTest", + "fileLocation": [ + "absolute" + ], + "source": "CTest", + "pattern": [ + { + "regexp": "^(.*)$", + "message": 1 + }, + { + "regexp": "^Error (.*)\\((\\d+)\\): (.*)$", + "file": 1, + "line": 2, + "message": 3 + } + ] + } + ], + "presentation": { + "showReuseMessage": false, + "clear": true, + "revealProblems": "onProblem" + } + }, + { + "label": "Test current group", + "type": "shell", + "command": "bbs_build build --known-env --target $(echo ${fileBasenameNoExtension} | head -c 3) --test run -v", + "problemMatcher": [ + "$gcc", + { + "owner": "CTest", + "fileLocation": [ + "absolute" + ], + "source": "CTest", + "pattern": [ + { + "regexp": "^(.*)$", + "message": 1 + }, + { + "regexp": "^Error (.*)\\((\\d+)\\): (.*)$", + "file": 1, + "line": 2, + "message": 3 + } + ] + } + ], + "presentation": { + "showReuseMessage": false, + "clear": true, + "revealProblems": "onProblem" + } + }, + { + "label": "Test dependers of current component", + "type": "shell", + "command": "bbs_build build --known-env --dependers-of $(echo ${fileBasenameNoExtension} | cut -f 1 -d '.') --test run -v", + "problemMatcher": [ + "$gcc", + { + "owner": "CTest", + "fileLocation": [ + "absolute" + ], + "source": "CTest", + "pattern": [ + { + "regexp": "^(.*)$", + "message": 1 + }, + { + "regexp": "^Error (.*)\\((\\d+)\\): (.*)$", + "file": 1, + "line": 2, + "message": 3 + } + ] + } + ], + "presentation": { + "showReuseMessage": false, + "clear": true, + "revealProblems": "onProblem" + } + }, + { + "label": "Test dependers of changes on branch", + "type": "shell", + "command": "bbs_build build --known-env --dependers-of $(bde_get_changed_components.sh ${fileDirname}) --test run -v", + "problemMatcher": [ + "$gcc", + { + "owner": "CTest", + "fileLocation": [ + "absolute" + ], + "source": "CTest", + "pattern": [ + { + "regexp": "^(.*)$", + "message": 1 + }, + { + "regexp": "^Error (.*)\\((\\d+)\\): (.*)$", + "file": 1, + "line": 2, + "message": 3 + } + ] + } + ], + "presentation": { + "showReuseMessage": false, + "clear": true, + "revealProblems": "onProblem" + } + }, + { + "label": "Build current component test", + "type": "shell", + "command": "bbs_build build --known-env --target $(echo ${fileBasenameNoExtension} | cut -f 1 -d '.') --test build -v", + "problemMatcher": [ + "$gcc" + ], + "presentation": { + "showReuseMessage": false, + "clear": true, + "revealProblems": "onProblem" + } + }, + { + "label": "Clear test problems", + "type": "shell", + "command": "echo \"Clearing test problems...\nDone.\"", + "problemMatcher": [ + { + "owner": "CTest", + "fileLocation": [ + "absolute" + ], + "source": "CTest", + "pattern": { + "regexp": "Never ever match this.", + "message": 0 + } + } + ], + "presentation": { + "showReuseMessage": false, + "clear": true, + "revealProblems": "always" + } + }, + { + "label": "Install Recommended Extensions", + "type": "shell", + "command": "cat .vscode/extensions.json | sed -nE 's/.*\"(.*\\..*)\".*/\\1/p' | xargs -n 1 $$codepath$$ --install-extension", + "problemMatcher": [] + } + ], + "inputs": [ + { + "id": "params", + "description": "Params for bbs_build_env", + "default": "", + "type": "promptString" + } + ] +} diff --git a/bin/vscode_templates/udb_launch.json b/share/templates/vscode/udb_launch.json similarity index 80% rename from bin/vscode_templates/udb_launch.json rename to share/templates/vscode/udb_launch.json index fe37ee47..afa20573 100644 --- a/bin/vscode_templates/udb_launch.json +++ b/share/templates/vscode/udb_launch.json @@ -1,5 +1,5 @@ { - "name": "(UDB) Launch", + "name": "(UDB) ", "type": "cppdbg", "externalConsole": false, "MIMode": "gdb", @@ -8,6 +8,9 @@ "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true + }, + { + "text": "source ${workspaceFolder}/.vscode/init-bde-pretty-printers" } ], "miDebuggerPath": "udb",