Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

x/tools/go/packages: Load(config, "./...") has odd behavior with build tags #75174

Open
Labels
BugReportIssues describing a possible bug in the Go implementation. NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolsThis label describes issues relating to any tools in the x/tools repository.
Milestone
@kalverra

Description

Go version

go version go1.25.0 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/adamhamrick/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/adamhamrick/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/2l/06jbymcj3mn7yp510wxm_jq40000gn/T/go-build4290062372=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/adamhamrick/Projects/branch-out/golang/example_project/go.mod'
GOMODCACHE='/Users/adamhamrick/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/adamhamrick/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.25.0/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/Users/adamhamrick/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.25.0/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.25.0'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

I'm writing a simple program to discover and load basic information about all packages in a Go project. This code normally works fine.

func loadPackagesFromModule(moduleDir string) {
 	config := &packages.Config{
		Mode: packages.NeedName | packages.NeedModule | packages.NeedFiles,
		Dir: moduleDir,
		Tests: true,
	}
	pkgs, err := packages.Load(config, "./...")
	if err != nil {
		return nil, fmt.Errorf("failed to load packages from module %s: %w", moduleDir, err)
	}
}

What did you see happen?

I'm dealing with a project that has build tags in many of their files. When I run the above code on this project:

.
├── go.mod
├── go.sum
├── main.go * Has build tag
├── package1
│ └── other1.go * Has build tag
│ └── other1_test.go * Has build tag
├── package2
│ └── other2.go * Has build tag
│ └── other2_test.go * Has build tag
├── base.go * Has build tag
├── base_test.go * Has build tag

the code returns only the main package and its files in IgnoredFiles.

What did you expect to see?

I can get it to properly Load all packages if I provide BuildFlags: []string{"-tags", "build_flag"}, but I thought the whole point of IgnoredFiles was to find files and packages that might have been ignored thanks to build tags. I wouldn't expect only the main package to be loaded in IgnoredFiles and all the rest to never be touched.

Is this a bug? Or am I misunderstanding how this is intended to work? Is there any way to fully Load all packages, agnostic of build tags?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation. NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /