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 15package phony 16 17import ( 18 "fmt" 19 "io" 20 "strings" 21 22 "android/soong/android" 23) 24 25func init() { 26 android.RegisterModuleType("phony", PhonyFactory) 27} 28 29type phony struct { 30 android.ModuleBase 31 requiredModuleNames []string 32 hostRequiredModuleNames []string 33 targetRequiredModuleNames []string 34} 35 36func PhonyFactory() android.Module { 37 module := &phony{} 38 39 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) 40 return module 41} 42 43func (p *phony) GenerateAndroidBuildActions(ctx android.ModuleContext) { 44 p.requiredModuleNames = ctx.RequiredModuleNames() 45 p.hostRequiredModuleNames = ctx.HostRequiredModuleNames() 46 p.targetRequiredModuleNames = ctx.TargetRequiredModuleNames() 47} 48 49func (p *phony) AndroidMk() android.AndroidMkData { 50 return android.AndroidMkData{ 51 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { 52 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") 53 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) 54 fmt.Fprintln(w, "LOCAL_MODULE :=", name) 55 data.Entries.WriteLicenseVariables(w) 56 if p.Host() { 57 fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") 58 } 59 if len(p.requiredModuleNames) > 0 { 60 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", 61 strings.Join(p.requiredModuleNames, " ")) 62 } 63 if len(p.hostRequiredModuleNames) > 0 { 64 fmt.Fprintln(w, "LOCAL_HOST_REQUIRED_MODULES :=", 65 strings.Join(p.hostRequiredModuleNames, " ")) 66 } 67 if len(p.targetRequiredModuleNames) > 0 { 68 fmt.Fprintln(w, "LOCAL_TARGET_REQUIRED_MODULES :=", 69 strings.Join(p.targetRequiredModuleNames, " ")) 70 } 71 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") 72 }, 73 } 74} 75