blob: e8a6550fa1828cf0c1e28b0e8e35339eb3a5d9cb [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
31 requiredModuleNames []string
32}
33
Steven Moreland00e1e612018-07-11 15:24:31 -070034func PhonyFactory() android.Module {
Nan Zhang6d34b302017-02-04 17:47:46 -080035 module := &phony{}
36
Colin Cross36242852017-06-23 15:06:31 -070037 android.InitAndroidModule(module)
38 return module
Nan Zhang6d34b302017-02-04 17:47:46 -080039}
40
Nan Zhang6d34b302017-02-04 17:47:46 -080041func (p *phony) GenerateAndroidBuildActions(ctx android.ModuleContext) {
42 p.requiredModuleNames = ctx.RequiredModuleNames()
43 if len(p.requiredModuleNames) == 0 {
44 ctx.PropertyErrorf("required", "phony must not have empty required dependencies in order to be useful(and therefore permitted).")
45 }
46}
47
Colin Crossa18e9cf2017-08-10 17:00:19 -070048func (p *phony) AndroidMk() android.AndroidMkData {
49 return android.AndroidMkData{
Colin Cross0f86d182017-08-10 17:07:28 -070050 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
Colin Crossa18e9cf2017-08-10 17:00:19 -070051 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
52 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
53 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
54 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(p.requiredModuleNames, " "))
55 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
56 },
Nan Zhang6d34b302017-02-04 17:47:46 -080057 }
Nan Zhang6d34b302017-02-04 17:47:46 -080058}