Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package 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 | |
| 21 | import ( |
| 22 | "android/soong/android" |
| 23 | "sort" |
| 24 | "strings" |
| 25 | ) |
| 26 | |
| 27 | func (a *codegenCustomizer) CustomizeProperties(ctx android.CustomizePropertiesContext) { |
| 28 | c := &a.codegenProperties.Codegen |
| 29 | |
| 30 | var hostArches, deviceArches []string |
| 31 | |
| 32 | e := envDefault(ctx, "ART_HOST_CODEGEN_ARCHS", "") |
| 33 | if e == "" { |
| 34 | hostArches = supportedArches |
| 35 | } else { |
| 36 | hostArches = strings.Split(e, " ") |
| 37 | } |
| 38 | |
| 39 | e = envDefault(ctx, "ART_TARGET_CODEGEN_ARCHS", "") |
| 40 | if e == "" { |
| 41 | deviceArches = defaultDeviceCodegenArches(ctx) |
| 42 | } else { |
| 43 | deviceArches = strings.Split(e, " ") |
| 44 | } |
| 45 | |
| 46 | type props struct { |
| 47 | Target struct { |
| 48 | Android *codegenArchProperties |
| 49 | Host *codegenArchProperties |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | addCodegenArchProperties := func(p *props, hod **codegenArchProperties, arch string) { |
| 54 | switch arch { |
| 55 | case "arm": |
| 56 | *hod = &c.Arm |
| 57 | case "arm64": |
| 58 | *hod = &c.Arm64 |
| 59 | case "mips": |
| 60 | *hod = &c.Mips |
| 61 | case "mips64": |
| 62 | *hod = &c.Mips64 |
| 63 | case "x86": |
| 64 | *hod = &c.X86 |
| 65 | case "x86_64": |
| 66 | *hod = &c.X86_64 |
| 67 | default: |
| 68 | ctx.ModuleErrorf("Unknown codegen architecture %q", arch) |
| 69 | return |
| 70 | } |
| 71 | ctx.AppendProperties(p) |
| 72 | } |
| 73 | |
| 74 | for _, a := range deviceArches { |
| 75 | p := &props{} |
| 76 | addCodegenArchProperties(p, &p.Target.Android, a) |
| 77 | if ctx.Failed() { |
| 78 | return |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | for _, a := range hostArches { |
| 83 | p := &props{} |
| 84 | addCodegenArchProperties(p, &p.Target.Host, a) |
| 85 | if ctx.Failed() { |
| 86 | return |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | type codegenArchProperties struct { |
| 92 | Srcs []string |
| 93 | Cflags []string |
| 94 | Static struct { |
| 95 | Whole_static_libs []string |
| 96 | } |
| 97 | Shared struct { |
| 98 | Shared_libs []string |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | type codegenProperties struct { |
| 103 | Codegen struct { |
| 104 | Arm, Arm64, Mips, Mips64, X86, X86_64 codegenArchProperties |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | type codegenCustomizer struct { |
| 109 | codegenProperties codegenProperties |
| 110 | } |
| 111 | |
| 112 | func defaultDeviceCodegenArches(ctx android.CustomizePropertiesContext) []string { |
| 113 | arches := make(map[string]bool) |
| 114 | for _, a := range ctx.DeviceConfig().Arches() { |
Nicolas Geoffray | e52ac15 | 2016-09-09 15:48:19 +0100 | [diff] [blame^] | 115 | s := a.ArchType.String() |
| 116 | arches[s] = true |
| 117 | if s == "arm64" { |
| 118 | arches["arm"] = true |
| 119 | } else if s == "mips64" { |
| 120 | arches["mips"] = true |
| 121 | } else if s == "x86_64" { |
| 122 | arches["x86"] = true |
| 123 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 124 | } |
| 125 | ret := make([]string, 0, len(arches)) |
| 126 | for a := range arches { |
| 127 | ret = append(ret, a) |
| 128 | } |
| 129 | sort.Strings(ret) |
| 130 | return ret |
| 131 | } |