Remove references of ConfiguredTarget.getTarget() from ToolchainUtil.
@@ -25,6 +25,8 @@ import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
import com.google.devtools.build.lib.analysis.platform.PlatformProviderUtils;
import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.packages.NoSuchTargetException;
+import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.ConfiguredValueCreationException;
import com.google.devtools.build.lib.skyframe.RegisteredToolchainsFunction.InvalidToolchainLabelException;
import com.google.devtools.build.lib.skyframe.ToolchainResolutionFunction.NoToolchainFoundException;
@@ -110,7 +112,9 @@ public class ToolchainUtil {
*/
@Nullable
private static PlatformInfo findPlatformInfo(
- ValueOrException<ConfiguredValueCreationException> valueOrException, String platformType)
+ ValueOrException<ConfiguredValueCreationException> valueOrException,
+ String platformType,
+ Environment env)
throws ConfiguredValueCreationException, ToolchainContextException {
ConfiguredTargetValue ctv = (ConfiguredTargetValue) valueOrException.get();
@@ -119,10 +123,20 @@ public class ToolchainUtil {
}
ConfiguredTarget configuredTarget = ctv.getConfiguredTarget();
+ Target target = null;
+ try {
+ target =
+ ((PackageValue)
+ env.getValue(
+ PackageValue.key(configuredTarget.getLabel().getPackageIdentifier())))
+ .getPackage()
+ .getTarget(configuredTarget.getLabel().getName());
+ } catch (NoSuchTargetException | InterruptedException e) {
+ throw new IllegalStateException("Unable to get Target when computing PlatformInfo.", e);
+ }
PlatformInfo platformInfo = PlatformProviderUtils.platform(configuredTarget);
if (platformInfo == null) {
- throw new ToolchainContextException(
- new InvalidPlatformException(platformType, configuredTarget));
+ throw new ToolchainContextException(new InvalidPlatformException(platformType, target));
}
return platformInfo;
@@ -150,9 +164,9 @@ public class ToolchainUtil {
boolean valuesMissing = env.valuesMissing();
try {
PlatformInfo execPlatform =
- findPlatformInfo(values.get(executionPlatformKey), "execution platform");
+ findPlatformInfo(values.get(executionPlatformKey), "execution platform", env);
PlatformInfo targetPlatform =
- findPlatformInfo(values.get(targetPlatformKey), "target platform");
+ findPlatformInfo(values.get(targetPlatformKey), "target platform", env);
if (valuesMissing) {
return null;
@@ -247,11 +261,11 @@ public class ToolchainUtil {
/** Exception used when a platform label is not a valid platform. */
public static final class InvalidPlatformException extends Exception {
- public InvalidPlatformException(String platformType, ConfiguredTarget resolvedTarget) {
+ public InvalidPlatformException(String platformType, Target target) {
super(
String.format(
"Target %s was found as the %s, but does not provide PlatformInfo",
- resolvedTarget.getTarget(), platformType));
+ target, platformType));
}
}
