Dan Albert | 30c9d6e | 2017-03-28 14:54:55 -0700 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. |
| 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 android |
| 16 | |
| 17 | import ( |
| 18 | "encoding/json" |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 19 | "path/filepath" |
Dan Albert | 30c9d6e | 2017-03-28 14:54:55 -0700 | [diff] [blame] | 20 | |
| 21 | "github.com/google/blueprint" |
| 22 | ) |
| 23 | |
| 24 | func init() { |
| 25 | RegisterSingletonType("api_levels", ApiLevelsSingleton) |
| 26 | } |
| 27 | |
| 28 | func ApiLevelsSingleton() blueprint.Singleton { |
| 29 | return &apiLevelsSingleton{} |
| 30 | } |
| 31 | |
| 32 | type apiLevelsSingleton struct{} |
| 33 | |
| 34 | func createApiLevelsJson(ctx blueprint.SingletonContext, file string, |
| 35 | apiLevelsMap map[string]int) { |
| 36 | |
| 37 | jsonStr, err := json.Marshal(apiLevelsMap) |
| 38 | if err != nil { |
| 39 | ctx.Errorf(err.Error()) |
| 40 | } |
| 41 | |
| 42 | ctx.Build(pctx, blueprint.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 43 | Rule: WriteFile, |
| 44 | Description: "generate " + filepath.Base(file), |
| 45 | Outputs: []string{file}, |
Dan Albert | 30c9d6e | 2017-03-28 14:54:55 -0700 | [diff] [blame] | 46 | Args: map[string]string{ |
| 47 | "content": string(jsonStr[:]), |
| 48 | }, |
| 49 | }) |
| 50 | } |
| 51 | |
| 52 | func GetApiLevelsJson(ctx PathContext) Path { |
| 53 | return PathForOutput(ctx, "api_levels.json") |
| 54 | } |
| 55 | |
| 56 | func (a *apiLevelsSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) { |
| 57 | baseApiLevel := 9000 |
Dan Albert | 1510271 | 2017-07-28 12:31:28 -0700 | [diff] [blame] | 58 | apiLevelsMap := map[string]int{ |
| 59 | "G": 9, |
| 60 | "I": 14, |
| 61 | "J": 16, |
| 62 | "J-MR1": 17, |
| 63 | "J-MR2": 18, |
| 64 | "K": 19, |
| 65 | "L": 21, |
| 66 | "L-MR1": 22, |
| 67 | "M": 23, |
| 68 | "N": 24, |
| 69 | "N-MR1": 25, |
Dan Albert | e3e4fc8 | 2017-08-29 11:50:34 -0700 | [diff] [blame^] | 70 | "O": 26, |
Dan Albert | 1510271 | 2017-07-28 12:31:28 -0700 | [diff] [blame] | 71 | } |
Dan Albert | 31384de | 2017-07-28 12:39:46 -0700 | [diff] [blame] | 72 | for i, codename := range ctx.Config().(Config).PlatformVersionCombinedCodenames() { |
Dan Albert | 30c9d6e | 2017-03-28 14:54:55 -0700 | [diff] [blame] | 73 | apiLevelsMap[codename] = baseApiLevel + i |
| 74 | } |
| 75 | |
| 76 | apiLevelsJson := GetApiLevelsJson(ctx) |
| 77 | createApiLevelsJson(ctx, apiLevelsJson.String(), apiLevelsMap) |
| 78 | } |