From a7f0f5ad27dfafa582d3209797620d44ac9de225 Mon Sep 17 00:00:00 2001 From: dogtopus Date: Tue, 15 Aug 2023 22:23:09 -0300 Subject: [PATCH 1/2] Improve vscode clangd experience (#2431) * Improve vscode clangd experience - Resolve and use absolute path for the toolchain. This allows clangd to use compile_commands.json file without running under fbtenv, simplifies setup for vscode clangd extension. As a side effect, a rebuild is needed to update compile_commands.json after moving the source tree. - Add the recommended default settings of the extension to settings.json. * Use build/latest for compile-commands-dir This makes it behave closer to c-cpp-properties. * Reformat crosscc.py This is a PEP-8 violation but black seems to enforce it * Bypass --query-driver This has some security implications as it grants clangd the ability to execute any executables anywhere while trying to probe a compiler based on CDB. However it's very hard to do this the safe and intended way without resorting to config generation due to reason listed in #2431. Besides that we already have workspace trust so what could go wrong? ;) * Add an option for vscode_dist to switch between clangd and cpptools This will install different extensions.json tuned for either clangd or cpptools based on user selection. It will also install c_cpp_properties.json when using cpptools since clangd doesn't use this file. The root .gitignore now also doesn't accidentally ignore everything under the .vscode directory. * Use absolute path for .vscode gitignore Turns out the previously used "relative" paths aren't even valid gitignore patterns and to actually do what it means one needs to use the absolute paths instead. * Handle variable parsing in commandline.scons commandline.scons is the place where all other command line parsing happens. Move LANG_SERVER variable parsing there and add a constraint to make the code more consistent. --------- Co-authored-by: hedger Co-authored-by: hedger --- .vscode/.gitignore | 9 +++++---- .vscode/example/clangd/extensions.json | 19 +++++++++++++++++++ .../{ => cpptools}/c_cpp_properties.json | 0 .../{ => example/cpptools}/extensions.json | 1 + .vscode/example/settings.json | 9 +++++++-- SConstruct | 10 +++++++++- documentation/fbt.md | 2 ++ scripts/fbt_tools/crosscc.py | 4 +++- site_scons/commandline.scons | 9 +++++++++ 9 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 .vscode/example/clangd/extensions.json rename .vscode/example/{ => cpptools}/c_cpp_properties.json (100%) rename .vscode/{ => example/cpptools}/extensions.json (93%) diff --git a/.vscode/.gitignore b/.vscode/.gitignore index 670df7d48..481efcdef 100644 --- a/.vscode/.gitignore +++ b/.vscode/.gitignore @@ -1,4 +1,5 @@ -./c_cpp_properties.json -./launch.json -./settings.json -./tasks.json +/c_cpp_properties.json +/extensions.json +/launch.json +/settings.json +/tasks.json diff --git a/.vscode/example/clangd/extensions.json b/.vscode/example/clangd/extensions.json new file mode 100644 index 000000000..daab417cd --- /dev/null +++ b/.vscode/example/clangd/extensions.json @@ -0,0 +1,19 @@ +{ + // 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": [ + "ms-python.black-formatter", + "llvm-vs-code-extensions.vscode-clangd", + "amiralizadeh9480.cpp-helper", + "marus25.cortex-debug", + "zxh404.vscode-proto3", + "augustocdias.tasks-shell-input" + ], + // List of extensions recommended by VS Code that should not be recommended for users of this workspace. + "unwantedRecommendations": [ + "twxs.cmake", + "ms-vscode.cpptools", + "ms-vscode.cmake-tools" + ] +} diff --git a/.vscode/example/c_cpp_properties.json b/.vscode/example/cpptools/c_cpp_properties.json similarity index 100% rename from .vscode/example/c_cpp_properties.json rename to .vscode/example/cpptools/c_cpp_properties.json diff --git a/.vscode/extensions.json b/.vscode/example/cpptools/extensions.json similarity index 93% rename from .vscode/extensions.json rename to .vscode/example/cpptools/extensions.json index ead935b08..a8babee1c 100644 --- a/.vscode/extensions.json +++ b/.vscode/example/cpptools/extensions.json @@ -13,6 +13,7 @@ ], // List of extensions recommended by VS Code that should not be recommended for users of this workspace. "unwantedRecommendations": [ + "llvm-vs-code-extensions.vscode-clangd", "twxs.cmake", "ms-vscode.cmake-tools" ] diff --git a/.vscode/example/settings.json b/.vscode/example/settings.json index 19a03b69d..efa08157b 100644 --- a/.vscode/example/settings.json +++ b/.vscode/example/settings.json @@ -21,5 +21,10 @@ "SConscript": "python", "SConstruct": "python", "*.fam": "python", - } -} + }, + "clangd.arguments": [ + // We might be able to tighten this a bit more to only include the correct toolchain. + "--query-driver=**", + "--compile-commands-dir=${workspaceFolder}/build/latest" + ] +} \ No newline at end of file diff --git a/SConstruct b/SConstruct index d968254b1..04cd057fd 100644 --- a/SConstruct +++ b/SConstruct @@ -45,6 +45,7 @@ distenv = coreenv.Clone( ], ENV=os.environ, UPDATE_BUNDLE_DIR="dist/${DIST_DIR}/f${TARGET_HW}-update-${DIST_SUFFIX}", + VSCODE_LANG_SERVER=ARGUMENTS.get("LANG_SERVER", "cpptools"), ) firmware_env = distenv.AddFwProject( @@ -348,7 +349,14 @@ distenv.PhonyTarget( ) # Prepare vscode environment -vscode_dist = distenv.Install("#.vscode", distenv.Glob("#.vscode/example/*")) +VSCODE_LANG_SERVER = cmd_environment["LANG_SERVER"] +vscode_dist = distenv.Install( + "#.vscode", + [ + distenv.Glob("#.vscode/example/*.json"), + distenv.Glob(f"#.vscode/example/{VSCODE_LANG_SERVER}/*.json"), + ], +) distenv.Precious(vscode_dist) distenv.NoClean(vscode_dist) distenv.Alias("vscode_dist", vscode_dist) diff --git a/documentation/fbt.md b/documentation/fbt.md index 1ab67b4e6..af588382b 100644 --- a/documentation/fbt.md +++ b/documentation/fbt.md @@ -46,6 +46,8 @@ To run cleanup (think of `make clean`) for specified targets, add the `-c` optio `fbt` includes basic development environment configuration for VS Code. Run `./fbt vscode_dist` to deploy it. That will copy the initial environment configuration to the `.vscode` folder. After that, you can use that configuration by starting VS Code and choosing the firmware root folder in the "File > Open Folder" menu. +To use language servers other than the default VS Code C/C++ language server, use `./fbt vscode_dist LANG_SERVER=` instead. Currently `fbt` supports the default language server (`cpptools`) and `clangd`. + - On the first start, you'll be prompted to install recommended plugins. We highly recommend installing them for the best development experience. _You can find a list of them in `.vscode/extensions.json`._ - Basic build tasks are invoked in the Ctrl+Shift+B menu. - Debugging requires a supported probe. That includes: diff --git a/scripts/fbt_tools/crosscc.py b/scripts/fbt_tools/crosscc.py index d0631ca33..42fb4ce4b 100644 --- a/scripts/fbt_tools/crosscc.py +++ b/scripts/fbt_tools/crosscc.py @@ -2,6 +2,8 @@ import subprocess import gdb import objdump +import shutil + import strip from SCons.Action import _subproc from SCons.Errors import StopError @@ -11,7 +13,7 @@ from SCons.Tool import ar, asm, gcc, gnulink, gxx def prefix_commands(env, command_prefix, cmd_list): for command in cmd_list: if command in env: - env[command] = command_prefix + env[command] + env[command] = shutil.which(command_prefix + env[command]) def _get_tool_version(env, tool): diff --git a/site_scons/commandline.scons b/site_scons/commandline.scons index 0d3b1f92e..096cbd54f 100644 --- a/site_scons/commandline.scons +++ b/site_scons/commandline.scons @@ -248,6 +248,15 @@ vars.AddVariables( "Full port name of Flipper to use, if multiple Flippers are connected", "auto", ), + EnumVariable( + "LANG_SERVER", + help="Language server type for vscode_dist.", + default="cpptools", + allowed_values=[ + "cpptools", + "clangd", + ], + ), ) Return("vars") From b90e2ca3426cf4c3e7bf6360e010b7aed71e6e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=82=E3=81=8F?= Date: Wed, 16 Aug 2023 18:16:42 +0900 Subject: [PATCH 2/2] SubGhz: add timeout to subghz_hal_async_tx_test_run (#2975) * SubGhz: add timeout to subghz_hal_async_tx_test_run * Removed full API from unit_test build config --------- Co-authored-by: hedger Co-authored-by: hedger --- applications/debug/unit_tests/application.fam | 1 + .../debug/unit_tests/subghz/subghz_test.c | 5 +++++ .../loader/firmware_api/firmware_api.cpp | 19 ++++++++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/applications/debug/unit_tests/application.fam b/applications/debug/unit_tests/application.fam index 949bb3fc2..ad9a278f3 100644 --- a/applications/debug/unit_tests/application.fam +++ b/applications/debug/unit_tests/application.fam @@ -3,6 +3,7 @@ App( apptype=FlipperAppType.STARTUP, entry_point="unit_tests_on_system_start", cdefines=["APP_UNIT_TESTS"], + requires=["system_settings"], provides=["delay_test"], order=100, ) diff --git a/applications/debug/unit_tests/subghz/subghz_test.c b/applications/debug/unit_tests/subghz/subghz_test.c index 6bdaa641e..e32a57482 100644 --- a/applications/debug/unit_tests/subghz/subghz_test.c +++ b/applications/debug/unit_tests/subghz/subghz_test.c @@ -330,7 +330,12 @@ bool subghz_hal_async_tx_test_run(SubGhzHalAsyncTxTestType type) { return false; } + FuriHalCortexTimer timer = furi_hal_cortex_timer_get(30000000); + while(!furi_hal_subghz_is_async_tx_complete()) { + if(furi_hal_cortex_timer_is_expired(timer)) { + return false; + } furi_delay_ms(10); } furi_hal_subghz_stop_async_tx(); diff --git a/applications/services/loader/firmware_api/firmware_api.cpp b/applications/services/loader/firmware_api/firmware_api.cpp index 6651bf112..47554f628 100644 --- a/applications/services/loader/firmware_api/firmware_api.cpp +++ b/applications/services/loader/firmware_api/firmware_api.cpp @@ -10,6 +10,19 @@ static_assert(!has_hash_collisions(elf_api_table), "Detected API method hash collision!"); +#ifdef APP_UNIT_TESTS +constexpr HashtableApiInterface mock_elf_api_interface{ + { + .api_version_major = 0, + .api_version_minor = 0, + .resolver_callback = &elf_resolve_from_hashtable, + }, + .table_cbegin = nullptr, + .table_cend = nullptr, +}; + +const ElfApiInterface* const firmware_api_interface = &mock_elf_api_interface; +#else constexpr HashtableApiInterface elf_api_interface{ { .api_version_major = (elf_api_version >> 16), @@ -19,10 +32,10 @@ constexpr HashtableApiInterface elf_api_interface{ .table_cbegin = elf_api_table.cbegin(), .table_cend = elf_api_table.cend(), }; - const ElfApiInterface* const firmware_api_interface = &elf_api_interface; +#endif extern "C" void furi_hal_info_get_api_version(uint16_t* major, uint16_t* minor) { - *major = elf_api_interface.api_version_major; - *minor = elf_api_interface.api_version_minor; + *major = firmware_api_interface->api_version_major; + *minor = firmware_api_interface->api_version_minor; } \ No newline at end of file