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