Skip to content

Commit

Permalink
fix: check file IsAbsPath
Browse files Browse the repository at this point in the history
  • Loading branch information
fcying committed Aug 23, 2024
1 parent be648cd commit 55c4d5d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .tasks
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion cmd/compiledb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 10 additions & 7 deletions internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,23 @@ 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
}
}

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
}
}
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions tests/build.log
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 55c4d5d

Please sign in to comment.