summaryrefslogtreecommitdiff
path: root/android/makevars_test.go
blob: 387d4575914ea277f1236d5cde09480b99d10198 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package android

import (
	"regexp"
	"testing"
)

func TestDistFilesInGenerateAndroidBuildActions(t *testing.T) {
	result := GroupFixturePreparers(
		FixtureRegisterWithContext(func(ctx RegistrationContext) {
			ctx.RegisterModuleType("my_module_type", newDistFileModule)
			ctx.RegisterParallelSingletonType("my_singleton", newDistFileSingleton)
			ctx.RegisterParallelSingletonModuleType("my_singleton_module", newDistFileSingletonModule)
		}),
		FixtureModifyConfig(SetKatiEnabledForTests),
		PrepareForTestWithMakevars,
	).RunTestWithBp(t, `
	my_module_type {
		name: "foo",
	}
	my_singleton_module {
		name: "bar"
	}
	`)

	lateContents := string(result.SingletonForTests(t, "makevars").Singleton().(*makeVarsSingleton).lateForTesting)
	matched, err := regexp.MatchString(`call dist-for-goals,my_goal,.*/my_file.txt:my_file.txt\)`, lateContents)
	if err != nil || !matched {
		t.Fatalf("Expected a dist of my_file.txt, but got: %s", lateContents)
	}
	matched, err = regexp.MatchString(`call dist-for-goals,my_singleton_goal,.*/my_singleton_file.txt:my_singleton_file.txt\)`, lateContents)
	if err != nil || !matched {
		t.Fatalf("Expected a dist of my_singleton_file.txt, but got: %s", lateContents)
	}
	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)
	if err != nil || !matched {
		t.Fatalf("Expected a dist of my_singleton_module_module_file.txt, but got: %s", lateContents)
	}
	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)
	if err != nil || !matched {
		t.Fatalf("Expected a dist of my_singleton_module_singleton_file.txt, but got: %s", lateContents)
	}
}

type distFileModule struct {
	ModuleBase
}

func newDistFileModule() Module {
	m := &distFileModule{}
	InitAndroidModule(m)
	return m
}

func (m *distFileModule) GenerateAndroidBuildActions(ctx ModuleContext) {
	out := PathForModuleOut(ctx, "my_file.txt")
	WriteFileRule(ctx, out, "Hello, world!")
	ctx.DistForGoal("my_goal", out)
}

type distFileSingleton struct {
}

func newDistFileSingleton() Singleton {
	return &distFileSingleton{}
}

func (d *distFileSingleton) GenerateBuildActions(ctx SingletonContext) {
	out := PathForOutput(ctx, "my_singleton_file.txt")
	WriteFileRule(ctx, out, "Hello, world!")
	ctx.DistForGoal("my_singleton_goal", out)
}

type distFileSingletonModule struct {
	SingletonModuleBase
}

func newDistFileSingletonModule() SingletonModule {
	sm := &distFileSingletonModule{}
	InitAndroidSingletonModule(sm)
	return sm
}

// GenerateAndroidBuildActions implements SingletonModule.
func (d *distFileSingletonModule) GenerateAndroidBuildActions(ctx ModuleContext) {
	out := PathForModuleOut(ctx, "my_singleton_module_module_file.txt")
	WriteFileRule(ctx, out, "Hello, world!")
	ctx.DistForGoal("my_singleton_module_module_goal", out)
}

// GenerateSingletonBuildActions implements SingletonModule.
func (d *distFileSingletonModule) GenerateSingletonBuildActions(ctx SingletonContext) {
	out := PathForOutput(ctx, "my_singleton_module_singleton_file.txt")
	WriteFileRule(ctx, out, "Hello, world!")
	ctx.DistForGoal("my_singleton_module_singleton_goal", out)
}