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) |
Cole Faust | f2aab5e | 2025-02-11 13:32:51 -0800 | [diff] [blame] | 12 | ctx.RegisterParallelSingletonType("my_singleton", newDistFileSingleton) |
| 13 | ctx.RegisterParallelSingletonModuleType("my_singleton_module", newDistFileSingletonModule) |
Cole Faust | d62a489 | 2025-02-07 16:55:11 -0800 | [diff] [blame] | 14 | }), |
| 15 | FixtureModifyConfig(SetKatiEnabledForTests), |
| 16 | PrepareForTestWithMakevars, |
| 17 | ).RunTestWithBp(t, ` |
| 18 | my_module_type { |
| 19 | name: "foo", |
| 20 | } |
Cole Faust | f2aab5e | 2025-02-11 13:32:51 -0800 | [diff] [blame] | 21 | my_singleton_module { |
| 22 | name: "bar" |
| 23 | } |
Cole Faust | d62a489 | 2025-02-07 16:55:11 -0800 | [diff] [blame] | 24 | `) |
| 25 | |
| 26 | lateContents := string(result.SingletonForTests("makevars").Singleton().(*makeVarsSingleton).lateForTesting) |
| 27 | matched, err := regexp.MatchString(`call dist-for-goals,my_goal,.*/my_file.txt:my_file.txt\)`, lateContents) |
| 28 | if err != nil || !matched { |
Cole Faust | f2aab5e | 2025-02-11 13:32:51 -0800 | [diff] [blame] | 29 | t.Fatalf("Expected a dist of my_file.txt, but got: %s", lateContents) |
| 30 | } |
| 31 | matched, err = regexp.MatchString(`call dist-for-goals,my_singleton_goal,.*/my_singleton_file.txt:my_singleton_file.txt\)`, lateContents) |
| 32 | if err != nil || !matched { |
| 33 | t.Fatalf("Expected a dist of my_singleton_file.txt, but got: %s", lateContents) |
| 34 | } |
| 35 | matched, err = regexp.MatchString(`call dist-for-goals,my_singleton_module_module_goal,.*/my_singleton_module_module_file.txt:my_singleton_module_module_file.txt\)`, lateContents) |
| 36 | if err != nil || !matched { |
| 37 | t.Fatalf("Expected a dist of my_singleton_module_module_file.txt, but got: %s", lateContents) |
| 38 | } |
| 39 | matched, err = regexp.MatchString(`call dist-for-goals,my_singleton_module_singleton_goal,.*/my_singleton_module_singleton_file.txt:my_singleton_module_singleton_file.txt\)`, lateContents) |
| 40 | if err != nil || !matched { |
| 41 | t.Fatalf("Expected a dist of my_singleton_module_singleton_file.txt, but got: %s", lateContents) |
Cole Faust | d62a489 | 2025-02-07 16:55:11 -0800 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
| 45 | type distFileModule struct { |
| 46 | ModuleBase |
| 47 | } |
| 48 | |
| 49 | func newDistFileModule() Module { |
| 50 | m := &distFileModule{} |
| 51 | InitAndroidModule(m) |
| 52 | return m |
| 53 | } |
| 54 | |
| 55 | func (m *distFileModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
| 56 | out := PathForModuleOut(ctx, "my_file.txt") |
| 57 | WriteFileRule(ctx, out, "Hello, world!") |
| 58 | ctx.DistForGoal("my_goal", out) |
| 59 | } |
Cole Faust | f2aab5e | 2025-02-11 13:32:51 -0800 | [diff] [blame] | 60 | |
| 61 | type distFileSingleton struct { |
| 62 | } |
| 63 | |
| 64 | func newDistFileSingleton() Singleton { |
| 65 | return &distFileSingleton{} |
| 66 | } |
| 67 | |
| 68 | func (d *distFileSingleton) GenerateBuildActions(ctx SingletonContext) { |
| 69 | out := PathForOutput(ctx, "my_singleton_file.txt") |
| 70 | WriteFileRule(ctx, out, "Hello, world!") |
| 71 | ctx.DistForGoal("my_singleton_goal", out) |
| 72 | } |
| 73 | |
| 74 | type distFileSingletonModule struct { |
| 75 | SingletonModuleBase |
| 76 | } |
| 77 | |
| 78 | func newDistFileSingletonModule() SingletonModule { |
| 79 | sm := &distFileSingletonModule{} |
| 80 | InitAndroidSingletonModule(sm) |
| 81 | return sm |
| 82 | } |
| 83 | |
| 84 | // GenerateAndroidBuildActions implements SingletonModule. |
| 85 | func (d *distFileSingletonModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
| 86 | out := PathForModuleOut(ctx, "my_singleton_module_module_file.txt") |
| 87 | WriteFileRule(ctx, out, "Hello, world!") |
| 88 | ctx.DistForGoal("my_singleton_module_module_goal", out) |
| 89 | } |
| 90 | |
| 91 | // GenerateSingletonBuildActions implements SingletonModule. |
| 92 | func (d *distFileSingletonModule) GenerateSingletonBuildActions(ctx SingletonContext) { |
| 93 | out := PathForOutput(ctx, "my_singleton_module_singleton_file.txt") |
| 94 | WriteFileRule(ctx, out, "Hello, world!") |
| 95 | ctx.DistForGoal("my_singleton_module_singleton_goal", out) |
| 96 | } |