Giter Site home page Giter Site logo

Comments (10)

mpassell avatar mpassell commented on May 30, 2024 1

As a workaround for this, I'm running buildozer delete '//vendor/...:%go_test' after running gazelle.

from bazel-gazelle.

ixdy avatar ixdy commented on May 30, 2024 1

That works. Also, if you're using dep, you can tell it to prune out test files.

from bazel-gazelle.

jayconrod avatar jayconrod commented on May 30, 2024 1

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.

AustinSchuh avatar AustinSchuh commented on May 30, 2024

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.

seh avatar seh commented on May 30, 2024

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.

jayconrod avatar jayconrod commented on May 30, 2024

@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.

seh avatar seh commented on May 30, 2024

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.

bogatuadrian avatar bogatuadrian commented on May 30, 2024

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.

ash2k avatar ash2k commented on May 30, 2024

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.

holycheater avatar holycheater commented on May 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.