Skip to content

Can't unset an attr with GlobValue during merge #1989

@ashi009

Description

@ashi009

What version of gazelle are you using?

0.37.0

What version of rules_go are you using?

0.49.0

What version of Bazel are you using?

7.2.1

Does this issue reproduce with the latest releases of all the above?

Yes

What operating system and processor architecture are you using?

macOS 15.1 aarch64

What did you do?

I generated some empty rules to remove existing rules in BUILD files:

func cleanUndefinedRules(res *language.GenerateResult, f *rule.File) {
	for _, fr := range f.Rules {
		if ... {
				continue
		}
		r := rule.NewRule(fr.Kind(), fr.Name())
		res.Empty = append(res.Empty, r)
	}
}

The kind definition has:

		MergeableAttrs: map[string]bool{
			"srcs": true,
		}

and the current build file has:

some_rule(
	name = "test",
    srcs = glob([...]),
)

What did you expect to see?

the "test" target gets removed.

What did you see instead?

gazelle: BUILD.bazel:124.12-124.29: could not merge expression

and the target is untouched after the run.

This is because when merging the attrs, if the dst is not a scalar, it can't be removed.

if srcAttr == nil && (dst == nil || isScalar(dst)) {

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