diff options
author | 2024-10-29 11:09:00 -0700 | |
---|---|---|
committer | 2024-10-29 11:12:22 -0700 | |
commit | 9820408a86c252fc8ea86772aefacc2b179a1034 (patch) | |
tree | 5d6f3f4908ef6e8de15c58b7eaa60b9a5e786ddb | |
parent | 0ba7034bf723aaf35db29811f6709aec5828b487 (diff) |
Add defaults for sh_ rules.
I was helping someone who wanted to use the same set of dependencies in
multiple sh_test rules and we realized that there are no defaults on
sh_test, sh_binary, etc. (see vts_ltp_test*)
Bug: 277261121 # Related to this bug
Change-Id: I81084771432e22e3de230511bdaba1b79a171406
Test: go test ./
-rw-r--r-- | sh/sh_binary.go | 20 | ||||
-rw-r--r-- | sh/sh_binary_test.go | 89 |
2 files changed, 109 insertions, 0 deletions
diff --git a/sh/sh_binary.go b/sh/sh_binary.go index 9c0db73ba..853f3d368 100644 --- a/sh/sh_binary.go +++ b/sh/sh_binary.go @@ -45,6 +45,7 @@ func registerShBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("sh_binary_host", ShBinaryHostFactory) ctx.RegisterModuleType("sh_test", ShTestFactory) ctx.RegisterModuleType("sh_test_host", ShTestHostFactory) + ctx.RegisterModuleType("sh_defaults", ShDefaultsFactory) } // Test fixture preparer that will register most sh build components. @@ -167,6 +168,7 @@ type TestProperties struct { type ShBinary struct { android.ModuleBase + android.DefaultableModuleBase properties shBinaryProperties @@ -548,6 +550,7 @@ func ShBinaryFactory() android.Module { module := &ShBinary{} initShBinaryModule(module) android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst) + android.InitDefaultableModule(module) return module } @@ -557,6 +560,7 @@ func ShBinaryHostFactory() android.Module { module := &ShBinary{} initShBinaryModule(module) android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst) + android.InitDefaultableModule(module) return module } @@ -567,6 +571,7 @@ func ShTestFactory() android.Module { module.AddProperties(&module.testProperties) android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst) + android.InitDefaultableModule(module) return module } @@ -581,6 +586,21 @@ func ShTestHostFactory() android.Module { } android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst) + android.InitDefaultableModule(module) + return module +} + +type ShDefaults struct { + android.ModuleBase + android.DefaultsModuleBase +} + +func ShDefaultsFactory() android.Module { + module := &ShDefaults{} + + module.AddProperties(&shBinaryProperties{}, &TestProperties{}) + android.InitDefaultsModule(module) + return module } diff --git a/sh/sh_binary_test.go b/sh/sh_binary_test.go index 37450b0e2..5a5043946 100644 --- a/sh/sh_binary_test.go +++ b/sh/sh_binary_test.go @@ -294,3 +294,92 @@ func TestShTestHost_javaData(t *testing.T) { actualData := entries.EntryMap["LOCAL_TEST_DATA"] android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData) } + +func TestDefaultsForTests(t *testing.T) { + ctx, config := testShBinary(t, ` + sh_defaults { + name: "defaults", + src: "test.sh", + filename: "test.sh", + data: [ + "testdata/data1", + "testdata/sub/data2", + ], + } + sh_test_host { + name: "foo", + defaults: ["defaults"], + data: [ + "testdata/more_data", + ], + java_data: [ + "javalib", + ], + } + + java_library_host { + name: "javalib", + srcs: [], + } + + sh_test { + name: "sh-test", + defaults: ["defaults"], + } + + `) + buildOS := ctx.Config().BuildOS.String() + mod := ctx.ModuleForTests("foo", buildOS+"_x86_64").Module().(*ShTest) + if !mod.Host() { + t.Errorf("host bit is not set for a sh_test_host module.") + } + expectedData := []string{ + ":testdata/data1", + ":testdata/sub/data2", + ":testdata/more_data", + "out/soong/.intermediates/javalib/" + buildOS + "_common/combined/:javalib.jar", + } + + entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] + actualData := entries.EntryMap["LOCAL_TEST_DATA"] + android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData) + + // Just the defaults + expectedData = []string{ + ":testdata/data1", + ":testdata/sub/data2", + } + mod = ctx.ModuleForTests("sh-test", "android_arm64_armv8-a").Module().(*ShTest) + entries = android.AndroidMkEntriesForTest(t, ctx, mod)[0] + actualData = entries.EntryMap["LOCAL_TEST_DATA"] + android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData) +} + +func TestDefaultsForBinaries(t *testing.T) { + ctx, _ := testShBinary(t, ` + sh_defaults { + name: "defaults", + src: "test.sh", + filename: "test.sh", + } + sh_binary_host { + name: "the-host-binary", + defaults: ["defaults"], + } + sh_binary{ + name: "the-binary", + defaults: ["defaults"], + } + `) + buildOS := ctx.Config().BuildOS.String() + mod := ctx.ModuleForTests("the-host-binary", buildOS+"_x86_64").Module().(*ShBinary) + if !mod.Host() { + t.Errorf("host bit is not set for a sh_binary_host module.") + } + + expectedFilename := "test.sh" + android.AssertStringEquals(t, "Filename", expectedFilename, *mod.properties.Filename) + + mod = ctx.ModuleForTests("the-binary", "android_arm64_armv8-a").Module().(*ShBinary) + android.AssertStringEquals(t, "Filename", expectedFilename, *mod.properties.Filename) +} |