Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [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 phony |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "io" |
| 20 | "strings" |
| 21 | |
Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 22 | "android/soong/android" |
| 23 | ) |
| 24 | |
| 25 | func init() { |
| 26 | android.RegisterModuleType("phony", phonyFactory) |
| 27 | } |
| 28 | |
| 29 | type phony struct { |
| 30 | android.ModuleBase |
| 31 | requiredModuleNames []string |
| 32 | } |
| 33 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 34 | func phonyFactory() android.Module { |
Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 35 | module := &phony{} |
| 36 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 37 | android.InitAndroidModule(module) |
| 38 | return module |
Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | func (p *phony) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 42 | } |
| 43 | |
| 44 | func (p *phony) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 45 | p.requiredModuleNames = ctx.RequiredModuleNames() |
| 46 | if len(p.requiredModuleNames) == 0 { |
| 47 | ctx.PropertyErrorf("required", "phony must not have empty required dependencies in order to be useful(and therefore permitted).") |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | func (p *phony) AndroidMk() (ret android.AndroidMkData, err error) { |
Colin Cross | 91825d2 | 2017-08-10 16:59:47 -0700 | [diff] [blame^] | 52 | ret.Custom = func(w io.Writer, name, prefix, moduleDir string) { |
Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 53 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 54 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) |
| 55 | fmt.Fprintln(w, "LOCAL_MODULE :=", name) |
| 56 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(p.requiredModuleNames, " ")) |
| 57 | fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") |
Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 58 | } |
| 59 | return |
| 60 | } |