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 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame^] | 27 | func codegen(ctx android.LoadHookContext, c *codegenProperties) { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 28 | 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 Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame^] | 54 | *hod = &c.Codegen.Arm |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 55 | case "arm64": |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame^] | 56 | *hod = &c.Codegen.Arm64 |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 57 | case "mips": |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame^] | 58 | *hod = &c.Codegen.Mips |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 59 | case "mips64": |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame^] | 60 | *hod = &c.Codegen.Mips64 |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 61 | case "x86": |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame^] | 62 | *hod = &c.Codegen.X86 |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 63 | case "x86_64": |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame^] | 64 | *hod = &c.Codegen.X86_64 |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 65 | 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 | |
| 89 | type 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 | |
| 100 | type codegenProperties struct { |
| 101 | Codegen struct { |
| 102 | Arm, Arm64, Mips, Mips64, X86, X86_64 codegenArchProperties |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | type codegenCustomizer struct { |
| 107 | codegenProperties codegenProperties |
| 108 | } |
| 109 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame^] | 110 | func defaultDeviceCodegenArches(ctx android.LoadHookContext) []string { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 111 | arches := make(map[string]bool) |
| 112 | for _, a := range ctx.DeviceConfig().Arches() { |
Nicolas Geoffray | e52ac15 | 2016-09-09 15:48:19 +0100 | [diff] [blame] | 113 | 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 Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 122 | } |
| 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 | } |