blob: d98ca4fd4f10ca4666884ffa3dffb96c67ab95da [file] [log] [blame]
Colin Cross1f7f3bd2016-07-27 10:12:38 -07001// Copyright (C) 2016 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package art
16
17// This file implements the "codegen" property to apply different properties based on the currently
18// selected codegen arches, which defaults to all arches on the host and the primary and secondary
19// arches on the device.
20
21import (
22 "android/soong/android"
23 "sort"
24 "strings"
25)
26
Colin Cross6e511782016-09-13 13:41:03 -070027func codegen(ctx android.LoadHookContext, c *codegenProperties) {
Colin Cross1f7f3bd2016-07-27 10:12:38 -070028 var hostArches, deviceArches []string
29
30 e := envDefault(ctx, "ART_HOST_CODEGEN_ARCHS", "")
31 if e == "" {
32 hostArches = supportedArches
33 } else {
34 hostArches = strings.Split(e, " ")
35 }
36
37 e = envDefault(ctx, "ART_TARGET_CODEGEN_ARCHS", "")
38 if e == "" {
39 deviceArches = defaultDeviceCodegenArches(ctx)
40 } else {
41 deviceArches = strings.Split(e, " ")
42 }
43
44 type props struct {
45 Target struct {
46 Android *codegenArchProperties
47 Host *codegenArchProperties
48 }
49 }
50
51 addCodegenArchProperties := func(p *props, hod **codegenArchProperties, arch string) {
52 switch arch {
53 case "arm":
Colin Cross6e511782016-09-13 13:41:03 -070054 *hod = &c.Codegen.Arm
Colin Cross1f7f3bd2016-07-27 10:12:38 -070055 case "arm64":
Colin Cross6e511782016-09-13 13:41:03 -070056 *hod = &c.Codegen.Arm64
Colin Cross1f7f3bd2016-07-27 10:12:38 -070057 case "mips":
Colin Cross6e511782016-09-13 13:41:03 -070058 *hod = &c.Codegen.Mips
Colin Cross1f7f3bd2016-07-27 10:12:38 -070059 case "mips64":
Colin Cross6e511782016-09-13 13:41:03 -070060 *hod = &c.Codegen.Mips64
Colin Cross1f7f3bd2016-07-27 10:12:38 -070061 case "x86":
Colin Cross6e511782016-09-13 13:41:03 -070062 *hod = &c.Codegen.X86
Colin Cross1f7f3bd2016-07-27 10:12:38 -070063 case "x86_64":
Colin Cross6e511782016-09-13 13:41:03 -070064 *hod = &c.Codegen.X86_64
Colin Cross1f7f3bd2016-07-27 10:12:38 -070065 default:
66 ctx.ModuleErrorf("Unknown codegen architecture %q", arch)
67 return
68 }
69 ctx.AppendProperties(p)
70 }
71
72 for _, a := range deviceArches {
73 p := &props{}
74 addCodegenArchProperties(p, &p.Target.Android, a)
75 if ctx.Failed() {
76 return
77 }
78 }
79
80 for _, a := range hostArches {
81 p := &props{}
82 addCodegenArchProperties(p, &p.Target.Host, a)
83 if ctx.Failed() {
84 return
85 }
86 }
87}
88
89type codegenArchProperties struct {
90 Srcs []string
91 Cflags []string
92 Static struct {
93 Whole_static_libs []string
94 }
95 Shared struct {
96 Shared_libs []string
97 }
98}
99
100type codegenProperties struct {
101 Codegen struct {
102 Arm, Arm64, Mips, Mips64, X86, X86_64 codegenArchProperties
103 }
104}
105
106type codegenCustomizer struct {
107 codegenProperties codegenProperties
108}
109
Colin Cross6e511782016-09-13 13:41:03 -0700110func defaultDeviceCodegenArches(ctx android.LoadHookContext) []string {
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700111 arches := make(map[string]bool)
112 for _, a := range ctx.DeviceConfig().Arches() {
Nicolas Geoffraye52ac152016-09-09 15:48:19 +0100113 s := a.ArchType.String()
114 arches[s] = true
115 if s == "arm64" {
116 arches["arm"] = true
117 } else if s == "mips64" {
118 arches["mips"] = true
119 } else if s == "x86_64" {
120 arches["x86"] = true
121 }
Colin Cross1f7f3bd2016-07-27 10:12:38 -0700122 }
123 ret := make([]string, 0, len(arches))
124 for a := range arches {
125 ret = append(ret, a)
126 }
127 sort.Strings(ret)
128 return ret
129}