Skip to content

It seems like --build-tags might not be behaving as expected #2562

@zounm

Description

@zounm

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).
  • Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)

Description of the problem

Hello.
It seems like --build-tags is not being (fully) effective. Only one of the two involved files should be considered.
Please see the full output in teh output box. I'm having

debug.go:7:6: `Assert` redeclared in this block (typecheck)                     
func Assert(cond bool, format string, args ...interface{}) {                    
     ^                                                                          
release.go:5:6: other declaration of Assert (typecheck)                         
func Assert(cond bool, format string, args ...interface{}) {                    
     ^                                                        

And disabling typecheck (not shown in output) does nothing (I've read elsewhere that it cannot be disabled for not being an actual (standalone) linter). In case I'm being mistaken and this is not a bug, could you please shed some light on any trick to work around the issue? Thanks for your time already.

Version of golangci-lint

Details
$ golangci-lint --version
# golangci-lint has version 1.44.0 built from 617470fa on 2022-01-25T11:31:17Z

Configuration file

Details
$ cat .golangci.yml
# N/A (not using one)

Go environment

Details
$ go version && go env
go version go1.16.13 linux/amd64
GO111MODULE=""                                                                     
GOARCH="amd64"                                                                     
GOBIN=""                                                                        
GOCACHE="/home/EDITED_NAME/.cache/go-build"                                     
GOENV="/home/EDITED_NAME/.config/go/env"                                        
GOEXE=""                                                                        
GOFLAGS=""                                                                      
GOHOSTARCH="amd64"                                                              
GOHOSTOS="linux"                                                                
GOINSECURE=""                                                                   
GOMODCACHE="/home/EDITED_NAME/go/pkg/mod"                                       
GONOPROXY=""                                                                    
GONOSUMDB=""                                                                    
GOOS="linux"                                                                    
GOPATH="/home/EDITED_NAME/go"                                                   
GOPRIVATE=""                                                                    
GOPROXY="direct"                                                                
GOROOT="/usr/lib/golang"                                                        
GOSUMDB="off"                                                                   
GOTMPDIR=""                                                                     
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"                                
GOVCS=""                                                                        
GOVERSION="go1.16.13"                                                           
GCCGO="gccgo"                                                                   
AR="ar"                                                                         
CC="gcc"                                                                        
CXX="g++"                                                                       
CGO_ENABLED="1"                                                                 
GOMOD="/tmp/golangci-lint/go.mod"                                               
CGO_CFLAGS="-g -O2"                                                             
CGO_CPPFLAGS=""                                                                 
CGO_CXXFLAGS="-g -O2"                                                           
CGO_FFLAGS="-g -O2"                                                             
CGO_LDFLAGS="-g -O2"                                                            
PKG_CONFIG="pkg-config"                                                         
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2626199701=/tmp/go-build -gno-record-gcc-switches"

Verbose output of running

Details
$ golangci-lint cache clean
$ golangci-lint run --verbose --build-tags=debug release.go debug.go

golangci-lint run --verbose --build-tags=debug release.go debug.go  
level=info msg="[config_reader] Config search paths: [ EDITED_AWAY]"            
level=info msg="[lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]"
level=info msg="[loader] Using build tags: [debug]"                             
level=info msg="[loader] Go packages loading at mode 575 (deps|files|types_sizes|compiled_files|exports_file|imports|name) took 117.699075ms"
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 174.489µs"
level=info msg="[linters context/goanalysis] analyzers took 2.049373ms with top 10 stages: stringintconv: 357.579µs, buildir: 289.038µs, fact_deprecated: 241.835µs, inspect: 49.431µs, S1006: 23.534µs, SA4019: 20.449µs, lostcancel: 17.971
level=info msg="[runner] Issues before processing: 326, after processing: 2"    
level=info msg="[runner] Processors filtering stat (out/in): exclude: 326/326, severity-rules: 2/2, filename_unadjuster: 326/326, path_prettifier: 326/326, skip_dirs: 326/326, nolint: 326/326, diff: 2/2, max_same_issues: 2/2, path_prefix
level=info msg="[runner] processing took 9.156654ms with stages: exclude-rules: 4.600171ms, identifier_marker: 3.894568ms, path_prettifier: 307.553µs, nolint: 199.143µs, skip_dirs: 37.065µs, source_code: 32.698µs, cgo: 25.892µs, uniq_by_
level=info msg="[runner] linters took 65.386848ms with stages: goanalysis_metalinter: 56.099125ms"
debug.go:7:6: `Assert` redeclared in this block (typecheck)                     
func Assert(cond bool, format string, args ...interface{}) {                    
     ^                                                                          
release.go:5:6: other declaration of Assert (typecheck)                         
func Assert(cond bool, format string, args ...interface{}) {                    
     ^                                                                          
...

Code example or link to a public repository

Details

debug.go

// +build debug                                                                                                         
                                                                                                                        
package thing                                                                                                           
                                                                                                                        
import "fmt"                                                                                                            
                                                                                                                        
func Assert(cond bool, format string, args ...interface{}) {                                                            
    if cond {                                                                                                           
        return                                                                                                          
    }                                                                                                                   
    panic(fmt.Sprintf("Assertion failed! "+format, args...))                                                            
}

release.go

// +build !debug                                                                                                        
                                                                                                                        
package codec                                                                                                           
                                                                                                                        
func Assert(cond bool, format string, args ...interface{}) {                                                            
}

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