Skip to content

Commit

Permalink
fix(gazelle): override parent target glob config when specified (#2651)
Browse files Browse the repository at this point in the history
When a BUILD specifies a glob for a target (lib, test, or custom target)
the parent glob configuration for that target is overridden, not
extended. This aligns with Aspect-CLI <5.5

GitOrigin-RevId: a3726a1ccfa410a0727578fc3e599129571f345e
  • Loading branch information
jbedard authored and gregmagolan committed Jun 20, 2023
1 parent b077571 commit a9dce42
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 6 deletions.
13 changes: 9 additions & 4 deletions gazelle/js/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,16 @@ func newRootConfig() *JsGazelleConfig {
}
}

func (g *TargetGroup) copy() *TargetGroup {
func (g *TargetGroup) newChild() *TargetGroup {
sources := g.customSources
if len(sources) == 0 {
sources = g.defaultSources
}

return &TargetGroup{
name: g.name,
customSources: g.customSources[:],
defaultSources: g.defaultSources,
customSources: make([]string, 0),
defaultSources: sources,
testonly: g.testonly,
}
}
Expand All @@ -207,7 +212,7 @@ func (c *JsGazelleConfig) NewChild(childPath string) *JsGazelleConfig {
// Copy the targets, any modifications will be local.
cCopy.targets = make([]*TargetGroup, 0, len(c.targets))
for _, target := range c.targets {
cCopy.targets = append(cCopy.targets, target.copy())
cCopy.targets = append(cCopy.targets, target.newChild())
}

// Copy the overrides, any modifications will be local.
Expand Down
4 changes: 4 additions & 0 deletions gazelle/js/tests/simple_globs/mix/test-lib/BUILD.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Output everything as a standard lib, no test target

# Only contains a standard target, no tests
# gazelle:js_test_files there-are-no-tests
16 changes: 16 additions & 0 deletions gazelle/js/tests/simple_globs/mix/test-lib/BUILD.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

# Output everything as a standard lib, no test target

# Only contains a standard target, no tests
# gazelle:js_test_files there-are-no-tests

ts_project(
name = "test-lib",
srcs = [
"faker.ts",
"normally.mock.ts",
"normally.spec.ts",
"normally.test.ts",
],
)
Empty file.
Empty file.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion gazelle/js/tests/simple_globs/mix/tests_override/BUILD.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# gazelle:js_test_files **/*.test.ts
# gazelle:js_test_files **/*.{mock,spec,test}.ts
2 changes: 1 addition & 1 deletion gazelle/js/tests/simple_globs/mix/tests_override/BUILD.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

# gazelle:js_test_files **/*.test.ts
# gazelle:js_test_files **/*.{mock,spec,test}.ts

ts_project(
name = "tests_override",
Expand Down

0 comments on commit a9dce42

Please sign in to comment.