Skip to content

Commit

Permalink
Handle lines without matching parenthesis better (#658)
Browse files Browse the repository at this point in the history
* fix extra paren

* only need to do the parsing and stripping of not paired parenthesis

* update changelog

* fix spacing in tests

* another spacing fix
  • Loading branch information
gcampbell-msft authored Oct 11, 2024
1 parent a7b6ae3 commit 36a5174
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Improvements:
Bug Fixes:

- Ensure that we append line endings, which fixes a recent regression. [#641](https://github.com/microsoft/vscode-makefile-tools/issues/641)
- Ensure we handle parenthesis without their partner correctly. [#543](https://github.com/microsoft/vscode-makefile-tools/issues/543)

Improvements:

Expand Down
Binary file added makefile-tools.zip
Binary file not shown.
2 changes: 2 additions & 0 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,7 @@ export async function parseCustomConfigProvider(
// Read the dry-run output line by line, searching for compilers and directory changing commands
// to construct information for the CppTools custom configuration
let dryRunOutputLines: string[] = dryRunOutputStr.split("\n");
dryRunOutputLines = util.removeSplitUpParenthesis(dryRunOutputLines);
let numberOfLines: number = dryRunOutputLines.length;
let index: number = 0;
let done: boolean = false;
Expand Down Expand Up @@ -1408,6 +1409,7 @@ export async function parseLaunchConfigurations(
// searching for compilers, linkers and directory changing commands
// to construct information for the launch configuration
let dryRunOutputLines: string[] = dryRunOutputStr.split("\n");
dryRunOutputLines = util.removeSplitUpParenthesis(dryRunOutputLines);
let numberOfLines: number = dryRunOutputLines.length;
let index: number = 0;
let done: boolean = false;
Expand Down
4 changes: 2 additions & 2 deletions src/test/fakeSuite/Repros/8cc_linux_baseline.out
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Sending configuration for file {REPO:VSCODE-MAKEFILE-TOOLS}/src/test/fakeSuite/R
Compiler Path: {REPO:VSCODE-MAKEFILE-TOOLS}/src/test/fakeSuite/Repros/bin/GitHub/compilers/cc
Compiler Arguments: -Wall;-Wno-strict-aliasing;-g;-O0;-c;-o;encoding.o;encoding.c
---------------------------------------------------------------------------------------------------
Found compiler command: cc -o 8cc main.o cpp.o debug.o dict.o gen.o lex.o vector.o parse.o buffer.o map.o error.o path.o file.o set.o encoding.o
Found compiler command: cc -o 8cc main.o cpp.o debug.o dict.o gen.o lex.o vector.o parse.o buffer.o map.o error.o path.o file.o set.o encoding.o
Sending Workspace Browse Configuration: -----------------------------------
Browse Path: {REPO:VSCODE-MAKEFILE-TOOLS}/src/test/fakeSuite/Repros
Standard: c11
Expand All @@ -200,7 +200,7 @@ Sending Workspace Browse Configuration: -----------------------------------
----------------------------------------------------------------------------
Parsing for IntelliSense elapsed time: 0
Parsing for launch targets.
Found linker command: cc -o 8cc main.o cpp.o debug.o dict.o gen.o lex.o vector.o parse.o buffer.o map.o error.o path.o file.o set.o encoding.o
Found linker command: cc -o 8cc main.o cpp.o debug.o dict.o gen.o lex.o vector.o parse.o buffer.o map.o error.o path.o file.o set.o encoding.o
Producing target binary: 8cc
Adding launch configuration:
{REPO:VSCODE-MAKEFILE-TOOLS}/src/test/fakeSuite/Repros>8cc()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Preprocess elapsed time: 0
Parsing for IntelliSense.
Updating the CppTools IntelliSense Configuration Provider.
Parsing dry-run output for CppTools Custom Configuration Provider.
Found compiler command: gcc "myfile.cpp" /DBETWEEN=\'some.value\' /DBETWEEN_EMPTY=\'\' /DBETWEEN_SPACE=\'some value\' /DBETWEEN_INNER_QUOTE=\'some'value\' /DBETWEEN_INNER_QUOTE_SLASH=\'some\" /'/ \` value\'
Found compiler command: gcc "myfile.cpp" /DBETWEEN=\'some.value\' /DBETWEEN_EMPTY=\'\' /DBETWEEN_SPACE=\'some value\' /DBETWEEN_INNER_QUOTE=\'some'value\' /DBETWEEN_INNER_QUOTE_SLASH=\'some\" /'/ \` value\'
Sending configuration for file {REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\Repros\myfile.cpp -----------------------------------
Defines: BETWEEN=\'some.value\';BETWEEN_EMPTY=\'\';BETWEEN_SPACE=\'some value\';BETWEEN_INNER_QUOTE=\'some'value\';BETWEEN_INNER_QUOTE_SLASH=\'some\" /'/ \` value\'
Includes:
Expand All @@ -54,7 +54,7 @@ Sending configuration for file {REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\R
Compiler Arguments:
Windows SDK Version: 12.3.45678.9\
---------------------------------------------------------------------------------------------------
Found compiler command: gcc '/DBETWEEN=\'some.value\'' /D"'BETWEEN_EMPTY'=\'\'" myfile.cpp /D'BETWEEN_SPACE=\'some value\'' /D "BETWEEN_INNER_QUOTE=\'some value\'" /DBETWEEN_INNER_QUOTE_SLASH='\'some\" /"/ \` value\''
Found compiler command: gcc '/DBETWEEN=\'some.value\'' /D"'BETWEEN_EMPTY'=\'\'" myfile.cpp /D'BETWEEN_SPACE=\'some value\'' /D "BETWEEN_INNER_QUOTE=\'some value\'" /DBETWEEN_INNER_QUOTE_SLASH='\'some\" /"/ \` value\''
Sending configuration for file {REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\Repros\myfile.cpp -----------------------------------
Defines: BETWEEN=\'some.value\';'BETWEEN_EMPTY'=\'\';BETWEEN_SPACE=\'some value\';BETWEEN_INNER_QUOTE=\'some value\';BETWEEN_INNER_QUOTE_SLASH='\'some\" /"/ \` value\''
Includes:
Expand All @@ -76,7 +76,7 @@ Sending configuration for file {REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\R
Compiler Arguments:
Windows SDK Version: 12.3.45678.9\
---------------------------------------------------------------------------------------------------
Found compiler command: gcc '/DBETWEEN=\'some.value\'' /D'\'BETWEEN_EMPTY\'=\'\'' myfile.cpp /D'BETWEEN_SPACE=\'some value\'' /D 'BETWEEN_INNER_QUOTE=\'some value\'' /DBETWEEN_INNER_QUOTE_SLASH='\'some\" /\'/ \` value\''
Found compiler command: gcc '/DBETWEEN=\'some.value\'' /D'\'BETWEEN_EMPTY\'=\'\'' myfile.cpp /D'BETWEEN_SPACE=\'some value\'' /D 'BETWEEN_INNER_QUOTE=\'some value\'' /DBETWEEN_INNER_QUOTE_SLASH='\'some\" /\'/ \` value\''
Sending configuration for file {REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\Repros\myfile.cpp -----------------------------------
Defines: BETWEEN=\'some.value\';\'BETWEEN_EMPTY\'=\'\';BETWEEN_SPACE=\'some value\';BETWEEN_INNER_QUOTE=\'some value\';BETWEEN_INNER_QUOTE_SLASH='\'some\" /\'/ \` value\''
Includes:
Expand All @@ -98,7 +98,7 @@ Sending configuration for file {REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\R
Compiler Arguments:
Windows SDK Version: 12.3.45678.9\
---------------------------------------------------------------------------------------------------
Found compiler command: gcc '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder with space\subfolder"' '/I"{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder"' /I'..' '/I "..\folder with space"' "myfile.cpp" ' /I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\\'folder1 with space\'\\`folder2 with space\`\subfolder" '
Found compiler command: gcc '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder with space\subfolder"' '/I"{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder"' /I'..' '/I "..\folder with space"' "myfile.cpp" ' /I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\\'folder1 with space\'\\`folder2 with space\`\subfolder" '
Sending configuration for file {REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\Repros\myfile.cpp -----------------------------------
Defines:
Includes: {REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder with space\subfolder;{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder;{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite;{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\folder with space;{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\\'folder1 with space\'\\`folder2 with space\`\subfolder
Expand All @@ -120,7 +120,7 @@ Sending configuration for file {REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\R
Compiler Arguments:
Windows SDK Version: 12.3.45678.9\
---------------------------------------------------------------------------------------------------
Found compiler command: gcc '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\\"folder with space\"\subfolder"' '/I"{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder with space\subfolder"' '/I`..`' '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder \"with\" space\subfolder" ' /I '..\"folder with space"\subfolder' "myfile.cpp" '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\\'folder1 with space\'\\`folder2 with space\`\subfolder"'
Found compiler command: gcc '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\\"folder with space\"\subfolder"' '/I"{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder with space\subfolder"' '/I`..`' '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder \"with\" space\subfolder" ' /I '..\"folder with space"\subfolder' "myfile.cpp" '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\\'folder1 with space\'\\`folder2 with space\`\subfolder"'
Sending configuration for file {REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\Repros\myfile.cpp -----------------------------------
Defines:
Includes: {REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\\"folder with space\"\subfolder;{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder with space\subfolder;{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite;{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\"folder with space"\subfolder;{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\\'folder1 with space\'\\`folder2 with space\`\subfolder
Expand All @@ -140,12 +140,12 @@ Sending Workspace Browse Configuration: -----------------------------------
----------------------------------------------------------------------------
Parsing for IntelliSense elapsed time: 0
Parsing for launch targets.
Found linker command: gcc "myfile.cpp" /DBETWEEN=\'some.value\' /DBETWEEN_EMPTY=\'\' /DBETWEEN_SPACE=\'some value\' /DBETWEEN_INNER_QUOTE=\'some'value\' /DBETWEEN_INNER_QUOTE_SLASH=\'some\" /'/ \` value\'
Found linker command: gcc "myfile.cpp" /DBETWEEN=\'some.value\' /DBETWEEN_EMPTY=\'\' /DBETWEEN_SPACE=\'some value\' /DBETWEEN_INNER_QUOTE=\'some'value\' /DBETWEEN_INNER_QUOTE_SLASH=\'some\" /'/ \` value\'
The link command is not producing a target binary explicitly. Assuming a.out
Producing target binary: a.out
Adding launch configuration:
{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\Repros>a.out()
Found linker command: gcc '/DBETWEEN=\'some.value\'' /D"'BETWEEN_EMPTY'=\'\'" myfile.cpp /D'BETWEEN_SPACE=\'some value\'' /D "BETWEEN_INNER_QUOTE=\'some value\'" /DBETWEEN_INNER_QUOTE_SLASH='\'some\" /"/ \` value\''
Found linker command: gcc '/DBETWEEN=\'some.value\'' /D"'BETWEEN_EMPTY'=\'\'" myfile.cpp /D'BETWEEN_SPACE=\'some value\'' /D "BETWEEN_INNER_QUOTE=\'some value\'" /DBETWEEN_INNER_QUOTE_SLASH='\'some\" /"/ \` value\''
The link command is not producing a target binary explicitly. Assuming a.out
Producing target binary: a.out
Adding launch configuration:
Expand All @@ -155,7 +155,7 @@ The link command is not producing a target binary explicitly. Assuming a.out
Producing target binary: a.out
Adding launch configuration:
{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\Repros>a.out()
Found linker command: gcc '/DBETWEEN=\'some.value\'' /D'\'BETWEEN_EMPTY\'=\'\'' myfile.cpp /D'BETWEEN_SPACE=\'some value\'' /D 'BETWEEN_INNER_QUOTE=\'some value\'' /DBETWEEN_INNER_QUOTE_SLASH='\'some\" /\'/ \` value\''
Found linker command: gcc '/DBETWEEN=\'some.value\'' /D'\'BETWEEN_EMPTY\'=\'\'' myfile.cpp /D'BETWEEN_SPACE=\'some value\'' /D 'BETWEEN_INNER_QUOTE=\'some value\'' /DBETWEEN_INNER_QUOTE_SLASH='\'some\" /\'/ \` value\''
The link command is not producing a target binary explicitly. Assuming a.out
Producing target binary: a.out
Adding launch configuration:
Expand All @@ -165,7 +165,7 @@ The link command is not producing a target binary explicitly. Assuming a.out
Producing target binary: a.out
Adding launch configuration:
{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\Repros>a.out()
Found linker command: gcc '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder with space\subfolder"' '/I"{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder"' /I'..' '/I "..\folder with space"' "myfile.cpp" ' /I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\\'folder1 with space\'\\`folder2 with space\`\subfolder" '
Found linker command: gcc '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder with space\subfolder"' '/I"{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder"' /I'..' '/I "..\folder with space"' "myfile.cpp" ' /I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\\'folder1 with space\'\\`folder2 with space\`\subfolder" '
The link command is not producing a target binary explicitly. Assuming a.out
Producing target binary: a.out
Adding launch configuration:
Expand All @@ -175,7 +175,7 @@ The link command is not producing a target binary explicitly. Assuming a.out
Producing target binary: a.out
Adding launch configuration:
{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\Repros>a.out()
Found linker command: gcc '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\\"folder with space\"\subfolder"' '/I"{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder with space\subfolder"' '/I`..`' '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder \"with\" space\subfolder" ' /I '..\"folder with space"\subfolder' "myfile.cpp" '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\\'folder1 with space\'\\`folder2 with space\`\subfolder"'
Found linker command: gcc '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\\"folder with space\"\subfolder"' '/I"{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder with space\subfolder"' '/I`..`' '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\folder \"with\" space\subfolder" ' /I '..\"folder with space"\subfolder' "myfile.cpp" '/I "{REPO:VSCODE-MAKEFILE-TOOLS}\src\test\fakeSuite\repros\\'folder1 with space\'\\`folder2 with space\`\subfolder"'
The link command is not producing a target binary explicitly. Assuming a.out
Producing target binary: a.out
Adding launch configuration:
Expand Down
16 changes: 16 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,22 @@ export function removeQuotes(str: string): string {
return str;
}

export function removeSplitUpParenthesis(strArray: string[]): string[] {
const resultArray: string[] = [];

for (const str of strArray) {
let result: string = str.trim();
if (result.startsWith("(") && !result.endsWith(")")) {
result = result.substring(1, str.length - 1);
} else if (result.endsWith(")") && !result.startsWith("(")) {
result = result.substring(0, str.length - 2);
}
resultArray.push(result.trim());
}

return resultArray;
}

// Remove only the quotes (", ' or `) that are surrounding the given string.
export function removeSurroundingQuotes(str: string): string {
let result: string = str.trim();
Expand Down

0 comments on commit 36a5174

Please sign in to comment.