diff options
author | Vincent Ambo <tazjin@google.com> | 2019-12-12T17·04+0000 |
---|---|---|
committer | Vincent Ambo <mail@tazj.in> | 2019-12-13T00·39+0000 |
commit | 1fd80fb20175c28bc500e6d889594d1a5ebb6be7 (patch) | |
tree | 721ca54db5a9aa48253acfb829aca0eeb6d50d84 | |
parent | b20e46d60b14d5e367e52ec14989dc27b4829774 (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).
-rw-r--r-- | external/main.go | 18 |
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) { |