diff --git a/cmd/compiledb/main.go b/cmd/compiledb/main.go index a546bbe..3d7fdd5 100644 --- a/cmd/compiledb/main.go +++ b/cmd/compiledb/main.go @@ -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") diff --git a/internal/parser.go b/internal/parser.go index 45ec0af..5315551 100644 --- a/internal/parser.go +++ b/internal/parser.go @@ -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 @@ -173,6 +174,26 @@ 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(" ") + 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 @@ -180,12 +201,6 @@ func (t *Tool) Parse(buildLog []string) { 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) diff --git a/tests/build.log b/tests/build.log index d88519f..49405bd 100644 --- a/tests/build.log +++ b/tests/build.log @@ -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