blob: 55a72a6a02eb1dbf06c7cb323db6d4ee306fbc8c [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.
Jiyong Park5a8d1be2018-04-25 22:57:34 +090031 Src *string `android:"arch_variant"`
Jiyong Parkc678ad32018-04-10 13:07:10 +090032
33 // optional subdirectory under which this file is installed into
34 Sub_dir *string `android:"arch_variant"`
35}
36
Jiyong Park5a8d1be2018-04-25 22:57:34 +090037type PrebuiltEtc struct {
Jiyong Parkc678ad32018-04-10 13:07:10 +090038 ModuleBase
Jiyong Parkc678ad32018-04-10 13:07:10 +090039
40 properties prebuiltEtcProperties
41
Jiyong Park5a8d1be2018-04-25 22:57:34 +090042 sourceFilePath Path
43 installDirPath OutputPath
44 additionalDependencies *Paths
Jiyong Parkc678ad32018-04-10 13:07:10 +090045}
46
Jiyong Park5a8d1be2018-04-25 22:57:34 +090047func (p *PrebuiltEtc) DepsMutator(ctx BottomUpMutatorContext) {
48 if p.properties.Src == nil {
49 ctx.PropertyErrorf("src", "missing prebuilt source file")
Jiyong Parkc678ad32018-04-10 13:07:10 +090050 }
51
52 // To support ":modulename" in src
Jiyong Park5a8d1be2018-04-25 22:57:34 +090053 ExtractSourceDeps(ctx, p.properties.Src)
Jiyong Parkc678ad32018-04-10 13:07:10 +090054}
55
Jiyong Park5a8d1be2018-04-25 22:57:34 +090056func (p *PrebuiltEtc) SourceFilePath(ctx ModuleContext) Path {
57 return ctx.ExpandSource(String(p.properties.Src), "src")
58}
59
60// This allows other derivative modules (e.g. prebuilt_etc_xml) to perform
61// additional steps (like validating the src) before the file is installed.
62func (p *PrebuiltEtc) SetAdditionalDependencies(paths Paths) {
63 p.additionalDependencies = &paths
64}
65
66func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx ModuleContext) {
67 p.sourceFilePath = ctx.ExpandSource(String(p.properties.Src), "src")
Jiyong Parkc678ad32018-04-10 13:07:10 +090068 p.installDirPath = PathForModuleInstall(ctx, "etc", String(p.properties.Sub_dir))
69}
70
Jiyong Park5a8d1be2018-04-25 22:57:34 +090071func (p *PrebuiltEtc) AndroidMk() AndroidMkData {
Jiyong Parkc678ad32018-04-10 13:07:10 +090072 return AndroidMkData{
73 Custom: func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData) {
74 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
75 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
76 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
77 fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC")
78 fmt.Fprintln(w, "LOCAL_MODULE_TAGS := optional")
79 fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", p.sourceFilePath.String())
80 fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", "$(OUT_DIR)/"+p.installDirPath.RelPathString())
Jiyong Park5a8d1be2018-04-25 22:57:34 +090081 if p.additionalDependencies != nil {
82 fmt.Fprint(w, "LOCAL_ADDITIONAL_DEPENDENCIES :=")
83 for _, path := range *p.additionalDependencies {
84 fmt.Fprint(w, " "+path.String())
85 }
86 fmt.Fprintln(w, "")
87 }
Jiyong Parkc678ad32018-04-10 13:07:10 +090088 fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
89 },
90 }
91}
92
Jiyong Park5a8d1be2018-04-25 22:57:34 +090093func InitPrebuiltEtcModule(p *PrebuiltEtc) {
94 p.AddProperties(&p.properties)
95}
Jiyong Parkc678ad32018-04-10 13:07:10 +090096
Jiyong Park5a8d1be2018-04-25 22:57:34 +090097func PrebuiltEtcFactory() Module {
98 module := &PrebuiltEtc{}
99 InitPrebuiltEtcModule(module)
100 // This module is device-only
101 InitAndroidArchModule(module, DeviceSupported, MultilibCommon)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900102 return module
103}