blob: c77ced16eacdbbb40859c45b8bd773d5897ff012 [file] [log] [blame]
Dan Albert30c9d6e2017-03-28 14:54:55 -07001// 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
15package android
16
17import (
18 "encoding/json"
19
20 "github.com/google/blueprint"
21)
22
23func init() {
24 RegisterSingletonType("api_levels", ApiLevelsSingleton)
25}
26
27func ApiLevelsSingleton() blueprint.Singleton {
28 return &apiLevelsSingleton{}
29}
30
31type apiLevelsSingleton struct{}
32
33func createApiLevelsJson(ctx blueprint.SingletonContext, file string,
34 apiLevelsMap map[string]int) {
35
36 jsonStr, err := json.Marshal(apiLevelsMap)
37 if err != nil {
38 ctx.Errorf(err.Error())
39 }
40
41 ctx.Build(pctx, blueprint.BuildParams{
42 Rule: WriteFile,
43 Outputs: []string{file},
44 Args: map[string]string{
45 "content": string(jsonStr[:]),
46 },
47 })
48}
49
50func GetApiLevelsJson(ctx PathContext) Path {
51 return PathForOutput(ctx, "api_levels.json")
52}
53
54func (a *apiLevelsSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
55 baseApiLevel := 9000
56 apiLevelsMap := map[string]int{}
57 for i, codename := range ctx.Config().(Config).PlatformVersionAllCodenames() {
58 apiLevelsMap[codename] = baseApiLevel + i
59 }
60
61 apiLevelsJson := GetApiLevelsJson(ctx)
62 createApiLevelsJson(ctx, apiLevelsJson.String(), apiLevelsMap)
63}