Skip to content

Commit

Permalink
go/packages: move TypecheckCgo to packagesinternal
Browse files Browse the repository at this point in the history
Updates golang/go#16623.
Updates golang/go#39072.

Change-Id: I6612cdac14faa5ad724ceb805e1d6c823b4046ff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237423
Run-TryBot: Matthew Dempsky <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Heschi Kreinick <[email protected]>
  • Loading branch information
mdempsky committed Jun 10, 2020
1 parent 51e3d70 commit 2ee2e4c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go/packages/golist.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func (state *golistState) createDriverResponse(words ...string) (*driverResponse
Module: p.Module,
}

if (state.cfg.Mode&TypecheckCgo) != 0 && len(p.CgoFiles) != 0 {
if (state.cfg.Mode&typecheckCgo) != 0 && len(p.CgoFiles) != 0 {
if len(p.CompiledGoFiles) > len(p.GoFiles) {
// We need the cgo definitions, which are in the first
// CompiledGoFile after the non-cgo ones. This is a hack but there
Expand Down
9 changes: 5 additions & 4 deletions go/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ const (
// NeedTypesSizes adds TypesSizes.
NeedTypesSizes

// TypecheckCgo enables full support for type checking cgo. Requires Go 1.15+.
// typecheckCgo enables full support for type checking cgo. Requires Go 1.15+.
// Modifies CompiledGoFiles and Types, and has no effect on its own.
TypecheckCgo
typecheckCgo

// NeedModule adds Module.
NeedModule
Expand Down Expand Up @@ -361,6 +361,7 @@ func init() {
packagesinternal.SetGoCmdRunner = func(config interface{}, runner *gocommand.Runner) {
config.(*Config).gocmdRunner = runner
}
packagesinternal.TypecheckCgo = int(typecheckCgo)
}

// An Error describes a problem with a package's metadata, syntax, or types.
Expand Down Expand Up @@ -921,10 +922,10 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
Error: appendError,
Sizes: ld.sizes,
}
if (ld.Mode & TypecheckCgo) != 0 {
if (ld.Mode & typecheckCgo) != 0 {
if !typesinternal.SetUsesCgo(tc) {
appendError(Error{
Msg: "TypecheckCgo requires Go 1.15+",
Msg: "typecheckCgo requires Go 1.15+",
Kind: ListError,
})
return
Expand Down
2 changes: 1 addition & 1 deletion go/packages/packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2923,7 +2923,7 @@ func testTypecheckCgo(t *testing.T, exporter packagestest.Exporter) {

exported.Config.Mode = packages.NeedFiles | packages.NeedCompiledGoFiles |
packages.NeedSyntax | packages.NeedDeps | packages.NeedTypes |
packages.TypecheckCgo
packages.LoadMode(packagesinternal.TypecheckCgo)

initial, err := packages.Load(exported.Config, "golang.org/fake/cgo")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/cache/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func typeCheck(ctx context.Context, fset *token.FileSet, m *metadata, mode sourc
}),
}
// We want to type check cgo code if go/types supports it.
// We passed TypecheckCgo to go/packages when we Loaded.
// We passed typecheckCgo to go/packages when we Loaded.
typesinternal.SetUsesCgo(cfg)

check := types.NewChecker(cfg, fset, pkg.types, pkg.typesInfo)
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/cache/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (s *snapshot) Config(ctx context.Context) *packages.Config {
}
// We want to type check cgo code if go/types supports it.
if typesinternal.SetUsesCgo(&types.Config{}) {
cfg.Mode |= packages.TypecheckCgo
cfg.Mode |= packages.LoadMode(packagesinternal.TypecheckCgo)
}
packagesinternal.SetGoCmdRunner(cfg, s.view.gocmdRunner)

Expand Down
2 changes: 2 additions & 0 deletions internal/packagesinternal/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ var GetForTest = func(p interface{}) string { return "" }
var GetGoCmdRunner = func(config interface{}) *gocommand.Runner { return nil }

var SetGoCmdRunner = func(config interface{}, runner *gocommand.Runner) {}

var TypecheckCgo int

0 comments on commit 2ee2e4c

Please sign in to comment.