Cole Faust | d62a489 | 2025-02-07 16:55:11 -0800 | [diff] [blame] | 1 | package android |
| 2 | |
| 3 | import ( |
| 4 | "regexp" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestDistFilesInGenerateAndroidBuildActions(t *testing.T) { |
| 9 | result := GroupFixturePreparers( |
| 10 | FixtureRegisterWithContext(func(ctx RegistrationContext) { |
| 11 | ctx.RegisterModuleType("my_module_type", newDistFileModule) |
| 12 | }), |
| 13 | FixtureModifyConfig(SetKatiEnabledForTests), |
| 14 | PrepareForTestWithMakevars, |
| 15 | ).RunTestWithBp(t, ` |
| 16 | my_module_type { |
| 17 | name: "foo", |
| 18 | } |
| 19 | `) |
| 20 | |
| 21 | lateContents := string(result.SingletonForTests("makevars").Singleton().(*makeVarsSingleton).lateForTesting) |
| 22 | matched, err := regexp.MatchString(`call dist-for-goals,my_goal,.*/my_file.txt:my_file.txt\)`, lateContents) |
| 23 | if err != nil || !matched { |
| 24 | t.Fatalf("Expected a dist, but got: %s", lateContents) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | type distFileModule struct { |
| 29 | ModuleBase |
| 30 | } |
| 31 | |
| 32 | func newDistFileModule() Module { |
| 33 | m := &distFileModule{} |
| 34 | InitAndroidModule(m) |
| 35 | return m |
| 36 | } |
| 37 | |
| 38 | func (m *distFileModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
| 39 | out := PathForModuleOut(ctx, "my_file.txt") |
| 40 | WriteFileRule(ctx, out, "Hello, world!") |
| 41 | ctx.DistForGoal("my_goal", out) |
| 42 | } |