Giter Site home page Giter Site logo

Comments (10)

dancompton avatar dancompton commented on May 29, 2024

@jayconrod Does this still apply? I'm currently attempting to rewrite the AST of many jsonnet manifests using a mix of tooling from go-jsonnet and now-defunct k8s.
The tests break when combined into one and it's impossible to construct proper tests using a single jsonnet file. I'm seeing this:

gazelle: /home/dc/work/src/github.com/zenreach/service-manifests/tools/refactor/query/BUILD.bazel: unknown directive: gazelle:skiprule

PS: if you have any tips on mass-refactoring jsonnet code that is are miserable, please include them in your response.

from bazel-gazelle.

jayconrod avatar jayconrod commented on May 29, 2024

This directive hasn't been implemented. Is this a go_test that ends up broken or something else?

Sorry I don't know enough about jsonnet to advise. Good luck though.

from bazel-gazelle.

dancompton avatar dancompton commented on May 29, 2024

Consider yourself lucky. Perhaps cel-spec could make a fine replacement? Will that be supported in rules_go?

from bazel-gazelle.

jayconrod avatar jayconrod commented on May 29, 2024

rules_go just supports Go and proto. I avoid adding support for too many other tools, since it adds dependencies for users.

I'm sure CEL rules could be written for Bazel, but I'm not sure if anyone is already planning to do so.

from bazel-gazelle.

dragonsinth avatar dragonsinth commented on May 29, 2024

@jayconrod did anything like this ever land? This would be SUPER useful in go_repository rules. I have a number of third party deps whose tests "fan out" into problematic deps; if I could write things like:

        build_directives = ["gazelle:exclude testing", "gazelle:skiprule go_default_test"],

I could prune a bunch of things out of our build tree.

from bazel-gazelle.

dragonsinth avatar dragonsinth commented on May 29, 2024

^^ btw I have a working patch for this if there is interest!

from bazel-gazelle.

jayconrod avatar jayconrod commented on May 29, 2024

@dragonsinth No this is still open. Feel free to send a patch. I changed the directive name in the first comment from skiprule to skip.

For the example you gave, # gazelle:skip would only skip generating a particular target, not all targets with a matching name. So I wonder if this might work better:

build_directives = ["gazelle:exclude **_test.go"],

#37 is a related issue: probably would be good to disable generation of all test targets in go_repository.

from bazel-gazelle.

dragonsinth avatar dragonsinth commented on May 29, 2024

@dragonsinth No this is still open. Feel free to send a patch. I changed the directive name in the first comment from skiprule to skip.

For the example you gave, # gazelle:skip would only skip generating a particular target, not all targets with a matching name. So I wonder if this might work better:

build_directives = ["gazelle:exclude **_test.go"],

Ah, that actually works just fine! Or rather in our particular case:

        build_directives = ["gazelle:exclude testing", "gazelle:exclude **/**_test.go"],

I didn't realize exclude would work on the file level!

So this solves my problem, and would allow me to unfork our skiprule implementation. But if you want a skip feature, happy to push you a PR. (It doesn't have test coverage, tho.)

from bazel-gazelle.

dragonsinth avatar dragonsinth commented on May 29, 2024

Actually the patch I used is pretty small... just gonna drop it here:

diff --git a/language/go/config.go b/language/go/config.go
index 98126b141c..ee425a39be 100644
--- a/language/go/config.go
+++ b/language/go/config.go
@@ -115,6 +115,9 @@ type goConfig struct {
 	// attribute.
 	repoNamingConvention map[string]namingConvention
 
+	// A list of rule names to skip generating rules for.
+	skipRule map[string]bool
+
 	// submodules is a list of modules which have the current module's path
 	// as a prefix of their own path. This affects visibility attributes
 	// in internal packages.
@@ -335,6 +338,7 @@ func (*goLang) KnownDirectives() []string {
 		"go_visibility",
 		"importmap_prefix",
 		"prefix",
+		"skiprule",
 	}
 }
 
@@ -570,6 +574,13 @@ Update io_bazel_rules_go to a newer version in your WORKSPACE file.`
 
 			case "prefix":
 				setPrefix(d.Value)
+
+			case "skiprule":
+				list := splitValue(d.Value)
+				gc.skipRule = map[string]bool{}
+				for _, e := range list {
+					gc.skipRule[e] = true
+				}
 			}
 		}
 
diff --git a/language/go/generate.go b/language/go/generate.go
index 2892948d38..7812878230 100644
--- a/language/go/generate.go
+++ b/language/go/generate.go
@@ -278,7 +278,11 @@ func (gl *goLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
 			g.generateTest(pkg, libName))
 	}
 
+	gc := getGoConfig(c)
 	for _, r := range rules {
+		if gc.skipRule[r.Name()] {
+			continue
+		}
 		if r.IsEmpty(goKinds[r.Kind()]) {
 			res.Empty = append(res.Empty, r)
 		} else {

from bazel-gazelle.

GabrielGhe avatar GabrielGhe commented on May 29, 2024

Is there a directive that we can use to skip a whole directory?

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.