Skip to content

Commit

Permalink
fix: support unix path in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
fcying committed Oct 7, 2024
1 parent ef31da2 commit 3370c40
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .tasks
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
command=go run ./cmd/compiledb/main.go -v -c --full-path < ./tests/build.log
cwd=$(VIM_ROOT)
output=terminal
close=1

[release]
command=go install ./cmd/compiledb
command=go install ./cmd/compiledb && GOOS=windows go install ./cmd/compiledb && mv ~/go/bin/windows_amd64/compiledb.exe ~/workspace/go/bin
cwd=$(VIM_ROOT)
output=terminal
close=1
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.3.6"
var Version string = "v1.3.7"

func init() {
log.SetOutput(os.Stdout)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/fcying/compiledb-go

go 1.22.3
go 1.23.1

require (
github.com/sirupsen/logrus v1.9.3
Expand Down
9 changes: 5 additions & 4 deletions internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func Parse(buildLog []string) {
workingDir, _ = os.Getwd()
}
}
workingDir = ConvertLinuxPath(workingDir)
workingDir = ConvertPath(workingDir)
log.Infof("workingDir: %s", workingDir)

dirStack := []string{workingDir}
Expand Down Expand Up @@ -120,8 +120,9 @@ func Parse(buildLog []string) {
// Parse directory that make entering/leaving
if make_enter_dir.MatchString(line) {
group := make_enter_dir.FindStringSubmatch(line)
if group != nil {
dirStack = append([]string{ConvertLinuxPath(group[1])}, dirStack...)
if group != nil && len(group) >= 2 {
enterDir := group[1]
dirStack = append([]string{ConvertPath(enterDir)}, dirStack...)
workingDir = dirStack[0]
log.Infof("change workingDir: %s", workingDir)
}
Expand Down Expand Up @@ -166,7 +167,7 @@ func Parse(buildLog []string) {
if ParseConfig.FullPath {
compileFullPath = GetBinFullPath(arguments[0])
if compileFullPath != "" {
compileFullPath = ConvertLinuxPath(compileFullPath)
compileFullPath = ConvertPath(compileFullPath)
arguments[0] = compileFullPath
}
}
Expand Down
19 changes: 12 additions & 7 deletions internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"os/exec"
"runtime"
"strings"

"golang.org/x/text/encoding/simplifiedchinese"
Expand All @@ -27,15 +28,19 @@ func GetBinFullPath(name string) string {
return path
}

func ConvertLinuxPath(path string) string {
linuxPath := strings.ReplaceAll(path, "\\", "/")
func ConvertPath(path string) string {
newPath := strings.ReplaceAll(path, "\\", "/")

// Handle drive letter (e.g., "C:\path" -> "/c/path")
// if len(linuxPath) > 1 && linuxPath[1] == ':' {
// linuxPath = "/" + strings.ToLower(string(linuxPath[0])) + linuxPath[2:]
// }
if runtime.GOOS == "windows" {
// Handle drive letter (e.g.: "/c/path -> c:/path")
if len(newPath) > 2 && newPath[0] == '/' && newPath[2] == '/' {
newPath = string(newPath[1]) + ":" + newPath[2:]
} else if len(newPath) == 2 && newPath[0] == '/' {
newPath = string(newPath[1]) + ":"
}
}

return linuxPath
return newPath
}

func IsAbsPath(path string) bool {
Expand Down

0 comments on commit 3370c40

Please sign in to comment.