phony.go 2.2 KB

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