blob: 5e4499fbbe99a77af4c1227292c1497756b5092e [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)
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
28type distFileModule struct {
29 ModuleBase
30}
31
32func newDistFileModule() Module {
33 m := &distFileModule{}
34 InitAndroidModule(m)
35 return m
36}
37
38func (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}