aboutsummaryrefslogtreecommitdiff
path: root/genrule/locations.go
blob: 2978b918d7f74a4cc9e391b8db15f0d59ab0bd12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2021 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package genrule

import (
	"strings"

	"android/soong/android"
)

// location is used to service $(location) and $(locations) entries in genrule commands.
type location interface {
	Paths(cmd *android.RuleBuilderCommand) []string
	String() string
}

// inputLocation is a $(location) result for an entry in the srcs property.
type inputLocation struct {
	paths android.Paths
}

func (l inputLocation) String() string {
	return strings.Join(l.paths.Strings(), " ")
}

func (l inputLocation) Paths(cmd *android.RuleBuilderCommand) []string {
	return cmd.PathsForInputs(l.paths)
}

var _ location = inputLocation{}

// outputLocation is a $(location) result for an entry in the out property.
type outputLocation struct {
	path android.WritablePath
}

func (l outputLocation) String() string {
	return l.path.String()
}

func (l outputLocation) Paths(cmd *android.RuleBuilderCommand) []string {
	return []string{cmd.PathForOutput(l.path)}
}

var _ location = outputLocation{}

// toolLocation is a $(location) result for an entry in the tools or tool_files property.
type toolLocation struct {
	paths android.Paths
}

func (l toolLocation) String() string {
	return strings.Join(l.paths.Strings(), " ")
}

func (l toolLocation) Paths(cmd *android.RuleBuilderCommand) []string {
	return cmd.PathsForTools(l.paths)
}

var _ location = toolLocation{}

// packagedToolLocation is a $(location) result for an entry in the tools or tool_files property
// that has PackagingSpecs.
type packagedToolLocation struct {
	spec android.PackagingSpec
}

func (l packagedToolLocation) String() string {
	return l.spec.FileName()
}

func (l packagedToolLocation) Paths(cmd *android.RuleBuilderCommand) []string {
	return []string{cmd.PathForPackagedTool(l.spec)}
}

var _ location = packagedToolLocation{}

// errorLocation is a placeholder for a $(location) result that returns garbage to break the command
// when error reporting is delayed by ALLOW_MISSING_DEPENDENCIES=true.
type errorLocation struct {
	err string
}

func (l errorLocation) String() string {
	return l.err
}

func (l errorLocation) Paths(cmd *android.RuleBuilderCommand) []string {
	return []string{l.err}
}

var _ location = errorLocation{}