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