blob: 387d4575914ea277f1236d5cde09480b99d10198 [file] [log] [blame]
Cole Faustd62a4892025-02-07 16:55:11 -08001package android
2
3import (
4 "regexp"
5 "testing"
6)
7
8func TestDistFilesInGenerateAndroidBuildActions(t *testing.T) {
9 result := GroupFixturePreparers(
10 FixtureRegisterWithContext(func(ctx RegistrationContext) {
11 ctx.RegisterModuleType("my_module_type", newDistFileModule)
Cole Faustf2aab5e2025-02-11 13:32:51 -080012 ctx.RegisterParallelSingletonType("my_singleton", newDistFileSingleton)
13 ctx.RegisterParallelSingletonModuleType("my_singleton_module", newDistFileSingletonModule)
Cole Faustd62a4892025-02-07 16:55:11 -080014 }),
15 FixtureModifyConfig(SetKatiEnabledForTests),
16 PrepareForTestWithMakevars,
17 ).RunTestWithBp(t, `
18 my_module_type {
19 name: "foo",
20 }
Cole Faustf2aab5e2025-02-11 13:32:51 -080021 my_singleton_module {
22 name: "bar"
23 }
Cole Faustd62a4892025-02-07 16:55:11 -080024 `)
25
Colin Cross90607e92025-02-11 14:58:07 -080026 lateContents := string(result.SingletonForTests(t, "makevars").Singleton().(*makeVarsSingleton).lateForTesting)
Cole Faustd62a4892025-02-07 16:55:11 -080027 matched, err := regexp.MatchString(`call dist-for-goals,my_goal,.*/my_file.txt:my_file.txt\)`, lateContents)
28 if err != nil || !matched {
Cole Faustf2aab5e2025-02-11 13:32:51 -080029 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 Faustd62a4892025-02-07 16:55:11 -080042 }
43}
44
45type distFileModule struct {
46 ModuleBase
47}
48
49func newDistFileModule() Module {
50 m := &distFileModule{}
51 InitAndroidModule(m)
52 return m
53}
54
55func (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 Faustf2aab5e2025-02-11 13:32:51 -080060
61type distFileSingleton struct {
62}
63
64func newDistFileSingleton() Singleton {
65 return &distFileSingleton{}
66}
67
68func (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
74type distFileSingletonModule struct {
75 SingletonModuleBase
76}
77
78func newDistFileSingletonModule() SingletonModule {
79 sm := &distFileSingletonModule{}
80 InitAndroidSingletonModule(sm)
81 return sm
82}
83
84// GenerateAndroidBuildActions implements SingletonModule.
85func (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.
92func (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}