Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/gazelle/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@gazelle//:def.bzl", "gazelle")

# gazelle:prefix github.com/abcue/rules_cue/examples/gazelle
# gazelle:cue_gen_consolidated_instance

# Run this to update BUILD.bazel files:
# bazel run //:gazelle
Expand Down
24 changes: 14 additions & 10 deletions examples/gazelle/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions examples/gazelle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ You can customize Gazelle behavior using directives in BUILD.bazel files:
# Control output format for CUE exports (json, yaml, text, or cue)
# gazelle:cue_output_format yaml

# Generate cue_consolidated_instance rules (opt-in)
# gazelle:cue_gen_consolidated_instance

# Disable in a subdirectory
# gazelle:cue_gen_consolidated_instance false

# Generate cue_exported_instance rules
# gazelle:cue_gen_exported_instance

Expand Down
11 changes: 3 additions & 8 deletions examples/gazelle/services/api/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
load("@rules_cue//cue:cue.bzl", "cue_consolidated_instance", "cue_instance")
load("@rules_cue//cue:cue.bzl", "cue_instance")

# gazelle:cue_gen_consolidated_instance false

cue_instance(
name = "api_cue_instance",
Expand All @@ -10,10 +12,3 @@ cue_instance(
ancestor = "//cue.mod:cue.mod",
visibility = ["//visibility:public"],
)

cue_consolidated_instance(
name = "api_cue_def",
instance = ":api_cue_instance",
output_format = "cue",
visibility = ["//visibility:public"],
)
15 changes: 11 additions & 4 deletions gazelle/cue/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ type cueConfig struct {
cueTestGoldenFilename string

// cueGenExportedInstance controls whether to generate cue_exported_instance rules
// for each cue_instance. When true, a corresponding cue_exported_instance rule will be created.
// #gazelle:cue_exported_instance
// for each cue_instance. When not false, a corresponding cue_exported_instance rule will be created.
// #gazelle:cue_gen_exported_instance
cueGenExportedInstance bool

// cueGenConsolidatedInstance controls whether to generate cue_consolidated_instance rules
// for each cue_instance. When not false, a corresponding cue_consolidated_instance rule will be created.
// #gazelle:cue_gen_consolidated_instance
cueGenConsolidatedInstance bool

// cueOutputFormat specifies the output format for CUE exports.
// Valid values are "json", "yaml", and "text".
// Default is "json" if not specified.
Expand All @@ -45,7 +50,7 @@ type cueConfig struct {
// Configurer can interpret. Gazelle prints errors for directives that
// are not recognized by any Configurer.
func (s *cueLang) KnownDirectives() []string {
return []string{"prefix", "cue_test_golden_suffix", "cue_test_golden_filename", "cue_output_format", "cue_gen_exported_instance"}
return []string{"prefix", "cue_test_golden_suffix", "cue_test_golden_filename", "cue_output_format", "cue_gen_exported_instance", "cue_gen_consolidated_instance"}
}

// RegisterFlags registers command-line flags used by the
Expand Down Expand Up @@ -117,7 +122,9 @@ func (s *cueLang) Configure(c *config.Config, rel string, f *rule.File) {
conf.cueTestGoldenFilename = d.Value
conf.cueTestGoldenSuffix = strings.TrimPrefix(path.Ext(d.Value), ".")
case "cue_gen_exported_instance":
conf.cueGenExportedInstance = true
conf.cueGenExportedInstance = d.Value != "false"
case "cue_gen_consolidated_instance":
conf.cueGenConsolidatedInstance = d.Value != "false"
case "cue_output_format":
conf.cueOutputFormat = d.Value
}
Expand Down
2 changes: 1 addition & 1 deletion gazelle/cue/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (cl *cueLang) GenerateRules(args language.GenerateArgs) language.GenerateRe
consolidatedInstances: make(map[string]*cueConsolidatedInstance),
exportedGoldenFiles: make(map[string]*GoldenFile), // key: filename
cueTestRules: make(map[string]*cueTest),
genConsolidatedInstances: true,
genConsolidatedInstances: conf.cueGenConsolidatedInstance,
genExportedInstances: conf.cueGenExportedInstance,
}

Expand Down
Loading