Comments (10)
As a workaround for this, I'm running buildozer delete '//vendor/...:%go_test'
after running gazelle.
from bazel-gazelle.
That works. Also, if you're using dep
, you can tell it to prune out test files.
from bazel-gazelle.
Ah, sorry for the trouble. It will be a little simpler in the next version. Since #603, you're able to add directives to the root build file of a go_repository
with build_directives
. So figuring out the equivalent command-line arguments won't be necessary in most cases.
from bazel-gazelle.
This works today with
# gazelle:exclude foo_test.go
# gazelle:exclude bar_test.go
...
It would be nice if *_test.go
worked, but it's functional as is.
from bazel-gazelle.
Is it possible to exclude a path in an external dependency?
My project depends on kubernetes-sigs/controller-runtime, which has test files pkg/webhook/conversion/testdata/main.go and pkg/webhook/conversion/conversion_test.go that import several packages that don't exist.
Whenever I run bazel build, it prints the following warnings:
DEBUG: /private/var/tmp/_bazel_seh/5f212e1971286a055146b31916a9b621/external/bazel_gazelle/internal/go_repository.bzl:184:13: gazelle:
gazelle: finding module path for import testdata.kb.io/api/v1: exit status 1: can't load package: package testdata.kb.io/api/v1: unknown import path "testdata.kb.io/api/v1": cannot find module providing package testdata.kb.io/api/v1
gazelle: finding module path for import testdata.kb.io/api/v2: exit status 1: can't load package: package testdata.kb.io/api/v2: unknown import path "testdata.kb.io/api/v2": cannot find module providing package testdata.kb.io/api/v2
gazelle: finding module path for import testdata.kb.io/api/v3: exit status 1: can't load package: package testdata.kb.io/api/v3: unknown import path "testdata.kb.io/api/v3": cannot find module providing package testdata.kb.io/api/v3
I've tried various paths with gazelle:exclude
to try to trap those files, but none of the directives I've tried so far make any difference.
Here are a few of the unsuccessful attempts:
# gazelle:exclude sigs.k8s.io/[email protected]/pkg/webhook/conversion/testdata/main.go
# gazelle:exclude external/io_k8s_sigs_controller_runtime/pkg/webhook/conversion/testdata/main.go
# gazelle:exclude main.go
# gazelle:exclude sigs.k8s.io/[email protected]/pkg/webhook/conversion/conversion_test.go
# gazelle:exclude external/io_k8s_sigs_controller_runtime/pkg/webhook/conversion/conversion_test.go
# gazelle:exclude conversion_test.go
from bazel-gazelle.
@seh # gazelle:exclude pkg/webhook/conversion/testdata
would probably work. That should prevent Gazelle from visiting that directory. But since this is in a go_repository
rule, you should probably add build_extra_args = ["-exclude=pkg/webhook/conversion/testdata"]
to the go_repository
rule instead.
from bazel-gazelle.
Adding the build_extra_args
parameter as you suggested worked! There ends a dogged pursuit that I confess must have consumed about four hours of my life. Thank you so much.
from bazel-gazelle.
In some situations, it may be desirable to ignore tests in dependencies (both in vendor directories and in external repositories). Test rules may introduce additional dependencies and slow down the build.
#603 doesn't seem to directly address that.
I'm running bazel test
with GOPROXY=off
(also having GO_REPOSITORY_USE_HOST_CACHE=1
) with go modules and I get tens of errors like
gazelle: finding module path for import <package>: exit status 1: can't load package: package <package>: unknown import path "<package>": cannot find module providing package <package>
It seems that gazelle tries to go list
packages that are not in my local modules cache (because go modules doesn't cache tests of dependencies) and I get this error.
If I understand correctly I have to manually exclude the test files of my dependencies, but that doesn't scale, having potentially hundreds of files that need to be excluded.
Although I think this is related with this feature request, I can create a separate issue if you'd like.
from bazel-gazelle.
I'm using update-repos
to import external dependencies from go.mod
into a macro. It works great, thank you for it! I came to make a suggestion and found this issue.
Would be good to be able to tell generated go_repository
invocations to not create go_test
targets for all the reasons stated in the comments above. It might make sense to make it the default behavior as most projects likely don't need those targets.
from bazel-gazelle.
just in case someone hit the same problem:
gazelle:exclude some_dir/**/*_test.go
seems to do the trick of excluding test files from being generated into BUILD files
from bazel-gazelle.
Related Issues (20)
- FR: Gazelle should import direct dependencies directly without requiring buildozer HOT 4
- concurrent map read and map write HOT 3
- Use host module cache without build cache
- go_repository does not support fallback configured via GOPROXY environment variable HOT 1
- cahed bazel_gazelle_go_repository_tools does not rebuild when OS architecture changes HOT 3
- Transitive Go dependencies not included when using `go_deps.from_file` HOT 3
- Any way to conditionally apply module_overrides? HOT 6
- Gazelle gets confused if directories already contain both BUILD and .pb.go files
- Gazelle extremely slow with MODULE.bazel and kubernetes
- Tables in the documentation are difficult to read HOT 2
- Expose bazel_deps to go_deps extension HOT 1
- new gazelle v0.36.0 fails with Go sum mismatches HOT 10
- go.mod FilePath ReplaceDirective is missing when using the go-deps bzlmod extension HOT 1
- gazelle_binary fails nogo linting
- 'invalid use of internal package' in IDE in external tests HOT 4
- Failing to upgrade to gazelle 0.36 HOT 1
- Gazelle ignores several GIT_CONFIG environment variables
- Gazelle fails on macOS when using `apple_support` and go version 1.22+ HOT 7
- Cyclical Indirect Dependencies & Go.work can cause divergence HOT 1
- Add support for generated files in gazelle HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bazel-gazelle.