17
17
18
18
import com .google .common .base .Preconditions ;
19
19
import com .google .common .collect .ImmutableList ;
20
+ import com .google .common .collect .ImmutableListMultimap ;
20
21
import com .google .common .collect .ImmutableMap ;
21
22
import com .google .common .collect .ImmutableSet ;
22
- import com .google .common .collect .Multimap ;
23
23
import com .google .common .collect .Multimaps ;
24
24
import com .google .devtools .build .lib .analysis .ConfiguredTarget ;
25
25
import com .google .devtools .build .lib .analysis .ConfiguredTargetValue ;
57
57
*
58
58
* <p>Incomplete; we'll implement getVisibility when needed.
59
59
*/
60
- public class ConfiguredTargetAccessor implements TargetAccessor <KeyedConfiguredTarget > {
60
+ public class ConfiguredTargetAccessor implements TargetAccessor <ConfiguredTarget > {
61
61
62
62
private final WalkableGraph walkableGraph ;
63
63
private final ConfiguredTargetQueryEnvironment queryEnvironment ;
@@ -69,55 +69,56 @@ public ConfiguredTargetAccessor(
69
69
}
70
70
71
71
@ Override
72
- public String getTargetKind (KeyedConfiguredTarget target ) {
72
+ public String getTargetKind (ConfiguredTarget target ) {
73
73
Target actualTarget = getTarget (target );
74
74
return actualTarget .getTargetKind ();
75
75
}
76
76
77
77
@ Override
78
- public String getLabel (KeyedConfiguredTarget target ) {
79
- return target .getLabel ().toString ();
78
+ public String getLabel (ConfiguredTarget target ) {
79
+ return target .getOriginalLabel ().toString ();
80
80
}
81
81
82
82
@ Override
83
- public String getPackage (KeyedConfiguredTarget target ) {
84
- return target .getLabel ().getPackageIdentifier ().getPackageFragment ().toString ();
83
+ public String getPackage (ConfiguredTarget target ) {
84
+ return target .getOriginalLabel ().getPackageIdentifier ().getPackageFragment ().toString ();
85
85
}
86
86
87
87
@ Override
88
- public boolean isRule (KeyedConfiguredTarget target ) {
88
+ public boolean isRule (ConfiguredTarget target ) {
89
89
Target actualTarget = getTarget (target );
90
90
return actualTarget instanceof Rule ;
91
91
}
92
92
93
93
@ Override
94
- public boolean isTestRule (KeyedConfiguredTarget target ) {
94
+ public boolean isTestRule (ConfiguredTarget target ) {
95
95
Target actualTarget = getTarget (target );
96
96
return TargetUtils .isTestRule (actualTarget );
97
97
}
98
98
99
99
@ Override
100
- public boolean isTestSuite (KeyedConfiguredTarget target ) {
100
+ public boolean isTestSuite (ConfiguredTarget target ) {
101
101
Target actualTarget = getTarget (target );
102
102
return TargetUtils .isTestSuiteRule (actualTarget );
103
103
}
104
104
105
105
@ Override
106
- public List <KeyedConfiguredTarget > getPrerequisites (
106
+ public List <ConfiguredTarget > getPrerequisites (
107
107
QueryExpression caller ,
108
- KeyedConfiguredTarget keyedConfiguredTarget ,
108
+ ConfiguredTarget keyedConfiguredTarget ,
109
109
String attrName ,
110
110
String errorMsgPrefix )
111
111
throws QueryException , InterruptedException {
112
112
// Process aliases.
113
- KeyedConfiguredTarget actual = keyedConfiguredTarget .getActual ();
113
+ ConfiguredTarget actual = keyedConfiguredTarget .getActual ();
114
114
115
115
Preconditions .checkArgument (
116
116
isRule (actual ), "%s %s is not a rule configured target" , errorMsgPrefix , getLabel (actual ));
117
117
118
- Multimap <Label , KeyedConfiguredTarget > depsByLabel =
118
+ ImmutableListMultimap <Label , ConfiguredTarget > depsByLabel =
119
119
Multimaps .index (
120
- queryEnvironment .getFwdDeps (ImmutableList .of (actual )), KeyedConfiguredTarget ::getLabel );
120
+ queryEnvironment .getFwdDeps (ImmutableList .of (actual )),
121
+ ConfiguredTarget ::getOriginalLabel );
121
122
122
123
Rule rule = (Rule ) getTarget (actual );
123
124
ImmutableMap <Label , ConfigMatchingProvider > configConditions = actual .getConfigConditions ();
@@ -135,41 +136,41 @@ public List<KeyedConfiguredTarget> getPrerequisites(
135
136
errorMsgPrefix , rule .getRuleClass (), attrName ),
136
137
ConfigurableQuery .Code .ATTRIBUTE_MISSING );
137
138
}
138
- ImmutableList .Builder <KeyedConfiguredTarget > toReturn = ImmutableList .builder ();
139
+ ImmutableList .Builder <ConfiguredTarget > toReturn = ImmutableList .builder ();
139
140
attributeMapper .visitLabels (attrName , label -> toReturn .addAll (depsByLabel .get (label )));
140
141
return toReturn .build ();
141
142
}
142
143
143
144
@ Override
144
- public List <String > getStringListAttr (KeyedConfiguredTarget target , String attrName ) {
145
+ public List <String > getStringListAttr (ConfiguredTarget target , String attrName ) {
145
146
Target actualTarget = getTarget (target );
146
147
return TargetUtils .getStringListAttr (actualTarget , attrName );
147
148
}
148
149
149
150
@ Override
150
- public String getStringAttr (KeyedConfiguredTarget target , String attrName ) {
151
+ public String getStringAttr (ConfiguredTarget target , String attrName ) {
151
152
Target actualTarget = getTarget (target );
152
153
return TargetUtils .getStringAttr (actualTarget , attrName );
153
154
}
154
155
155
156
@ Override
156
- public Iterable <String > getAttrAsString (KeyedConfiguredTarget target , String attrName ) {
157
+ public Iterable <String > getAttrAsString (ConfiguredTarget target , String attrName ) {
157
158
Target actualTarget = getTarget (target );
158
159
return TargetUtils .getAttrAsString (actualTarget , attrName );
159
160
}
160
161
161
162
@ Override
162
- public ImmutableSet <QueryVisibility <KeyedConfiguredTarget >> getVisibility (
163
- QueryExpression caller , KeyedConfiguredTarget from ) throws QueryException {
163
+ public ImmutableSet <QueryVisibility <ConfiguredTarget >> getVisibility (
164
+ QueryExpression caller , ConfiguredTarget from ) throws QueryException {
164
165
// TODO(bazel-team): implement this if needed.
165
166
throw new QueryException (
166
167
"visible() is not supported on configured targets" ,
167
168
ConfigurableQuery .Code .VISIBLE_FUNCTION_NOT_SUPPORTED );
168
169
}
169
170
170
- public Target getTarget (KeyedConfiguredTarget keyedConfiguredTarget ) {
171
+ public Target getTarget (ConfiguredTarget configuredTarget ) {
171
172
// Dereference any aliases that might be present.
172
- Label label = keyedConfiguredTarget . getConfiguredTarget () .getOriginalLabel ();
173
+ Label label = configuredTarget .getOriginalLabel ();
173
174
try {
174
175
return queryEnvironment .getTarget (label );
175
176
} catch (InterruptedException e ) {
@@ -180,18 +181,15 @@ public Target getTarget(KeyedConfiguredTarget keyedConfiguredTarget) {
180
181
}
181
182
182
183
/** Returns the rule that generates the given output file. */
183
- RuleConfiguredTarget getGeneratingConfiguredTarget (KeyedConfiguredTarget kct )
184
+ RuleConfiguredTarget getGeneratingConfiguredTarget (ConfiguredTarget kct )
184
185
throws InterruptedException {
185
- Preconditions .checkArgument (kct . getConfiguredTarget () instanceof OutputFileConfiguredTarget );
186
+ Preconditions .checkArgument (kct instanceof OutputFileConfiguredTarget );
186
187
return (RuleConfiguredTarget )
187
188
((ConfiguredTargetValue )
188
189
walkableGraph .getValue (
189
190
ConfiguredTargetKey .builder ()
190
- .setLabel (
191
- ((OutputFileConfiguredTarget ) kct .getConfiguredTarget ())
192
- .getGeneratingRule ()
193
- .getLabel ())
194
- .setConfiguration (queryEnvironment .getConfiguration (kct ))
191
+ .setLabel (((OutputFileConfiguredTarget ) kct ).getGeneratingRule ().getLabel ())
192
+ .setConfigurationKey (kct .getConfigurationKey ())
195
193
.build ()
196
194
.toKey ()))
197
195
.getConfiguredTarget ();
0 commit comments