diff --git a/SConscript b/SConscript index 37494ad..346b565 100644 --- a/SConscript +++ b/SConscript @@ -532,7 +532,8 @@ def _target_entry(target_value): def _generate_project(project_type: str) -> None: source_folder, target_folder = { - 'clion': (os.path.join(_spp_dir.abspath, 'util', 'clion_project_template'), Dir('#.idea').abspath) + 'clion': (os.path.join(_spp_dir.abspath, 'util', 'clion_project_template'), Dir('#.idea').abspath), + 'vscode': (os.path.join(_spp_dir.abspath, 'util', 'vscode_project_template'), Dir('#.vscode').abspath) }.get(project_type, (None, None)) if not source_folder: _error(None, 'Invalid project type option.') @@ -590,6 +591,8 @@ def _generate_project(project_type: str) -> None: 'filename': str(lib_path) }) return result + def _escape_path(input: str) -> str: + return input.replace('\\', '\\\\') jinja_env = jinja2.Environment() jinja_env.globals['generate_uuid'] = _generate_uuid @@ -601,6 +604,8 @@ def _generate_project(project_type: str) -> None: } jinja_env.globals['scons_exe'] = shutil.which('scons') jinja_env.globals['nproc'] = multiprocessing.cpu_count() + + jinja_env.filters['escape_path'] = _escape_path source_path = pathlib.Path(source_folder) target_path = pathlib.Path(target_folder) @@ -712,7 +717,7 @@ AddOption( '--generate_project', dest = 'generate_project', type = 'choice', - choices = ('clion',), + choices = ('clion', 'vscode'), nargs = 1, action = 'store' ) diff --git a/util/vscode_project_template/extensions.json b/util/vscode_project_template/extensions.json new file mode 100644 index 0000000..a0a5ba1 --- /dev/null +++ b/util/vscode_project_template/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "ms-vscode.cpptools", + "llvm-vs-code-extensions.vscode-clangd" + ] +} \ No newline at end of file diff --git a/util/vscode_project_template/launch.json.jinja b/util/vscode_project_template/launch.json.jinja new file mode 100644 index 0000000..fd623b0 --- /dev/null +++ b/util/vscode_project_template/launch.json.jinja @@ -0,0 +1,18 @@ +{ + "configurations": [ + {% for executable in project.executables %} + {% set build_type_name = build_type | capitalize -%} + { + "name": "Debug {{ executable.name }}", + "type": "cppvsdbg", + "request": "launch", + "program": "{{ executable.filename | escape_path }}", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "console": "integratedTerminal" + } + {% endfor %} + ] +} \ No newline at end of file diff --git a/util/vscode_project_template/tasks.json.jinja b/util/vscode_project_template/tasks.json.jinja new file mode 100644 index 0000000..f753166 --- /dev/null +++ b/util/vscode_project_template/tasks.json.jinja @@ -0,0 +1,69 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + {% for executable in project.executables %} + {% for build_type in project.build_types %} + {% set build_type_name = build_type | capitalize -%} + { + "label": "{{ executable.name }} {{ build_type_name }}", + "type": "shell", + "command": "{{ scons_exe | escape_path }} -j{{ nproc }} --build_type={{ build_type }} --unity=disable {{ executable.filename | escape_path }} compile_commands.json", + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "label": "{{ executable.name }} {{ build_type_name }} Clean", + "type": "shell", + "command": "{{ scons_exe | escape_path }} --build_type={{ build_type }} --unity=disable {{ executable.filename | escape_path }} -c", + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": false + } + }, + {% endfor %} + {% endfor %} + {% for library in project.libraries %} + {% for build_type in project.build_types %} + {% set build_type_name = build_type | capitalize -%} + { + "label": "{{ library.name }} {{ build_type_name }}", + "type": "shell", + "command": "{{ scons_exe | escape_path }} -j{{ nproc }} --build_type={{ build_type }} --unity=disable {{ library.filename | escape_path }} compile_commands.json", + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "label": "{{ library.name }} {{ build_type_name }} Clean", + "type": "shell", + "command": "{{ scons_exe | escape_path }} --build_type={{ build_type }} --unity=disable {{ library.filename | escape_path }} -c", + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": false + } + }, + {% endfor %} + {% endfor %} + ] +} \ No newline at end of file