1package 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) 12 ctx.RegisterParallelSingletonType("my_singleton", newDistFileSingleton) 13 ctx.RegisterParallelSingletonModuleType("my_singleton_module", newDistFileSingletonModule) 14 }), 15 FixtureModifyConfig(SetKatiEnabledForTests), 16 PrepareForTestWithMakevars, 17 ).RunTestWithBp(t, ` 18 my_module_type { 19 name: "foo", 20 } 21 my_singleton_module { 22 name: "bar" 23 } 24 `) 25 26 lateContents := string(result.SingletonForTests(t, "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 { 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) 42 } 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} 60 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} 97