use of com.google.devtools.build.lib.cmdline.TargetParsingException 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.cmdline.TargetParsingException in project bazel by bazelbuild.
the class PrepareDepsOfPatternsFunction method getSkyKeys.
public static ImmutableList<SkyKey> getSkyKeys(SkyKey skyKey, EventHandler eventHandler) {
TargetPatternSequence targetPatternSequence = (TargetPatternSequence) skyKey.argument();
Iterable<PrepareDepsOfPatternSkyKeyOrException> keysMaybe = PrepareDepsOfPatternValue.keys(targetPatternSequence.getPatterns(), targetPatternSequence.getOffset());
ImmutableList.Builder<SkyKey> skyKeyBuilder = ImmutableList.builder();
boolean handlerIsParseFailureListener = eventHandler instanceof ParseFailureListener;
for (PrepareDepsOfPatternSkyKeyOrException skyKeyOrException : keysMaybe) {
try {
skyKeyBuilder.add(skyKeyOrException.getSkyKey());
} catch (TargetParsingException e) {
handleTargetParsingException(eventHandler, handlerIsParseFailureListener, skyKeyOrException.getOriginalPattern(), e);
}
}
return skyKeyBuilder.build();
}
use of com.google.devtools.build.lib.cmdline.TargetParsingException in project bazel by bazelbuild.
the class SkyframeTargetPatternEvaluator method parseTargetPatternList.
/**
* Loads a list of target patterns (eg, "foo/..."). When policy is set to FILTER_TESTS,
* test_suites are going to be expanded.
*/
ResolvedTargets<Target> parseTargetPatternList(String offset, ExtendedEventHandler eventHandler, List<String> targetPatterns, FilteringPolicy policy, boolean keepGoing) throws InterruptedException, TargetParsingException {
Iterable<TargetPatternSkyKeyOrException> keysMaybe = TargetPatternValue.keys(targetPatterns, policy, offset);
ImmutableList.Builder<SkyKey> builder = ImmutableList.builder();
for (TargetPatternSkyKeyOrException skyKeyOrException : keysMaybe) {
try {
builder.add(skyKeyOrException.getSkyKey());
} catch (TargetParsingException e) {
if (!keepGoing) {
throw e;
}
String pattern = skyKeyOrException.getOriginalPattern();
eventHandler.handle(Event.error("Skipping '" + pattern + "': " + e.getMessage()));
if (eventHandler instanceof ParseFailureListener) {
((ParseFailureListener) eventHandler).parsingError(pattern, e.getMessage());
}
}
}
ImmutableList<SkyKey> skyKeys = builder.build();
return parseTargetPatternKeys(targetPatterns, skyKeys, SkyframeExecutor.DEFAULT_THREAD_COUNT, keepGoing, eventHandler, createTargetPatternEvaluatorUtil(policy, eventHandler, keepGoing));
}
use of com.google.devtools.build.lib.cmdline.TargetParsingException in project bazel by bazelbuild.
the class BuildTool method processRequest.
/**
* The crux of the build system. Builds the targets specified in the request using the specified
* Executor.
*
* <p>Performs loading, analysis and execution for the specified set of targets, honoring the
* configuration options in the BuildRequest. Returns normally iff successful, throws an exception
* otherwise.
*
* <p>The caller is responsible for setting up and syncing the package cache.
*
* <p>During this function's execution, the actualTargets and successfulTargets
* fields of the request object are set.
*
* @param request the build request that this build tool is servicing, which specifies various
* options; during this method's execution, the actualTargets and successfulTargets fields
* of the request object are populated
* @param validator target validator
* @return the result as a {@link BuildResult} object
*/
public BuildResult processRequest(BuildRequest request, TargetValidator validator) {
BuildResult result = new BuildResult(request.getStartTime());
env.getEventBus().register(result);
maybeSetStopOnFirstFailure(request, result);
Throwable catastrophe = null;
ExitCode exitCode = ExitCode.BLAZE_INTERNAL_ERROR;
try {
buildTargets(request, result, validator);
exitCode = ExitCode.SUCCESS;
} catch (BuildFailedException e) {
if (e.isErrorAlreadyShown()) {
// The actual error has already been reported by the Builder.
} else {
reportExceptionError(e);
}
if (e.isCatastrophic()) {
result.setCatastrophe();
}
exitCode = e.getExitCode() != null ? e.getExitCode() : ExitCode.BUILD_FAILURE;
} catch (InterruptedException e) {
// We may have been interrupted by an error, or the user's interruption may have raced with
// an error, so check to see if we should report that error code instead.
exitCode = env.getPendingExitCode();
if (exitCode == null) {
exitCode = ExitCode.INTERRUPTED;
env.getReporter().handle(Event.error("build interrupted"));
env.getEventBus().post(new BuildInterruptedEvent());
} else {
// Report the exception from the environment - the exception we're handling here is just an
// interruption.
reportExceptionError(env.getPendingException());
result.setCatastrophe();
}
} catch (TargetParsingException | LoadingFailedException | ViewCreationFailedException e) {
exitCode = ExitCode.PARSING_FAILURE;
reportExceptionError(e);
} catch (TestExecException e) {
// ExitCode.SUCCESS means that build was successful. Real return code of program
// is going to be calculated in TestCommand.doTest().
exitCode = ExitCode.SUCCESS;
reportExceptionError(e);
} catch (InvalidConfigurationException e) {
exitCode = ExitCode.COMMAND_LINE_ERROR;
reportExceptionError(e);
// TODO(gregce): With "global configurations" we cannot tie a configuration creation failure
// to a single target and have to halt the entire build. Once configurations are genuinely
// created as part of the analysis phase they should report their error on the level of the
// target(s) that triggered them.
result.setCatastrophe();
} catch (AbruptExitException e) {
exitCode = e.getExitCode();
reportExceptionError(e);
result.setCatastrophe();
} catch (Throwable throwable) {
catastrophe = throwable;
Throwables.propagate(throwable);
} finally {
stopRequest(result, catastrophe, exitCode);
}
return result;
}
use of com.google.devtools.build.lib.cmdline.TargetParsingException in project bazel by bazelbuild.
the class TargetPatternPhaseFunction method determineTests.
/**
* Interpret test target labels from the command-line arguments and return the corresponding set
* of targets, handling the filter flags, and expanding test suites.
*
* @param targetPatterns the list of command-line target patterns specified by the user
* @param testFilter the test filter
*/
private static ResolvedTargets<Target> determineTests(Environment env, List<String> targetPatterns, String offset, TestFilter testFilter) throws InterruptedException {
List<SkyKey> patternSkyKeys = new ArrayList<>();
for (TargetPatternSkyKeyOrException keyOrException : TargetPatternValue.keys(targetPatterns, FilteringPolicies.FILTER_TESTS, offset)) {
try {
patternSkyKeys.add(keyOrException.getSkyKey());
} catch (TargetParsingException e) {
// Skip.
}
}
Map<SkyKey, ValueOrException<TargetParsingException>> resolvedPatterns = env.getValuesOrThrow(patternSkyKeys, TargetParsingException.class);
if (env.valuesMissing()) {
return null;
}
List<SkyKey> expandedSuiteKeys = new ArrayList<>();
for (SkyKey key : patternSkyKeys) {
TargetPatternValue value;
try {
value = (TargetPatternValue) resolvedPatterns.get(key).get();
} catch (TargetParsingException e) {
// Skip.
continue;
}
expandedSuiteKeys.add(TestSuiteExpansionValue.key(value.getTargets().getTargets()));
}
Map<SkyKey, SkyValue> expandedSuites = env.getValues(expandedSuiteKeys);
if (env.valuesMissing()) {
return null;
}
ResolvedTargets.Builder<Target> testTargetsBuilder = ResolvedTargets.builder();
for (SkyKey key : patternSkyKeys) {
TargetPatternKey pattern = (TargetPatternKey) key.argument();
TargetPatternValue value;
try {
value = (TargetPatternValue) resolvedPatterns.get(key).get();
} catch (TargetParsingException e) {
// This was already reported in getTargetsToBuild (maybe merge the two code paths?).
continue;
}
TestSuiteExpansionValue expandedSuitesValue = (TestSuiteExpansionValue) expandedSuites.get(TestSuiteExpansionValue.key(value.getTargets().getTargets()));
if (pattern.isNegative()) {
ResolvedTargets<Target> negativeTargets = expandedSuitesValue.getTargets();
testTargetsBuilder.filter(Predicates.not(Predicates.in(negativeTargets.getTargets())));
testTargetsBuilder.mergeError(negativeTargets.hasError());
} else {
ResolvedTargets<Target> positiveTargets = expandedSuitesValue.getTargets();
testTargetsBuilder.addAll(positiveTargets.getTargets());
testTargetsBuilder.mergeError(positiveTargets.hasError());
}
}
testTargetsBuilder.filter(testFilter);
return testTargetsBuilder.build();
}
Aggregations