blob: fee2c49499f33f0ad46cc71ac0ee9f8f3c885314 [file] [log] [blame]
Jiyong Parkc678ad32018-04-10 13:07:10 +09001// Copyright 2016 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 "fmt"
19 "io"
20)
21
22// prebuilt_etc is for prebuilts that will be installed to
23// <partition>/etc/<subdir>
24
25func init() {
26 RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
27}
28
29type prebuiltEtcProperties struct {
30 // Source file of this prebuilt.
31 Srcs []string `android:"arch_variant"`
32
33 // optional subdirectory under which this file is installed into
34 Sub_dir *string `android:"arch_variant"`
35}
36
37type prebuiltEtc struct {
38 ModuleBase
39 prebuilt Prebuilt
40
41 properties prebuiltEtcProperties
42
43 sourceFilePath Path
44 installDirPath OutputPath
45}
46
47func (p *prebuiltEtc) Prebuilt() *Prebuilt {
48 return &p.prebuilt
49}
50
51func (p *prebuiltEtc) DepsMutator(ctx BottomUpMutatorContext) {
52 if len(p.properties.Srcs) == 0 {
53 ctx.PropertyErrorf("srcs", "missing prebuilt source file")
54 }
55
56 if len(p.properties.Srcs) > 1 {
57 ctx.PropertyErrorf("srcs", "multiple prebuilt source files")
58 }
59
60 // To support ":modulename" in src
61 ExtractSourceDeps(ctx, &(p.properties.Srcs)[0])
62}
63
64func (p *prebuiltEtc) GenerateAndroidBuildActions(ctx ModuleContext) {
65 p.sourceFilePath = ctx.ExpandSource(p.properties.Srcs[0], "srcs")
66 p.installDirPath = PathForModuleInstall(ctx, "etc", String(p.properties.Sub_dir))
67}
68
69func (p *prebuiltEtc) AndroidMk() AndroidMkData {
70 return AndroidMkData{
71 Custom: func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData) {
72 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
73 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
74 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
75 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC")
76 fmt.Fprintln(w, "LOCAL_MODULE_TAGS := optional")
77 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", p.sourceFilePath.String())
78 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", "$(OUT_DIR)/"+p.installDirPath.RelPathString())
79 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
80 },
81 }
82}
83
84func PrebuiltEtcFactory() Module {
85 module := &prebuiltEtc{}
86 module.AddProperties(&module.properties)
87
88 InitPrebuiltModule(module, &(module.properties.Srcs))
89 InitAndroidModule(module)
90 return module
91}