Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/compiledb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/urfave/cli/v2"
)

var Version string = "v1.5.3"
var Version string = "v1.5.4"

func createConfig(ctx *cli.Context) internal.Config {
outputFile := ctx.String("output")
Expand Down
27 changes: 21 additions & 6 deletions internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (t *Tool) Parse(buildLog []string) {
cmdCnt = 0
result []Command
matchGroup []string
fullLineBuilder strings.Builder // Buffer for merging multi-line commands
)

// check workingDir
Expand Down Expand Up @@ -173,19 +174,33 @@ func (t *Tool) Parse(buildLog []string) {
}

for _, line := range buildLog {
line = strings.TrimSpace(line)
if line == "" {
continue
}

if before, ok :=strings.CutSuffix(line, "\\"); ok {
// If ending with '\', remove '\' and append a space, then continue to read the next line
fullLineBuilder.WriteString(before)
fullLineBuilder.WriteString(" ")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not inject spaces when joining continued lines

Backslash-newline continuation in shell removes the newline without adding whitespace, but this code always appends a literal space before reading the next line. For commands that split a token across lines (for example gcc -c src/fo\ then o.c -o foo.o), the merged string becomes src/fo o.c, which changes argument boundaries and makes fileRegex capture the wrong source file, producing an incorrect compile database entry.

Useful? React with 👍 / 👎.

continue
} else {
// Otherwise, it is the last line of the command (or a single-line command), append to buffer
fullLineBuilder.WriteString(line)
}
// Get the complete merged line
line = fullLineBuilder.String()
// Reset buffer for the next command
fullLineBuilder.Reset()
t.Logger.Debug("New command:", line)

// Restore workingDir {{{
if backupWorkingDir != "" {
workingDir = backupWorkingDir
backupWorkingDir = ""
t.Logger.Infof("Restore workingDir: %s", workingDir)
}

line = strings.TrimSpace(line)
if line == "" {
continue
}
t.Logger.Debug("New command:", line)

// Parse directory that make entering/leaving {{{
if makeEnterDir.MatchString(line) {
group := makeEnterDir.FindStringSubmatch(line)
Expand Down
4 changes: 3 additions & 1 deletion tests/build.log
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
make: Entering directory '/opt/compiledb_test/src"

clang.exe -I../include -c test1.c -o objs/test1.cc.o
g++ -c test1.cpp
g++ -c test1.cpp \
--strip-unneeded \
-o test1.o
g++ -c test_none.c
ccache-clang-11 -c /opt/compiledb_test/test2.c -o objs/test2.c.o

Expand Down