Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not compile active file if definition has quoted text #969

Closed
dmyger opened this issue Dec 12, 2019 · 5 comments
Closed

Can not compile active file if definition has quoted text #969

dmyger opened this issue Dec 12, 2019 · 5 comments
Assignees
Labels
bug a bug in the product Feature: configure
Milestone

Comments

@dmyger
Copy link

dmyger commented Dec 12, 2019

Brief Issue Summary

If CMakeLists.txt has any C++ definition with ampersands char it brokes compiling active file.

It does not mater what kind of cmake command used no one of add_definitions, add_compile_definitions nor target_compile_definitions.

Apparent Behavior:

Just add in the file

add_compile_definitions(_WRONG_CHAR_='&')

First try configure the project and check compile_commands.json to ensure that it was correctly processed in compilers option -D_WRONG_CHAR_=\"'&'\"
And you can successfully build entire project as expected.

But if you try run compile only one active file with command cmake.compileFile you will get an error, because this definition will lost first part and leave only "'&'"

Expected:

Compile active file should use the same command from compile_commands.json as it was used to compile entire project.

Other Notes

Originally the issue was noticed with following cmake code:

string(LENGTH "${CMAKE_SOURCE_DIR}/" __SOURCE_PATH_SIZE)
add_compile_definitions(__FILENAME__=\(&__FILE__[${__SOURCE_PATH_SIZE}]\))

To set __FILENAME__ in relative path of current sorce file.

Platform and Versions

  • Operating System: openSUSE 15.0
  • CMake Version: 3.13.4
  • VSCode Version: 1.40.2
  • CMake Tools Extension Version: 1.2.3
  • Compiler/Toolchain: GCC 7.4
@bobbrow
Copy link
Member

bobbrow commented Dec 23, 2019

The problem appears to be in the argument splitting logic where the current token is cleared when a quote char is encountered.

token = '';

This might not have ever worked in the extension. Thanks for reporting it!

@bobbrow bobbrow added bug a bug in the product Feature: configure labels Dec 23, 2019
@bobbrow bobbrow changed the title Can not compile active file if definition has ampersand char Can not compile active file if definition has quoted text Dec 23, 2019
@andreeis andreeis added this to the 1.4.0 milestone Jan 24, 2020
@ThorstenKleinSmith
Copy link

Looks like this is the same as issue #605

@Trass3r
Copy link

Trass3r commented Sep 14, 2020

The problem appears to be in the argument splitting logic where the current token is cleared when a quote char is encountered.

token = '';

It's much easier to just let the shell do its job via shell: true or similar.
Had the same problem in another extension.

@stevenr3
Copy link

stevenr3 commented Oct 9, 2020

I think I have a similar problem where compile_commands.json contains:

"command": "C:\\PROGRA~2\\MIB055~1\\2019\\PROFES~1\\VC\\Tools\\MSVC\\1424~1.283\\bin\\Hostx86\\x86\\cl.exe ...
-DQT_TESTCASE_BUILDDIR=\"\\\"D:/Projects/CMakeBuild/vscode/Visual Studio Professional 2019 Release - x86/Debug\\\"\" ...

Build all works fine, but "cmake compile active file" does not.

cl : Command line warning D9002 : ignoring unknown option '-'
cl : Command line warning D9002 : ignoring unknown option '-'
Studio
cl : Command line warning D9002 : ignoring unknown option '-'
Professional
cl : Command line warning D9002 : ignoring unknown option '-'
2019
cl : Command line warning D9002 : ignoring unknown option '-'
cl : Command line warning D9002 : ignoring unknown option '-'
Release
Debug"
cl : Command line warning D9002 : ignoring unknown option '-'

If I paste the command into terminal myself, it also fails.
If I modify the command - changing the leading and trailing \" to " for the -DQT_TESTCASE_BUILDDIR=:

"command": "C:\\PROGRA~2\\MIB055~1\\2019\\PROFES~1\\VC\\Tools\\MSVC\\1424~1.283\\bin\\Hostx86\\x86\\cl.exe ...
-DQT_TESTCASE_BUILDDIR="\\\"D:/Projects/CMakeBuild/vscode/Visual Studio Professional 2019 Release - x86/Debug\\\"" ...

Pasting this into terminal works fine.

Trass3r added a commit to Trass3r/vscode-cmake-tools that referenced this issue Oct 9, 2020
in particular macro definitions containing quotes and spaces
fixes microsoft#969 microsoft#1221
Trass3r added a commit to Trass3r/vscode-cmake-tools that referenced this issue Oct 9, 2020
in particular macro definitions containing quotes and spaces
fixes microsoft#969
fixes microsoft#1221
Trass3r added a commit to Trass3r/vscode-cmake-tools that referenced this issue Jan 26, 2021
in particular macro definitions containing quotes and spaces
fixes microsoft#969
fixes microsoft#1221
@andreeis
Copy link
Contributor

We almost have CMake Tools 1.6.0 release out the door. Until then, if you want, you can also verify if this problem has been fixed correctly by installing the vsix built here: https://github.com/microsoft/vscode-cmake-tools/actions/runs/557242002#artifacts.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug a bug in the product Feature: configure
Projects
None yet
Development

No branches or pull requests

7 participants