Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package android |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "io" |
| 20 | ) |
| 21 | |
| 22 | // prebuilt_etc is for prebuilts that will be installed to |
| 23 | // <partition>/etc/<subdir> |
| 24 | |
| 25 | func init() { |
| 26 | RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory) |
| 27 | } |
| 28 | |
| 29 | type prebuiltEtcProperties struct { |
| 30 | // Source file of this prebuilt. |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame^] | 31 | Src *string `android:"arch_variant"` |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 32 | |
| 33 | // optional subdirectory under which this file is installed into |
| 34 | Sub_dir *string `android:"arch_variant"` |
| 35 | } |
| 36 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame^] | 37 | type PrebuiltEtc struct { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 38 | ModuleBase |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 39 | |
| 40 | properties prebuiltEtcProperties |
| 41 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame^] | 42 | sourceFilePath Path |
| 43 | installDirPath OutputPath |
| 44 | additionalDependencies *Paths |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 45 | } |
| 46 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame^] | 47 | func (p *PrebuiltEtc) DepsMutator(ctx BottomUpMutatorContext) { |
| 48 | if p.properties.Src == nil { |
| 49 | ctx.PropertyErrorf("src", "missing prebuilt source file") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | // To support ":modulename" in src |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame^] | 53 | ExtractSourceDeps(ctx, p.properties.Src) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 54 | } |
| 55 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame^] | 56 | func (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. |
| 62 | func (p *PrebuiltEtc) SetAdditionalDependencies(paths Paths) { |
| 63 | p.additionalDependencies = &paths |
| 64 | } |
| 65 | |
| 66 | func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx ModuleContext) { |
| 67 | p.sourceFilePath = ctx.ExpandSource(String(p.properties.Src), "src") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 68 | p.installDirPath = PathForModuleInstall(ctx, "etc", String(p.properties.Sub_dir)) |
| 69 | } |
| 70 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame^] | 71 | func (p *PrebuiltEtc) AndroidMk() AndroidMkData { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 72 | 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 Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame^] | 81 | 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 Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 88 | fmt.Fprintln(w, "include $(BUILD_PREBUILT)") |
| 89 | }, |
| 90 | } |
| 91 | } |
| 92 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame^] | 93 | func InitPrebuiltEtcModule(p *PrebuiltEtc) { |
| 94 | p.AddProperties(&p.properties) |
| 95 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 96 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame^] | 97 | func PrebuiltEtcFactory() Module { |
| 98 | module := &PrebuiltEtc{} |
| 99 | InitPrebuiltEtcModule(module) |
| 100 | // This module is device-only |
| 101 | InitAndroidArchModule(module, DeviceSupported, MultilibCommon) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 102 | return module |
| 103 | } |