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