use of com.google.devtools.build.lib.events.Location in project bazel by bazelbuild.
the class CircularDependencyTest method testThreeLongPackageGroupCycle.
@Test
public void testThreeLongPackageGroupCycle() throws Exception {
String expectedEvent = "cycle in dependency graph:\n" + " //cycle:superman\n" + ".-> //cycle:rock\n" + "| //cycle:paper\n" + "| //cycle:scissors\n" + "`-- //cycle:rock";
checkError("cycle", "superman", expectedEvent, "# dummy line", "package_group(name='paper', includes=['//cycle:scissors'])", "package_group(name='rock', includes=['//cycle:paper'])", "package_group(name='scissors', includes=['//cycle:rock'])", "sh_library(name='superman', visibility=[':rock'])");
Event foundEvent = null;
for (Event event : eventCollector) {
if (event.getMessage().contains(expectedEvent)) {
foundEvent = event;
break;
}
}
assertNotNull(foundEvent);
Location location = foundEvent.getLocation();
assertEquals(3, location.getStartLineAndColumn().getLine());
assertEquals("/workspace/cycle/BUILD", location.getPath().toString());
}
use of com.google.devtools.build.lib.events.Location in project bazel by bazelbuild.
the class SkylarkRuleConfiguredTargetBuilder method parseProviderKeys.
private static void parseProviderKeys(SkylarkClassObject provider, Boolean isDefaultProvider, RuleContext ruleContext, Location loc, Artifact executable, Map<String, Class<? extends TransitiveInfoProvider>> registeredProviderTypes, RuleConfiguredTargetBuilder builder) throws EvalException {
Runfiles statelessRunfiles = null;
Runfiles dataRunfiles = null;
Runfiles defaultRunfiles = null;
for (String key : provider.getKeys()) {
if (key.equals("files")) {
// If we specify files_to_build we don't have the executable in it by default.
builder.setFilesToBuild(cast("files", provider, SkylarkNestedSet.class, Artifact.class, loc).getSet(Artifact.class));
} else if (key.equals("runfiles")) {
statelessRunfiles = cast("runfiles", provider, Runfiles.class, loc);
} else if (key.equals("data_runfiles")) {
dataRunfiles = cast("data_runfiles", provider, Runfiles.class, loc);
} else if (key.equals("default_runfiles")) {
defaultRunfiles = cast("default_runfiles", provider, Runfiles.class, loc);
} else if (key.equals("output_groups")) {
addOutputGroups(provider.getValue(key), loc, builder);
} else if (key.equals("instrumented_files")) {
SkylarkClassObject insStruct = cast("instrumented_files", provider, SkylarkClassObject.class, loc);
Location insLoc = insStruct.getCreationLoc();
FileTypeSet fileTypeSet = FileTypeSet.ANY_FILE;
if (insStruct.getKeys().contains("extensions")) {
@SuppressWarnings("unchecked") List<String> exts = cast("extensions", insStruct, SkylarkList.class, String.class, insLoc);
if (exts.isEmpty()) {
fileTypeSet = FileTypeSet.NO_FILE;
} else {
FileType[] fileTypes = new FileType[exts.size()];
for (int i = 0; i < fileTypes.length; i++) {
fileTypes[i] = FileType.of(exts.get(i));
}
fileTypeSet = FileTypeSet.of(fileTypes);
}
}
List<String> dependencyAttributes = Collections.emptyList();
if (insStruct.getKeys().contains("dependency_attributes")) {
dependencyAttributes = cast("dependency_attributes", insStruct, SkylarkList.class, String.class, insLoc);
}
List<String> sourceAttributes = Collections.emptyList();
if (insStruct.getKeys().contains("source_attributes")) {
sourceAttributes = cast("source_attributes", insStruct, SkylarkList.class, String.class, insLoc);
}
InstrumentationSpec instrumentationSpec = new InstrumentationSpec(fileTypeSet).withSourceAttributes(sourceAttributes.toArray(new String[0])).withDependencyAttributes(dependencyAttributes.toArray(new String[0]));
InstrumentedFilesProvider instrumentedFilesProvider = InstrumentedFilesCollector.collect(ruleContext, instrumentationSpec, InstrumentedFilesCollector.NO_METADATA_COLLECTOR, Collections.<Artifact>emptySet());
builder.addProvider(InstrumentedFilesProvider.class, instrumentedFilesProvider);
} else if (registeredProviderTypes.containsKey(key)) {
Class<? extends TransitiveInfoProvider> providerType = registeredProviderTypes.get(key);
TransitiveInfoProvider providerField = cast(key, provider, providerType, loc);
builder.addProvider(providerType, providerField);
} else if (isDefaultProvider) {
// Custom keys are not allowed for default providers
throw new EvalException(loc, "Invalid key for default provider: " + key);
} else if (key.equals("providers")) {
Iterable iterable = cast(key, provider, Iterable.class, loc);
for (Object o : iterable) {
SkylarkClassObject declaredProvider = SkylarkType.cast(o, SkylarkClassObject.class, loc, "The value of 'providers' should be a sequence of declared providers");
builder.addSkylarkDeclaredProvider(declaredProvider, loc);
}
} else if (!key.equals("executable")) {
// We handled executable already.
builder.addSkylarkTransitiveInfo(key, provider.getValue(key), loc);
}
}
addSimpleProviders(builder, ruleContext, loc, executable, statelessRunfiles, dataRunfiles, defaultRunfiles, (isDefaultProvider ? provider : null));
}
use of com.google.devtools.build.lib.events.Location in project bazel by bazelbuild.
the class AttributeContainerTest method testAttributeLocation.
@Test
public void testAttributeLocation() throws Exception {
Location location1 = newLocation();
Location location2 = newLocation();
container.setAttributeLocation(attribute1, location1);
container.setAttributeLocation(attribute2, location2);
assertEquals(location1, container.getAttributeLocation(attribute1.getName()));
assertEquals(location2, container.getAttributeLocation(attribute2.getName()));
assertNull(container.getAttributeLocation("nomatch"));
}
use of com.google.devtools.build.lib.events.Location in project bazel by bazelbuild.
the class BlazeCommandEventHandler method handle.
/** See EventHandler.handle. */
@Override
public void handle(Event event) {
if (!eventMask.contains(event.getKind())) {
return;
}
String prefix;
switch(event.getKind()) {
case STDOUT:
putOutput(outErr.getOutputStream(), event);
return;
case STDERR:
putOutput(outErr.getErrorStream(), event);
return;
case PASS:
case FAIL:
case TIMEOUT:
case ERROR:
case WARNING:
case DEPCHECKER:
prefix = event.getKind() + ": ";
break;
case SUBCOMMAND:
prefix = ">>>>>>>>> ";
break;
case INFO:
case PROGRESS:
case START:
case FINISH:
prefix = "____";
break;
default:
throw new IllegalStateException("" + event.getKind());
}
StringBuilder buf = new StringBuilder();
buf.append(prefix);
if (showTimestamp) {
buf.append(timestamp());
}
Location location = event.getLocation();
if (location != null) {
buf.append(location.print()).append(": ");
}
buf.append(event.getMessage());
if (event.getKind() == EventKind.FINISH) {
buf.append(" DONE");
}
// typically English sentences composed from exception messages.
if (event.getKind() == EventKind.WARNING || event.getKind() == EventKind.ERROR) {
buf.append('.');
}
// Event messages go to stderr; results (e.g. 'blaze query') go to stdout.
errPrintStream.println(buf);
}
use of com.google.devtools.build.lib.events.Location in project bazel by bazelbuild.
the class SkylarkAspectFactory method addDeclaredProviders.
private void addDeclaredProviders(ConfiguredAspect.Builder builder, Iterable aspectSkylarkObject) throws EvalException {
for (Object o : aspectSkylarkObject) {
Location loc = skylarkAspect.getImplementation().getLocation();
SkylarkClassObject declaredProvider = SkylarkType.cast(o, SkylarkClassObject.class, loc, "A return value of an aspect implementation function should be " + "a sequence of declared providers");
Location creationLoc = declaredProvider.getCreationLocOrNull();
builder.addSkylarkDeclaredProvider(declaredProvider, creationLoc != null ? creationLoc : loc);
}
}
Aggregations