From 55c4d5d77007c37d00323a0a328f9d930602a842 Mon Sep 17 00:00:00 2001 From: fcying Date: Fri, 23 Aug 2024 20:19:28 +0800 Subject: [PATCH] fix: check file IsAbsPath --- .github/workflows/release.yml | 6 ++++++ .tasks | 1 + cmd/compiledb/main.go | 2 +- internal/parser.go | 17 ++++++++++------- internal/util.go | 10 ++++++++++ tests/build.log | 3 +++ 6 files changed, 31 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ae749a8..c603d20 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -67,6 +67,12 @@ jobs: ls -la $out + - uses: actions/upload-artifact@v3 + with: + name: bin + path: build/* + retention-days: 90 + - name: Release if: ${{ env.VERSION != '' }} uses: ncipollo/release-action@v1 diff --git a/.tasks b/.tasks index c8e12ca..b7a6812 100644 --- a/.tasks +++ b/.tasks @@ -1,6 +1,7 @@ [build] # command=go run ./cmd/compiledb/main.go -v command=go run ./cmd/compiledb/main.go -v -c -S --full-path < ./tests/build.log +# command=go run ./cmd/compiledb/main.go -v -c --full-path < ./tests/build.log output=terminal [release] diff --git a/cmd/compiledb/main.go b/cmd/compiledb/main.go index 5e0cb47..cf0f72a 100644 --- a/cmd/compiledb/main.go +++ b/cmd/compiledb/main.go @@ -9,7 +9,7 @@ import ( "github.com/urfave/cli/v2" ) -var Version string = "v1.3.0" +var Version string = "v1.3.1" func init() { log.SetOutput(os.Stdout) diff --git a/internal/parser.go b/internal/parser.go index be3f7c7..c44b287 100644 --- a/internal/parser.go +++ b/internal/parser.go @@ -142,11 +142,14 @@ func Parse(buildLog []string) { } // Parse command - arguments, filepath := commandProcess(line, workingDir) + arguments, filePath := commandProcess(line, workingDir) compileFullPath := "" - if filepath != "" { + if filePath != "" { if ParseConfig.NoStrict == false { - fileFullPath := workingDir + "/" + filepath + fileFullPath := filePath + if IsAbsPath(filePath) == false { + fileFullPath = workingDir + "/" + filePath + } if FileExist(fileFullPath) == false { log.Printf("file %s not exist", fileFullPath) continue @@ -154,8 +157,8 @@ func Parse(buildLog []string) { } if ParseConfig.Exclude != "" { - if exclude_regex.MatchString(filepath) { - log.Printf("file %s exclude", filepath) + if exclude_regex.MatchString(filePath) { + log.Printf("file %s exclude", filePath) continue } } @@ -177,13 +180,13 @@ func Parse(buildLog []string) { result = append(result, Command{ Directory: workingDir, Command: command, - File: filepath, + File: filePath, }) } else { result = append(result, Command{ Directory: workingDir, Arguments: arguments, - File: filepath, + File: filePath, }) } log.Printf("Adding command %d: %s", cmdCnt, command) diff --git a/internal/util.go b/internal/util.go index 4d8b682..048fcb7 100644 --- a/internal/util.go +++ b/internal/util.go @@ -32,3 +32,13 @@ func ConvertLinuxPath(path string) string { return linuxPath } + +func IsAbsPath(path string) bool { + if strings.HasPrefix(path, "/") { + return true + } + if strings.HasPrefix(path, "\\") || (len(path) > 1 && path[1] == ':') { + return true + } + return false +} diff --git a/tests/build.log b/tests/build.log index d265903..6220c34 100644 --- a/tests/build.log +++ b/tests/build.log @@ -13,4 +13,7 @@ ccache-clang-11++ -c test2.cpp printf 't' 1>&2;cc -c -DINC=\"t.h\" test3.c +gcc -c /opt/fullpath.c -o objs/fullpath.c.o + + make: Leaving directory 'out/test'