| 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() { | 
| Steven Moreland | 00e1e61 | 2018-07-11 15:24:31 -0700 | [diff] [blame] | 26 | android.RegisterModuleType("phony", PhonyFactory) | 
| Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 27 | } | 
|  | 28 |  | 
|  | 29 | type phony struct { | 
|  | 30 | android.ModuleBase | 
| Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 31 | requiredModuleNames       []string | 
|  | 32 | hostRequiredModuleNames   []string | 
|  | 33 | targetRequiredModuleNames []string | 
| Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 34 | } | 
|  | 35 |  | 
| Steven Moreland | 00e1e61 | 2018-07-11 15:24:31 -0700 | [diff] [blame] | 36 | func PhonyFactory() android.Module { | 
| Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 37 | module := &phony{} | 
|  | 38 |  | 
| Dan Willemsen | 60294ef | 2019-04-02 17:04:18 -0700 | [diff] [blame] | 39 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 40 | return module | 
| Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 41 | } | 
|  | 42 |  | 
| Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 43 | func (p *phony) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
|  | 44 | p.requiredModuleNames = ctx.RequiredModuleNames() | 
| Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 45 | p.hostRequiredModuleNames = ctx.HostRequiredModuleNames() | 
|  | 46 | p.targetRequiredModuleNames = ctx.TargetRequiredModuleNames() | 
| Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 47 | } | 
|  | 48 |  | 
| Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 49 | func (p *phony) AndroidMk() android.AndroidMkData { | 
|  | 50 | return android.AndroidMkData{ | 
| Colin Cross | 0f86d18 | 2017-08-10 17:07:28 -0700 | [diff] [blame] | 51 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { | 
| Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 52 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") | 
|  | 53 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) | 
|  | 54 | fmt.Fprintln(w, "LOCAL_MODULE :=", name) | 
| Dan Willemsen | 60294ef | 2019-04-02 17:04:18 -0700 | [diff] [blame] | 55 | if p.Host() { | 
|  | 56 | fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") | 
|  | 57 | } | 
| Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 58 | if len(p.requiredModuleNames) > 0 { | 
|  | 59 | fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", | 
|  | 60 | strings.Join(p.requiredModuleNames, " ")) | 
|  | 61 | } | 
|  | 62 | if len(p.hostRequiredModuleNames) > 0 { | 
|  | 63 | fmt.Fprintln(w, "LOCAL_HOST_REQUIRED_MODULES :=", | 
|  | 64 | strings.Join(p.hostRequiredModuleNames, " ")) | 
|  | 65 | } | 
|  | 66 | if len(p.targetRequiredModuleNames) > 0 { | 
|  | 67 | fmt.Fprintln(w, "LOCAL_TARGET_REQUIRED_MODULES :=", | 
|  | 68 | strings.Join(p.targetRequiredModuleNames, " ")) | 
|  | 69 | } | 
| Colin Cross | a18e9cf | 2017-08-10 17:00:19 -0700 | [diff] [blame] | 70 | fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") | 
|  | 71 | }, | 
| Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 72 | } | 
| Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 73 | } |