Skip to content

gopackagesdriver returns incorrect response for files with cgo dependencies #356

Description

@hartblanc

When calling the gopacakgesdriver on a file which has cgo dependencies the response is:

  1. Missing the generated _cgo_gotypes.go files which contain the types in the CompiledFiles and its imports are missing in the Imports.
  2. Contains the generated *.cgo1.go files in both the GoFiles and CompiledFiles, when they should only be in the CompiledFiles.
  3. is missing the original go source files in the GoFiles.

The 1st item leads to issues where the imports that the ExportFile expects are not present in the Imports of the package. This causes errors like the following to be surfaced when running tools via gopackagesdriver.

testifylint: golang.org/x/tools/go/packages: unexpected new packages during load of github.com/confluentinc/confluent-kafka-go/v2/kafka
panic: golang.org/x/tools/go/packages: unexpected new packages during load of github.com/confluentinc/confluent-kafka-go/v2/kafka

goroutine 431 [running]:
log.Panicf({0x9358cb?, 0x33?}, {0x1ce2f277c20?, 0x8?, 0x1ce2eef2880?})
        log/log.go:460 +0x74
golang.org/x/tools/go/packages.(*loader).loadFromExportData(0x1ce2efd6180, 0x1ce2f816340)
        pkg/linux_amd64/golang.org/x/tools/go/packages/packages.go:1553 +0x63e
golang.org/x/tools/go/packages.(*loader).loadPackage(0x1ce2efd6180, 0x1ce2f816340)
        pkg/linux_amd64/golang.org/x/tools/go/packages/packages.go:1079 +0x645
golang.org/x/tools/go/packages.(*loader).refine.func2.1()
        pkg/linux_amd64/golang.org/x/tools/go/packages/packages.go:945 +0x2d
golang.org/x/sync/errgroup.(*Group).Go.func1()
        pkg/linux_amd64/golang.org/x/sync/errgroup/errgroup.go:93 +0x50
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 430
        pkg/linux_amd64/golang.org/x/sync/errgroup/errgroup.go:78 +0x95

I have a fix for all these issues on my fork.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions