From a9dce42d2520232967e9455b0cdcb1bea3535826 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Mon, 19 Jun 2023 19:23:45 -0400 Subject: [PATCH] fix(gazelle): override parent target glob config when specified (#2651) 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 --- gazelle/js/config.go | 13 +++++++++---- .../js/tests/simple_globs/mix/test-lib/BUILD.in | 4 ++++ .../js/tests/simple_globs/mix/test-lib/BUILD.out | 16 ++++++++++++++++ .../js/tests/simple_globs/mix/test-lib/faker.ts | 0 .../simple_globs/mix/test-lib/normally.mock.ts | 0 .../simple_globs/mix/test-lib/normally.spec.ts | 0 .../simple_globs/mix/test-lib/normally.test.ts | 0 .../simple_globs/mix/tests_override/BUILD.in | 2 +- .../simple_globs/mix/tests_override/BUILD.out | 2 +- 9 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 gazelle/js/tests/simple_globs/mix/test-lib/BUILD.in create mode 100644 gazelle/js/tests/simple_globs/mix/test-lib/BUILD.out create mode 100644 gazelle/js/tests/simple_globs/mix/test-lib/faker.ts create mode 100644 gazelle/js/tests/simple_globs/mix/test-lib/normally.mock.ts create mode 100644 gazelle/js/tests/simple_globs/mix/test-lib/normally.spec.ts create mode 100644 gazelle/js/tests/simple_globs/mix/test-lib/normally.test.ts diff --git a/gazelle/js/config.go b/gazelle/js/config.go index a50c5ccd1..032158a52 100644 --- a/gazelle/js/config.go +++ b/gazelle/js/config.go @@ -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, } } @@ -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. diff --git a/gazelle/js/tests/simple_globs/mix/test-lib/BUILD.in b/gazelle/js/tests/simple_globs/mix/test-lib/BUILD.in new file mode 100644 index 000000000..58921bb68 --- /dev/null +++ b/gazelle/js/tests/simple_globs/mix/test-lib/BUILD.in @@ -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 diff --git a/gazelle/js/tests/simple_globs/mix/test-lib/BUILD.out b/gazelle/js/tests/simple_globs/mix/test-lib/BUILD.out new file mode 100644 index 000000000..e56c1300c --- /dev/null +++ b/gazelle/js/tests/simple_globs/mix/test-lib/BUILD.out @@ -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", + ], +) diff --git a/gazelle/js/tests/simple_globs/mix/test-lib/faker.ts b/gazelle/js/tests/simple_globs/mix/test-lib/faker.ts new file mode 100644 index 000000000..e69de29bb diff --git a/gazelle/js/tests/simple_globs/mix/test-lib/normally.mock.ts b/gazelle/js/tests/simple_globs/mix/test-lib/normally.mock.ts new file mode 100644 index 000000000..e69de29bb diff --git a/gazelle/js/tests/simple_globs/mix/test-lib/normally.spec.ts b/gazelle/js/tests/simple_globs/mix/test-lib/normally.spec.ts new file mode 100644 index 000000000..e69de29bb diff --git a/gazelle/js/tests/simple_globs/mix/test-lib/normally.test.ts b/gazelle/js/tests/simple_globs/mix/test-lib/normally.test.ts new file mode 100644 index 000000000..e69de29bb diff --git a/gazelle/js/tests/simple_globs/mix/tests_override/BUILD.in b/gazelle/js/tests/simple_globs/mix/tests_override/BUILD.in index ee0231105..ada14ee30 100644 --- a/gazelle/js/tests/simple_globs/mix/tests_override/BUILD.in +++ b/gazelle/js/tests/simple_globs/mix/tests_override/BUILD.in @@ -1 +1 @@ -# gazelle:js_test_files **/*.test.ts +# gazelle:js_test_files **/*.{mock,spec,test}.ts diff --git a/gazelle/js/tests/simple_globs/mix/tests_override/BUILD.out b/gazelle/js/tests/simple_globs/mix/tests_override/BUILD.out index e72877638..86ad5f88a 100644 --- a/gazelle/js/tests/simple_globs/mix/tests_override/BUILD.out +++ b/gazelle/js/tests/simple_globs/mix/tests_override/BUILD.out @@ -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",