blob: 305a434f4215b0986e6052c48cc835531a558df9 [file] [log] [blame]
Nan Zhang6d34b302017-02-04 17:47:46 -08001// 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 phony
16
17import (
18 "fmt"
19 "io"
20 "strings"
21
Nan Zhang6d34b302017-02-04 17:47:46 -080022 "android/soong/android"
23)
24
25func init() {
Steven Moreland00e1e612018-07-11 15:24:31 -070026 android.RegisterModuleType("phony", PhonyFactory)
Nan Zhang6d34b302017-02-04 17:47:46 -080027}
28
29type phony struct {
30 android.ModuleBase
Sasha Smundakb6d23052019-04-01 18:37:36 -070031 requiredModuleNames []string
32 hostRequiredModuleNames []string
33 targetRequiredModuleNames []string
Nan Zhang6d34b302017-02-04 17:47:46 -080034}
35
Steven Moreland00e1e612018-07-11 15:24:31 -070036func PhonyFactory() android.Module {
Nan Zhang6d34b302017-02-04 17:47:46 -080037 module := &phony{}
38
Dan Willemsen60294ef2019-04-02 17:04:18 -070039 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
Colin Cross36242852017-06-23 15:06:31 -070040 return module
Nan Zhang6d34b302017-02-04 17:47:46 -080041}
42
Nan Zhang6d34b302017-02-04 17:47:46 -080043func (p *phony) GenerateAndroidBuildActions(ctx android.ModuleContext) {
44 p.requiredModuleNames = ctx.RequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -070045 p.hostRequiredModuleNames = ctx.HostRequiredModuleNames()
46 p.targetRequiredModuleNames = ctx.TargetRequiredModuleNames()
47 if len(p.requiredModuleNames) == 0 &&
48 len(p.hostRequiredModuleNames) == 0 && len(p.targetRequiredModuleNames) == 0 {
49 ctx.PropertyErrorf("required", "phony must not have empty required dependencies "+
50 "in order to be useful(and therefore permitted).")
Nan Zhang6d34b302017-02-04 17:47:46 -080051 }
52}
53
Colin Crossa18e9cf2017-08-10 17:00:19 -070054func (p *phony) AndroidMk() android.AndroidMkData {
55 return android.AndroidMkData{
Colin Cross0f86d182017-08-10 17:07:28 -070056 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
Colin Crossa18e9cf2017-08-10 17:00:19 -070057 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
58 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
59 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
Dan Willemsen60294ef2019-04-02 17:04:18 -070060 if p.Host() {
61 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
62 }
Sasha Smundakb6d23052019-04-01 18:37:36 -070063 if len(p.requiredModuleNames) > 0 {
64 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=",
65 strings.Join(p.requiredModuleNames, " "))
66 }
67 if len(p.hostRequiredModuleNames) > 0 {
68 fmt.Fprintln(w, "LOCAL_HOST_REQUIRED_MODULES :=",
69 strings.Join(p.hostRequiredModuleNames, " "))
70 }
71 if len(p.targetRequiredModuleNames) > 0 {
72 fmt.Fprintln(w, "LOCAL_TARGET_REQUIRED_MODULES :=",
73 strings.Join(p.targetRequiredModuleNames, " "))
74 }
Colin Crossa18e9cf2017-08-10 17:00:19 -070075 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
76 },
Nan Zhang6d34b302017-02-04 17:47:46 -080077 }
Nan Zhang6d34b302017-02-04 17:47:46 -080078}