summaryrefslogtreecommitdiff
path: root/build/codegen.go
blob: fde94200394302f1573c6653f1178b3b7eef7a25 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package art

// This file implements the "codegen" property to apply different properties based on the currently
// selected codegen arches, which defaults to all arches on the host and the primary and secondary
// arches on the device.

import (
	"android/soong/android"
	"sort"
	"strings"
)

func (a *codegenCustomizer) CustomizeProperties(ctx android.CustomizePropertiesContext) {
	c := &a.codegenProperties.Codegen

	var hostArches, deviceArches []string

	e := envDefault(ctx, "ART_HOST_CODEGEN_ARCHS", "")
	if e == "" {
		hostArches = supportedArches
	} else {
		hostArches = strings.Split(e, " ")
	}

	e = envDefault(ctx, "ART_TARGET_CODEGEN_ARCHS", "")
	if e == "" {
		deviceArches = defaultDeviceCodegenArches(ctx)
	} else {
		deviceArches = strings.Split(e, " ")
	}

	type props struct {
		Target struct {
			Android *codegenArchProperties
			Host    *codegenArchProperties
		}
	}

	addCodegenArchProperties := func(p *props, hod **codegenArchProperties, arch string) {
		switch arch {
		case "arm":
			*hod = &c.Arm
		case "arm64":
			*hod = &c.Arm64
		case "mips":
			*hod = &c.Mips
		case "mips64":
			*hod = &c.Mips64
		case "x86":
			*hod = &c.X86
		case "x86_64":
			*hod = &c.X86_64
		default:
			ctx.ModuleErrorf("Unknown codegen architecture %q", arch)
			return
		}
		ctx.AppendProperties(p)
	}

	for _, a := range deviceArches {
		p := &props{}
		addCodegenArchProperties(p, &p.Target.Android, a)
		if ctx.Failed() {
			return
		}
	}

	for _, a := range hostArches {
		p := &props{}
		addCodegenArchProperties(p, &p.Target.Host, a)
		if ctx.Failed() {
			return
		}
	}
}

type codegenArchProperties struct {
	Srcs   []string
	Cflags []string
	Static struct {
		Whole_static_libs []string
	}
	Shared struct {
		Shared_libs []string
	}
}

type codegenProperties struct {
	Codegen struct {
		Arm, Arm64, Mips, Mips64, X86, X86_64 codegenArchProperties
	}
}

type codegenCustomizer struct {
	codegenProperties codegenProperties
}

func defaultDeviceCodegenArches(ctx android.CustomizePropertiesContext) []string {
	arches := make(map[string]bool)
	for _, a := range ctx.DeviceConfig().Arches() {
		s := a.ArchType.String()
		arches[s] = true
		if s == "arm64" {
			arches["arm"] = true
		} else if s == "mips64" {
			arches["mips"] = true
		} else if s == "x86_64" {
			arches["x86"] = true
		}
	}
	ret := make([]string, 0, len(arches))
	for a := range arches {
		ret = append(ret, a)
	}
	sort.Strings(ret)
	return ret
}