use of com.google.devtools.build.lib.packages.NoSuchTargetException in project bazel by bazelbuild.
the class TransitiveBaseTraversalFunction method loadTarget.
private LoadTargetResults loadTarget(Environment env, Label label) throws NoSuchTargetException, NoSuchPackageException, InterruptedException {
SkyKey packageKey = PackageValue.key(label.getPackageIdentifier());
SkyKey targetKey = TargetMarkerValue.key(label);
boolean packageLoadedSuccessfully;
Target target;
NoSuchTargetException errorLoadingTarget = null;
try {
TargetMarkerValue targetValue = getTargetMarkerValue(targetKey, env);
boolean targetValueMissing = targetValue == null;
Preconditions.checkState(targetValueMissing == env.valuesMissing(), targetKey);
if (targetValueMissing) {
return ValuesMissing.INSTANCE;
}
PackageValue packageValue = (PackageValue) env.getValueOrThrow(packageKey, NoSuchPackageException.class);
if (packageValue == null) {
return ValuesMissing.INSTANCE;
}
Package pkg = packageValue.getPackage();
if (pkg.containsErrors()) {
throw new BuildFileContainsErrorsException(label.getPackageIdentifier());
}
packageLoadedSuccessfully = true;
try {
target = pkg.getTarget(label.getName());
} catch (NoSuchTargetException unexpected) {
// was not present.
throw new IllegalStateException(unexpected);
}
} catch (NoSuchTargetException e) {
if (!e.hasTarget()) {
throw e;
}
// We know that a Target may be extracted, but we need to get it out of the Package
// (which is known to be in error).
PackageValue packageValue = (PackageValue) Preconditions.checkNotNull(env.getValue(packageKey), label);
Package pkg = packageValue.getPackage();
try {
target = pkg.getTarget(label.getName());
} catch (NoSuchTargetException nste) {
throw new IllegalStateException("Expected target to exist", nste);
}
errorLoadingTarget = e;
packageLoadedSuccessfully = false;
}
return new TargetAndErrorIfAnyImpl(packageLoadedSuccessfully, errorLoadingTarget, target);
}
use of com.google.devtools.build.lib.packages.NoSuchTargetException in project bazel by bazelbuild.
the class TransitiveBaseTraversalFunction method getStrictLabelAspectKeys.
/**
* Return an Iterable of SkyKeys corresponding to the Aspect-related dependencies of target.
*
* <p>This method may return a precise set of aspect keys, but may need to request additional
* dependencies from the env to do so.
*/
private Iterable<SkyKey> getStrictLabelAspectKeys(Target target, Map<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>> depMap, Environment env) throws InterruptedException {
List<SkyKey> depKeys = Lists.newArrayList();
if (target instanceof Rule) {
Map<Label, ValueOrException2<NoSuchPackageException, NoSuchTargetException>> labelDepMap = new HashMap<>(depMap.size());
for (Entry<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>> entry : depMap.entrySet()) {
labelDepMap.put((Label) entry.getKey().argument(), entry.getValue());
}
Multimap<Attribute, Label> transitions = ((Rule) target).getTransitions(DependencyFilter.NO_NODEP_ATTRIBUTES);
for (Entry<Attribute, Label> entry : transitions.entries()) {
ValueOrException2<NoSuchPackageException, NoSuchTargetException> value = labelDepMap.get(entry.getValue());
for (Label label : getAspectLabels((Rule) target, entry.getKey(), entry.getValue(), value, env)) {
depKeys.add(getKey(label));
}
}
}
return depKeys;
}
use of com.google.devtools.build.lib.packages.NoSuchTargetException in project bazel by bazelbuild.
the class TransitiveBaseTraversalFunction method compute.
@Override
public SkyValue compute(SkyKey key, Environment env) throws TransitiveBaseTraversalFunctionException, InterruptedException {
Label label = (Label) key.argument();
LoadTargetResults loadTargetResults;
try {
loadTargetResults = loadTarget(env, label);
} catch (NoSuchTargetException e) {
throw new TransitiveBaseTraversalFunctionException(e);
} catch (NoSuchPackageException e) {
throw new TransitiveBaseTraversalFunctionException(e);
}
LoadTargetResultsType loadTargetResultsType = loadTargetResults.getType();
if (loadTargetResultsType.equals(LoadTargetResultsType.VALUES_MISSING)) {
return null;
}
Preconditions.checkState(loadTargetResultsType.equals(LoadTargetResultsType.TARGET_AND_ERROR_IF_ANY), loadTargetResultsType);
TargetAndErrorIfAny targetAndErrorIfAny = (TargetAndErrorIfAny) loadTargetResults;
TProcessedTargets processedTargets = processTarget(label, targetAndErrorIfAny);
// Process deps from attributes.
Iterable<SkyKey> labelDepKeys = getLabelDepKeys(targetAndErrorIfAny.getTarget());
Map<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>> depMap = env.getValuesOrThrow(labelDepKeys, NoSuchPackageException.class, NoSuchTargetException.class);
processDeps(processedTargets, env.getListener(), targetAndErrorIfAny, depMap.entrySet());
if (env.valuesMissing()) {
return null;
}
// Process deps from aspects.
Iterable<SkyKey> labelAspectKeys = getStrictLabelAspectKeys(targetAndErrorIfAny.getTarget(), depMap, env);
Set<Entry<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>>> labelAspectEntries = env.getValuesOrThrow(labelAspectKeys, NoSuchPackageException.class, NoSuchTargetException.class).entrySet();
processDeps(processedTargets, env.getListener(), targetAndErrorIfAny, labelAspectEntries);
if (env.valuesMissing()) {
return null;
}
return computeSkyValue(targetAndErrorIfAny, processedTargets);
}
use of com.google.devtools.build.lib.packages.NoSuchTargetException in project bazel by bazelbuild.
the class TransitiveTargetFunction method computeSkyValue.
@Override
public SkyValue computeSkyValue(TargetAndErrorIfAny targetAndErrorIfAny, TransitiveTargetValueBuilder builder) {
Target target = targetAndErrorIfAny.getTarget();
NoSuchTargetException errorLoadingTarget = targetAndErrorIfAny.getErrorLoadingTarget();
// Get configuration fragments directly required by this rule.
if (target instanceof Rule) {
Rule rule = (Rule) target;
// Declared by the rule class:
ConfigurationFragmentPolicy configurationFragmentPolicy = rule.getRuleClassObject().getConfigurationFragmentPolicy();
for (ConfigurationFragmentFactory factory : ruleClassProvider.getConfigurationFragments()) {
Class<? extends Fragment> fragment = factory.creates();
// (named) fragments.
if (configurationFragmentPolicy.isLegalConfigurationFragment(fragment)) {
addFragmentIfNew(builder, fragment.asSubclass(BuildConfiguration.Fragment.class));
}
}
// Declared by late-bound attributes:
for (Attribute attr : rule.getAttributes()) {
if (attr.isLateBound()) {
addFragmentsIfNew(builder, attr.getLateBoundDefault().getRequiredConfigurationFragments());
}
}
// corresponding fragments in their configurations to properly resolve:
if (rule.getRuleClass().equals(ConfigSettingRule.RULE_NAME)) {
addFragmentsIfNew(builder, ConfigSettingRule.requiresConfigurationFragments(rule, optionsToFragmentMap));
}
// Fragments to unconditionally include:
addFragmentIfNew(builder, ruleClassProvider.getUniversalFragment().asSubclass(BuildConfiguration.Fragment.class));
}
return builder.build(errorLoadingTarget);
}
use of com.google.devtools.build.lib.packages.NoSuchTargetException in project bazel by bazelbuild.
the class TransitiveTraversalFunction method processTarget.
@Override
FirstErrorMessageAccumulator processTarget(Label label, TargetAndErrorIfAny targetAndErrorIfAny) {
NoSuchTargetException errorIfAny = targetAndErrorIfAny.getErrorLoadingTarget();
String errorMessageIfAny = errorIfAny == null ? null : errorIfAny.getMessage();
return new FirstErrorMessageAccumulator(errorMessageIfAny);
}
Aggregations