use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class AarImportTest method testResourcesProvided.
@Test
public void testResourcesProvided() throws Exception {
ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:foo");
NestedSet<ResourceContainer> directResources = aarImportTarget.getProvider(AndroidResourcesProvider.class).getDirectAndroidResources();
assertThat(directResources).hasSize(1);
ResourceContainer resourceContainer = directResources.iterator().next();
assertThat(resourceContainer.getManifest()).isNotNull();
Iterable<Artifact> resourceArtifacts = resourceContainer.getArtifacts();
assertThat(resourceArtifacts).hasSize(1);
Artifact resourceTreeArtifact = resourceArtifacts.iterator().next();
assertThat(resourceTreeArtifact.isTreeArtifact()).isTrue();
assertThat(resourceTreeArtifact.getExecPathString()).endsWith("_aar/unzipped/resources/foo");
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class AndroidSdkRepositoryTest method testMultipleAndroidSdkApiLevels.
@Test
public void testMultipleAndroidSdkApiLevels() throws Exception {
int[] apiLevels = { 23, 24, 25 };
scratchPlatformsDirectories(apiLevels);
scratchBuildToolsDirectories("25.0.1");
FileSystemUtils.appendIsoLatin1(scratch.resolve("WORKSPACE"), "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')", "android_sdk_repository(", " name = 'androidsdk',", " path = '/sdk',", " api_level = 24,", " build_tools_version = '25.0.1',", ")");
invalidatePackages();
for (int apiLevel : apiLevels) {
ConfiguredTarget androidSdk = getConfiguredTarget("@androidsdk//:sdk-" + apiLevel);
assertThat(androidSdk).isNotNull();
assertThat(androidSdk.getProvider(AndroidSdkProvider.class).getAndroidJar().getExecPathString()).isEqualTo(String.format("external/androidsdk/platforms/android-%d/android.jar", apiLevel));
}
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class AndroidSdkRepositoryTest method testBuildToolsHighestVersionDetection.
@Test
public void testBuildToolsHighestVersionDetection() throws Exception {
scratchPlatformsDirectories(25);
scratchBuildToolsDirectories("24.0.3", "25.0.1");
FileSystemUtils.appendIsoLatin1(scratch.resolve("WORKSPACE"), "local_repository(name = 'bazel_tools', path = '/bazel_tools_workspace')", "android_sdk_repository(", " name = 'androidsdk',", " path = '/sdk',", " api_level = 25,", ")");
invalidatePackages();
ConfiguredTarget androidSdk = getConfiguredTarget("@androidsdk//:sdk");
assertThat(androidSdk).isNotNull();
assertThat(androidSdk.getProvider(AndroidSdkProvider.class).getBuildToolsVersion()).isEqualTo("25.0.1");
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class BuildResultPrinter method showBuildResult.
/**
* Shows the result of the build. Information includes the list of up-to-date
* and failed targets and list of output artifacts for successful targets
*
* <p>This corresponds to the --show_result flag.
*/
public void showBuildResult(BuildRequest request, BuildResult result, Collection<ConfiguredTarget> configuredTargets, Collection<AspectValue> aspects) {
// NOTE: be careful what you print! We don't want to create a consistency
// problem where the summary message and the exit code disagree. The logic
// here is already complex.
Collection<ConfiguredTarget> targetsToPrint = filterTargetsToPrint(configuredTargets);
Collection<AspectValue> aspectsToPrint = filterAspectsToPrint(aspects);
// Filter the targets we care about into two buckets:
Collection<ConfiguredTarget> succeeded = new ArrayList<>();
Collection<ConfiguredTarget> failed = new ArrayList<>();
for (ConfiguredTarget target : targetsToPrint) {
Collection<ConfiguredTarget> successfulTargets = result.getSuccessfulTargets();
(successfulTargets.contains(target) ? succeeded : failed).add(target);
}
// Suppress summary if --show_result value is exceeded:
if (succeeded.size() + failed.size() + aspectsToPrint.size() > request.getBuildOptions().maxResultTargets) {
return;
}
OutErr outErr = request.getOutErr();
TopLevelArtifactContext context = request.getTopLevelArtifactContext();
for (ConfiguredTarget target : succeeded) {
Label label = target.getLabel();
// For up-to-date targets report generated artifacts, but only
// if they have associated action and not middleman artifacts.
boolean headerFlag = true;
for (Artifact artifact : TopLevelArtifactHelper.getAllArtifactsToBuild(target, context).getImportantArtifacts()) {
if (shouldPrint(artifact)) {
if (headerFlag) {
outErr.printErr("Target " + label + " up-to-date:\n");
headerFlag = false;
}
outErr.printErrLn(formatArtifactForShowResults(artifact, request));
}
}
if (headerFlag) {
outErr.printErr("Target " + label + " up-to-date (nothing to build)\n");
}
}
for (AspectValue aspect : aspectsToPrint) {
Label label = aspect.getLabel();
String aspectName = aspect.getConfiguredAspect().getName();
boolean headerFlag = true;
NestedSet<Artifact> importantArtifacts = TopLevelArtifactHelper.getAllArtifactsToBuild(aspect, context).getImportantArtifacts();
for (Artifact importantArtifact : importantArtifacts) {
if (headerFlag) {
outErr.printErr("Aspect " + aspectName + " of " + label + " up-to-date:\n");
headerFlag = false;
}
if (shouldPrint(importantArtifact)) {
outErr.printErrLn(formatArtifactForShowResults(importantArtifact, request));
}
}
if (headerFlag) {
outErr.printErr("Aspect " + aspectName + " of " + label + " up-to-date (nothing to build)\n");
}
}
for (ConfiguredTarget target : failed) {
outErr.printErr("Target " + target.getLabel() + " failed to build\n");
// For failed compilation, it is still useful to examine temp artifacts,
// (ie, preprocessed and assembler files).
OutputGroupProvider topLevelProvider = target.getProvider(OutputGroupProvider.class);
String productName = env.getRuntime().getProductName();
if (topLevelProvider != null) {
for (Artifact temp : topLevelProvider.getOutputGroup(OutputGroupProvider.TEMP_FILES)) {
if (temp.getPath().exists()) {
outErr.printErrLn(" See temp at " + OutputDirectoryLinksUtils.getPrettyPath(temp.getPath(), env.getWorkspaceName(), env.getWorkspace(), request.getBuildOptions().getSymlinkPrefix(productName), productName));
}
}
}
}
if (!failed.isEmpty() && !request.getOptions(ExecutionOptions.class).verboseFailures) {
outErr.printErr("Use --verbose_failures to see the command lines of failed build steps.\n");
}
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class BuildTool method checkTargetEnvironmentRestrictions.
/**
* Checks that if this is an environment-restricted build, all top-level targets support the
* expected environments.
*
* @param topLevelTargets the build's top-level targets
* @throws ViewCreationFailedException if constraint enforcement is on, the build declares
* environment-restricted top level configurations, and any top-level target doesn't support
* the expected environments
*/
private static void checkTargetEnvironmentRestrictions(Iterable<ConfiguredTarget> topLevelTargets, LoadedPackageProvider packageManager) throws ViewCreationFailedException, InterruptedException {
for (ConfiguredTarget topLevelTarget : topLevelTargets) {
BuildConfiguration config = topLevelTarget.getConfiguration();
if (config == null) {
// TODO(bazel-team): support file targets (they should apply package-default constraints).
continue;
} else if (!config.enforceConstraints() || config.getTargetEnvironments().isEmpty()) {
continue;
}
// Parse and collect this configuration's environments.
EnvironmentCollection.Builder builder = new EnvironmentCollection.Builder();
for (Label envLabel : config.getTargetEnvironments()) {
try {
Target env = packageManager.getLoadedTarget(envLabel);
builder.put(ConstraintSemantics.getEnvironmentGroup(env), envLabel);
} catch (NoSuchPackageException | NoSuchTargetException | ConstraintSemantics.EnvironmentLookupException e) {
throw new ViewCreationFailedException("invalid target environment", e);
}
}
EnvironmentCollection expectedEnvironments = builder.build();
// Now check the target against those environments.
SupportedEnvironmentsProvider provider = Verify.verifyNotNull(topLevelTarget.getProvider(SupportedEnvironmentsProvider.class));
Collection<Label> missingEnvironments = ConstraintSemantics.getUnsupportedEnvironments(provider.getRefinedEnvironments(), expectedEnvironments);
if (!missingEnvironments.isEmpty()) {
throw new ViewCreationFailedException(String.format("This is a restricted-environment build. %s does not support" + " required environment%s %s", topLevelTarget.getLabel(), missingEnvironments.size() == 1 ? "" : "s", Joiner.on(", ").join(missingEnvironments)));
}
}
}
Aggregations