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 "github.com/google/blueprint" 23 24 "android/soong/android" 25) 26 27func init() { 28 android.RegisterModuleType("phony", phonyFactory) 29} 30 31type phony struct { 32 android.ModuleBase 33 requiredModuleNames []string 34} 35 36func phonyFactory() (blueprint.Module, []interface{}) { 37 module := &phony{} 38 39 return android.InitAndroidModule(module) 40} 41 42func (p *phony) DepsMutator(ctx android.BottomUpMutatorContext) { 43} 44 45func (p *phony) GenerateAndroidBuildActions(ctx android.ModuleContext) { 46 p.requiredModuleNames = ctx.RequiredModuleNames() 47 if len(p.requiredModuleNames) == 0 { 48 ctx.PropertyErrorf("required", "phony must not have empty required dependencies in order to be useful(and therefore permitted).") 49 } 50} 51 52func (p *phony) AndroidMk() (ret android.AndroidMkData, err error) { 53 ret.Custom = func(w io.Writer, name, prefix, moduleDir string) error { 54 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") 55 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) 56 fmt.Fprintln(w, "LOCAL_MODULE :=", name) 57 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(p.requiredModuleNames, " ")) 58 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") 59 60 return nil 61 } 62 return 63} 64