diff --git a/package.go b/package.go index 4142110..6c29090 100644 --- a/package.go +++ b/package.go @@ -19,7 +19,6 @@ package gore import ( "fmt" - "path/filepath" "runtime/debug" "sort" "strings" @@ -118,8 +117,8 @@ type PackageClassifier interface { func NewPathPackageClassifier(mainPkgFilepath string) *PathPackageClassifier { return &PathPackageClassifier{ mainFilepath: mainPkgFilepath, mainFolders: []string{ - filepath.Dir(mainPkgFilepath), - filepath.Clean(mainPkgFilepath), + osAwarePathDir(mainPkgFilepath), + osAwarePathClean(mainPkgFilepath), }, } } @@ -160,11 +159,11 @@ func (c *PathPackageClassifier) Classify(pkg *Package) PackageClass { return ClassVendor } - parentFolder := filepath.Dir(pkg.Filepath) + parentFolder := osAwarePathDir(pkg.Filepath) if strings.HasPrefix(pkg.Filepath, c.mainFilepath+"/vendor/") || - strings.HasPrefix(pkg.Filepath, filepath.Dir(c.mainFilepath)+"/vendor/") || - strings.HasPrefix(pkg.Filepath, filepath.Dir(filepath.Dir(c.mainFilepath))+"/vendor/") { + strings.HasPrefix(pkg.Filepath, osAwarePathDir(c.mainFilepath)+"/vendor/") || + strings.HasPrefix(pkg.Filepath, osAwarePathDir(osAwarePathDir(c.mainFilepath))+"/vendor/") { return ClassVendor } @@ -188,11 +187,11 @@ func (c *PathPackageClassifier) Classify(pkg *Package) PackageClass { // If the path does not contain the "vendor" in a path but has the main package folder name, assume part of main. if !strings.Contains(pkg.Filepath, "vendor/") && - (filepath.Base(filepath.Dir(pkg.Filepath)) == filepath.Base(c.mainFilepath)) { + (osAwarePathBase(osAwarePathDir(pkg.Filepath)) == osAwarePathBase(c.mainFilepath)) { return ClassMain } // Special case for entry point package. - if pkg.Name == "" && filepath.Base(pkg.Filepath) == "runtime" { + if pkg.Name == "" && osAwarePathBase(pkg.Filepath) == "runtime" { return ClassSTD } diff --git a/utils.go b/utils.go index 96e7037..a86ed38 100644 --- a/utils.go +++ b/utils.go @@ -14,3 +14,7 @@ func osAwarePathDir(s string) string { func osAwarePathBase(s string) string { return filepath.Base(s) } + +func osAwarePathClean(s string) string { + return filepath.Clean(s) +} diff --git a/utils_windows.go b/utils_windows.go index 5f33c01..d5b3719 100644 --- a/utils_windows.go +++ b/utils_windows.go @@ -23,3 +23,11 @@ func osAwarePathBase(s string) string { return s } } + +func osAwarePathClean(s string) string { + if strings.Contains(s, "/") { + return strings.ReplaceAll(filepath.Clean(s), "\\", "/") + } else { + return s + } +}