about summary refs log tree commit diff
path: root/external/main.go
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-12-12T17·04+0000
committerVincent Ambo <mail@tazj.in>2019-12-13T00·39+0000
commit1fd80fb20175c28bc500e6d889594d1a5ebb6be7 (patch)
tree721ca54db5a9aa48253acfb829aca0eeb6d50d84 /external/main.go
parentb20e46d60b14d5e367e52ec14989dc27b4829774 (diff)
fix(external): Correctly set names for root packages
Fixes the prefix trimming logic for package names and source files if
the source files appear in the package root (which is, unsurprisingly,
very common).
Diffstat (limited to 'external/main.go')
-rw-r--r--external/main.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/external/main.go b/external/main.go
index 0c1d84d5b723..028703e38cad 100644
--- a/external/main.go
+++ b/external/main.go
@@ -94,19 +94,27 @@ func analysePackage(root, source, importpath string, stdlib map[string]bool) (pk
 	}
 
 	prefix := strings.TrimPrefix(source, root+"/")
+
+	name := []string{}
+	if len(prefix) != len(source) {
+		name = strings.Split(prefix, "/")
+	} else {
+		// Otherwise, the name is empty since its the root package and no
+		// prefix should be added to files.
+		prefix = ""
+	}
+
 	files := []string{}
 	for _, f := range p.GoFiles {
 		files = append(files, path.Join(prefix, f))
 	}
 
-	analysed := pkg{
-		Name:        strings.Split(prefix, "/"),
+	return pkg{
+		Name:        name,
 		Files:       files,
 		LocalDeps:   local,
 		ForeignDeps: foreign,
-	}
-
-	return analysed, nil
+	}, nil
 }
 
 func loadStdlibPkgs(from string) (pkgs map[string]bool, err error) {