use of com.google.devtools.build.lib.skyframe.EnvironmentBackedRecursivePackageProvider.MissingDepException in project bazel by bazelbuild.
the class TargetPatternFunction method compute.
@Override
public SkyValue compute(SkyKey key, Environment env) throws TargetPatternFunctionException, InterruptedException {
TargetPatternValue.TargetPatternKey patternKey = ((TargetPatternValue.TargetPatternKey) key.argument());
ResolvedTargets<Target> resolvedTargets;
try {
EnvironmentBackedRecursivePackageProvider provider = new EnvironmentBackedRecursivePackageProvider(env);
RecursivePackageProviderBackedTargetPatternResolver resolver = new RecursivePackageProviderBackedTargetPatternResolver(provider, env.getListener(), patternKey.getPolicy(), MultisetSemaphore.<PackageIdentifier>unbounded());
TargetPattern parsedPattern = patternKey.getParsedPattern();
ImmutableSet<PathFragment> excludedSubdirectories = patternKey.getExcludedSubdirectories();
final Set<Target> results = CompactHashSet.create();
BatchCallback<Target, RuntimeException> callback = new BatchCallback<Target, RuntimeException>() {
@Override
public void process(Iterable<Target> partialResult) {
Iterables.addAll(results, partialResult);
}
};
parsedPattern.eval(resolver, excludedSubdirectories, callback, RuntimeException.class);
resolvedTargets = ResolvedTargets.<Target>builder().addAll(results).build();
} catch (TargetParsingException e) {
throw new TargetPatternFunctionException(e);
} catch (MissingDepException e) {
// implementations that are unconcerned with MissingDepExceptions.
return null;
}
Preconditions.checkNotNull(resolvedTargets, key);
ResolvedTargets.Builder<Label> resolvedLabelsBuilder = ResolvedTargets.builder();
for (Target target : resolvedTargets.getTargets()) {
resolvedLabelsBuilder.add(target.getLabel());
}
for (Target target : resolvedTargets.getFilteredTargets()) {
resolvedLabelsBuilder.remove(target.getLabel());
}
return new TargetPatternValue(resolvedLabelsBuilder.build());
}
use of com.google.devtools.build.lib.skyframe.EnvironmentBackedRecursivePackageProvider.MissingDepException in project bazel by bazelbuild.
the class PrepareDepsOfPatternFunction method compute.
@Nullable
@Override
public SkyValue compute(SkyKey key, Environment env) throws SkyFunctionException, InterruptedException {
TargetPatternValue.TargetPatternKey patternKey = ((TargetPatternValue.TargetPatternKey) key.argument());
// DepsOfPatternPreparer below expects to be able to ignore the filtering policy from the
// TargetPatternKey, which should be valid because PrepareDepsOfPatternValue.keys
// unconditionally creates TargetPatternKeys with the NO_FILTER filtering policy. (Compare
// with SkyframeTargetPatternEvaluator, which can create TargetPatternKeys with other
// filtering policies like FILTER_TESTS or FILTER_MANUAL.) This check makes sure that the
// key's filtering policy is NO_FILTER as expected.
Preconditions.checkState(patternKey.getPolicy().equals(FilteringPolicies.NO_FILTER), patternKey.getPolicy());
TargetPattern parsedPattern = patternKey.getParsedPattern();
BlacklistedPackagePrefixesValue blacklist = (BlacklistedPackagePrefixesValue) env.getValue(BlacklistedPackagePrefixesValue.key());
if (blacklist == null) {
return null;
}
ImmutableSet<PathFragment> subdirectoriesToExclude = patternKey.getAllSubdirectoriesToExclude(blacklist.getPatterns());
DepsOfPatternPreparer preparer = new DepsOfPatternPreparer(env, pkgPath.get());
try {
parsedPattern.eval(preparer, subdirectoriesToExclude, NullCallback.<Void>instance(), RuntimeException.class);
} catch (TargetParsingException e) {
throw new PrepareDepsOfPatternFunctionException(e);
} catch (MissingDepException e) {
// when it has a dependency on a missing Environment value.
return null;
}
return PrepareDepsOfPatternValue.INSTANCE;
}
use of com.google.devtools.build.lib.skyframe.EnvironmentBackedRecursivePackageProvider.MissingDepException in project bazel by bazelbuild.
the class TargetPatternPhaseFunction method getTargetsToBuild.
/**
* Interpret the command-line arguments.
*
* @param options the command-line arguments in structured form
*/
private static ResolvedTargets<Target> getTargetsToBuild(Environment env, TargetPatternList options) throws InterruptedException {
List<SkyKey> patternSkyKeys = new ArrayList<>();
for (TargetPatternSkyKeyOrException keyOrException : TargetPatternValue.keys(options.getTargetPatterns(), FilteringPolicies.FILTER_MANUAL, options.getOffset())) {
try {
patternSkyKeys.add(keyOrException.getSkyKey());
} catch (TargetParsingException e) {
// Skip.
}
}
Map<SkyKey, ValueOrException<TargetParsingException>> resolvedPatterns = env.getValuesOrThrow(patternSkyKeys, TargetParsingException.class);
if (env.valuesMissing()) {
return null;
}
ResolvedTargets.Builder<Target> builder = ResolvedTargets.builder();
for (SkyKey key : patternSkyKeys) {
TargetPatternKey pattern = (TargetPatternKey) key.argument();
TargetPatternValue value;
try {
value = (TargetPatternValue) resolvedPatterns.get(key).get();
} catch (TargetParsingException e) {
// TODO(ulfjack): Report to EventBus.
String rawPattern = pattern.getPattern();
String errorMessage = e.getMessage();
env.getListener().handle(Event.error("Skipping '" + rawPattern + "': " + errorMessage));
builder.setError();
continue;
}
// TODO(ulfjack): This is terribly inefficient.
ResolvedTargets<Target> asTargets = TestSuiteExpansionFunction.labelsToTargets(env, value.getTargets().getTargets(), value.getTargets().hasError());
if (pattern.isNegative()) {
builder.filter(Predicates.not(Predicates.in(asTargets.getTargets())));
} else {
builder.merge(asTargets);
}
}
ResolvedTargets<Target> result = builder.filter(TargetUtils.tagFilter(options.getBuildTargetFilter())).build();
if (options.getCompileOneDependency()) {
TargetProvider targetProvider = new EnvironmentBackedRecursivePackageProvider(env);
try {
return new CompileOneDependencyTransformer(targetProvider).transformCompileOneDependency(env.getListener(), result);
} catch (MissingDepException e) {
return null;
} catch (TargetParsingException e) {
env.getListener().handle(Event.error(e.getMessage()));
return ResolvedTargets.failed();
}
}
return result;
}
Aggregations