Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ashi009 opened this issue Nov 28, 2024 · 1 comment · May be fixed by #1993
Open

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

ashi009 opened this issue Nov 28, 2024 · 1 comment · May be fixed by #1993

Comments

@ashi009
Copy link
Contributor

ashi009 commented Nov 28, 2024

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)) {

@ashi009
Copy link
Contributor Author

ashi009 commented Dec 10, 2024

I'm wondering if isScalar is required here. If I understand it correctly, the purpose for checking isScaler is to make sure there is no Merger applicable. However, Merger is designed for src to merge dst, and when src is nil, there is no way for it to do a custom merge.

I think it's safe to remove the isScaler check, and remove dst regardless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant