tpm2-tss icon indicating copy to clipboard operation
tpm2-tss copied to clipboard

[RFC] vscode support

Open joholl opened this issue 9 months ago • 8 comments

This one might be opinionated.

So far there is no clean way to get first-class language support in vscode. Add make target for creating a compilation database using bear. This enables you to do the following

make -j compile_commands.json

This file is recognized by many tools including e.g. clang-tidy and the vscode clangd extension. This way, the vscode language server knows exactly where symbols come from, which #ifdefs are compiled and where to find the right headers.

I also added a launch.json which lets you debug single unit and integration tests easily. What do you think of this?

Things I thought of but did not want to do in this first step:

  • Automatic test discovery/running with something like Test Explorer
  • A devcontainer
  • IDE-integrated formatting (clang-format) and linting (e.g. clang-tidy, I will probably submit that as a future PR)

Why _vscode and not .vscode? Because this leaves users who want to use their own, different .vscode with a dirty working tree. Once-tracked files cannot be .gitignore-d and there is no clean way to resolve this.

joholl avatar May 17 '24 14:05 joholl

Although this is a draft, it is ready for comments!

joholl avatar May 17 '24 14:05 joholl

@joholl I tried it on ubuntu 22.04 (bear installed with apt) But compile_commands.json only contained [] ?

JuergenReppSIT avatar May 19 '24 10:05 JuergenReppSIT

@JuergenReppSIT Weird, that happens when no files are built by make. The command should rebuild the whole project (depending on how you ./configured it. The following is the command executed. Can you try calling make clean before?

bear -- make --always-make check-programs

joholl avatar May 19 '24 10:05 joholl

@joholl I tried the following: make clean make -j compile_commands.json compile_commands.json was again produced with [] and tss was not compiled. If I enter make -j afterwards tss was compiled. The begining of the output of make -j compile_commands.json was as follows:

oot@0d5cd7b145f2:/workspace/tpm2-tss# make -j compile_commands.json
  GEN      compile_commands.json
E0519 12:17:35.683570767  533308 server_chttp2.cc:40]        {"created":"@1716121055.683527884","description":"Only 1 addresses added out of total 2 resolved","file":"src/core/ext/transport/chttp2/server/chttp2_server.cc","file_line":406,"referenced_errors":[{"created":"@1716121055.683522157","description":"Address family not supported by protocol","errno":97,"file":"src/core/lib/iomgr/socket_utils_common_posix.cc","file_line":403,"os_error":"Address family not supported by protocol","syscall":"socket","target_address":"[::1]:33281"}]}
make[1]: Entering directory '/workspace/tpm2-tss'
CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/bash '/workspace/tpm2-tss/missing' aclocal-1.16 -I m4 --install
CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/bash '/workspace/tpm2-tss/missing' autoconf
 cd . && /bin/bash /workspace/tpm2-tss/missing automake-1.16 --foreign
/bin/bash ./config.status --recheck
running CONFIG_SHELL=/bin/bash /bin/bash ./configure --enable-debug CC=clang --no-create --no-recursion
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes

JuergenReppSIT avatar May 19 '24 12:05 JuergenReppSIT