locations.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright 2021 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 genrule
  15. import (
  16. "strings"
  17. "android/soong/android"
  18. )
  19. // location is used to service $(location) and $(locations) entries in genrule commands.
  20. type location interface {
  21. Paths(cmd *android.RuleBuilderCommand) []string
  22. String() string
  23. }
  24. // inputLocation is a $(location) result for an entry in the srcs property.
  25. type inputLocation struct {
  26. paths android.Paths
  27. }
  28. func (l inputLocation) String() string {
  29. return strings.Join(l.paths.Strings(), " ")
  30. }
  31. func (l inputLocation) Paths(cmd *android.RuleBuilderCommand) []string {
  32. return cmd.PathsForInputs(l.paths)
  33. }
  34. var _ location = inputLocation{}
  35. // outputLocation is a $(location) result for an entry in the out property.
  36. type outputLocation struct {
  37. path android.WritablePath
  38. }
  39. func (l outputLocation) String() string {
  40. return l.path.String()
  41. }
  42. func (l outputLocation) Paths(cmd *android.RuleBuilderCommand) []string {
  43. return []string{cmd.PathForOutput(l.path)}
  44. }
  45. var _ location = outputLocation{}
  46. // toolLocation is a $(location) result for an entry in the tools or tool_files property.
  47. type toolLocation struct {
  48. paths android.Paths
  49. }
  50. func (l toolLocation) String() string {
  51. return strings.Join(l.paths.Strings(), " ")
  52. }
  53. func (l toolLocation) Paths(cmd *android.RuleBuilderCommand) []string {
  54. return cmd.PathsForTools(l.paths)
  55. }
  56. var _ location = toolLocation{}
  57. // packagedToolLocation is a $(location) result for an entry in the tools or tool_files property
  58. // that has PackagingSpecs.
  59. type packagedToolLocation struct {
  60. spec android.PackagingSpec
  61. }
  62. func (l packagedToolLocation) String() string {
  63. return l.spec.FileName()
  64. }
  65. func (l packagedToolLocation) Paths(cmd *android.RuleBuilderCommand) []string {
  66. return []string{cmd.PathForPackagedTool(l.spec)}
  67. }
  68. var _ location = packagedToolLocation{}
  69. // errorLocation is a placeholder for a $(location) result that returns garbage to break the command
  70. // when error reporting is delayed by ALLOW_MISSING_DEPENDENCIES=true.
  71. type errorLocation struct {
  72. err string
  73. }
  74. func (l errorLocation) String() string {
  75. return l.err
  76. }
  77. func (l errorLocation) Paths(cmd *android.RuleBuilderCommand) []string {
  78. return []string{l.err}
  79. }
  80. var _ location = errorLocation{}