Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
efritz committed Jun 8, 2022
1 parent fac2c5e commit 85c5d5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cmd/go-mockgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func mainErr() error {
}
}

log.Printf("loading data for %d packages\n", len(importPaths))

pkgs, err := packages.Load(&packages.Config{Mode: packages.NeedName | packages.NeedImports | packages.NeedSyntax | packages.NeedTypes}, importPaths...)
if err != nil {
return fmt.Errorf("could not load packages %s (%s)", strings.Join(importPaths, ","), err.Error())
Expand Down
13 changes: 9 additions & 4 deletions internal/mockgen/types/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ func Extract(pkgs []*packages.Package, packageOptions []PackageOptions) (ifaces
return nil, fmt.Errorf("failed to get working directory (%s)", err.Error())
}

var importPaths []string
for _, packageOpts := range packageOptions {
packageTypes, err := gatherAllPackageTypes(pkgs, workingDirectory, packageOpts.ImportPaths)
if err != nil {
return nil, err
}
importPaths = append(importPaths, packageOpts.ImportPaths...)
}

packageTypes, err := gatherAllPackageTypes(pkgs, workingDirectory, importPaths)
if err != nil {
return nil, err
}

for _, packageOpts := range packageOptions {
for _, name := range gatherAllPackageTypeNames(packageTypes) {
iface, err := extractInterface(packageTypes, name, packageOpts.Interfaces, packageOpts.Exclude)
if err != nil {
Expand Down

0 comments on commit 85c5d5b

Please sign in to comment.