• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2023 The Android Open Source Project
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 soong_wayland_protocol_codegen
16
17import (
18	"strings"
19
20	"android/soong/android"
21)
22
23// Note: the types defined here are identical to the types defined in the
24// locations.go file included as "android/soong/genrule" package.
25// Unfortunately all the types defined there are not public, which means we
26// can't reference them from that package.
27
28// location is used to service $(location) and $(locations) entries in
29// wayland_protocol_codegen commands.
30type location interface {
31	Paths(cmd *android.RuleBuilderCommand) []string
32	String() string
33}
34
35// inputLocation is a $(location) result for an entry in the srcs property.
36type inputLocation struct {
37	paths android.Paths
38}
39
40func (l inputLocation) String() string {
41	return strings.Join(l.paths.Strings(), " ")
42}
43
44func (l inputLocation) Paths(cmd *android.RuleBuilderCommand) []string {
45	return cmd.PathsForInputs(l.paths)
46}
47
48var _ location = inputLocation{}
49
50// outputLocation is a $(location) result for an entry in the out property.
51type outputLocation struct {
52	path android.WritablePath
53}
54
55func (l outputLocation) String() string {
56	return l.path.String()
57}
58
59func (l outputLocation) Paths(cmd *android.RuleBuilderCommand) []string {
60	return []string{cmd.PathForOutput(l.path)}
61}
62
63var _ location = outputLocation{}
64
65// toolLocation is a $(location) result for an entry in the tools or
66// tool_files property.
67type toolLocation struct {
68	paths android.Paths
69}
70
71func (l toolLocation) String() string {
72	return strings.Join(l.paths.Strings(), " ")
73}
74
75func (l toolLocation) Paths(cmd *android.RuleBuilderCommand) []string {
76	return cmd.PathsForTools(l.paths)
77}
78
79var _ location = toolLocation{}
80
81// packagedToolLocation is a $(location) result for an entry in the tools or
82// tool_files property that has PackagingSpecs.
83type packagedToolLocation struct {
84	spec android.PackagingSpec
85}
86
87func (l packagedToolLocation) String() string {
88	return l.spec.FileName()
89}
90
91func (l packagedToolLocation) Paths(cmd *android.RuleBuilderCommand) []string {
92	return []string{cmd.PathForPackagedTool(l.spec)}
93}
94
95var _ location = packagedToolLocation{}
96
97// errorLocation is a placeholder for a $(location) result that returns
98// garbage to break the command when error reporting is delayed by
99// ALLOW_MISSING_DEPENDENCIES=true.
100type errorLocation struct {
101	err string
102}
103
104func (l errorLocation) String() string {
105	return l.err
106}
107
108func (l errorLocation) Paths(cmd *android.RuleBuilderCommand) []string {
109	return []string{l.err}
110}
111
112var _ location = errorLocation{}
113