use of com.google.devtools.build.lib.actions.extra.ExtraActionInfo in project bazel by bazelbuild.
the class CcLibraryConfiguredTargetTest method testCppLinkActionExtraActionInfoWithSharedLibraries.
@Test
public void testCppLinkActionExtraActionInfoWithSharedLibraries() throws Exception {
useConfiguration("--cpu=k8");
ConfiguredTarget hello = getConfiguredTarget("//hello:hello");
Artifact sharedObject = FileType.filter(getFilesToBuild(hello), CppFileTypes.SHARED_LIBRARY).iterator().next();
CppLinkAction action = (CppLinkAction) getGeneratingAction(sharedObject);
ExtraActionInfo.Builder builder = action.getExtraActionInfo();
ExtraActionInfo info = builder.build();
assertEquals("CppLink", info.getMnemonic());
CppLinkInfo cppLinkInfo = info.getExtension(CppLinkInfo.cppLinkInfo);
assertNotNull(cppLinkInfo);
Iterable<String> inputs = Artifact.asExecPaths(LinkerInputs.toLibraryArtifacts(action.getLinkCommandLine().getLinkerInputs()));
assertThat(cppLinkInfo.getInputFileList()).containsExactlyElementsIn(inputs);
assertEquals(action.getPrimaryOutput().getExecPathString(), cppLinkInfo.getOutputFile());
assertEquals(action.getLinkCommandLine().getLinkTargetType().name(), cppLinkInfo.getLinkTargetType());
assertEquals(action.getLinkCommandLine().getLinkStaticness().name(), cppLinkInfo.getLinkStaticness());
Iterable<String> linkstamps = Artifact.asExecPaths(action.getLinkCommandLine().getLinkstamps().values());
assertThat(cppLinkInfo.getLinkStampList()).containsExactlyElementsIn(linkstamps);
Iterable<String> buildInfoHeaderArtifacts = Artifact.asExecPaths(action.getLinkCommandLine().getBuildInfoHeaderArtifacts());
assertThat(cppLinkInfo.getBuildInfoHeaderArtifactList()).containsExactlyElementsIn(buildInfoHeaderArtifacts);
assertThat(cppLinkInfo.getLinkOptList()).containsExactlyElementsIn(action.getLinkCommandLine().getRawLinkArgv());
}
use of com.google.devtools.build.lib.actions.extra.ExtraActionInfo in project bazel by bazelbuild.
the class SpawnActionTest method testGetExtraActionInfoOnAspects.
/**
* Tests that the ExtraActionInfo proto that's generated from an action, contains Aspect-related
* information.
*/
@Test
public void testGetExtraActionInfoOnAspects() throws Exception {
scratch.file("a/BUILD", "load('//a:def.bzl', 'testrule')", "testrule(name='a', deps=[':b'])", "testrule(name='b')");
scratch.file("a/def.bzl", "def _aspect_impl(target, ctx):", " f = ctx.new_file('foo.txt')", " ctx.action(outputs = [f], command = 'echo foo > \"$1\"')", " return struct(output=f)", "def _rule_impl(ctx):", " return struct(files=depset([artifact.output for artifact in ctx.attr.deps]))", "aspect1 = aspect(_aspect_impl, attr_aspects=['deps'], ", " attrs = {'parameter': attr.string(values = ['param_value'])})", "testrule = rule(_rule_impl, attrs = { ", " 'deps' : attr.label_list(aspects = [aspect1]), ", " 'parameter': attr.string(default='param_value') })");
update(ImmutableList.of("//a:a"), false, /* keepGoing */
1, /* loadingPhaseThreads */
true, /* doAnalysis */
new EventBus());
Artifact artifact = getOnlyElement(getFilesToBuild(getConfiguredTarget("//a:a")));
ExtraActionInfo.Builder extraActionInfo = getGeneratingAction(artifact).getExtraActionInfo();
assertThat(extraActionInfo.getAspectName()).isEqualTo("//a:def.bzl%aspect1");
assertThat(extraActionInfo.getAspectParametersMap()).containsExactly("parameter", ExtraActionInfo.StringList.newBuilder().addValue("param_value").build());
}
use of com.google.devtools.build.lib.actions.extra.ExtraActionInfo in project bazel by bazelbuild.
the class SpawnActionTest method testExtraActionInfo.
@Test
public void testExtraActionInfo() throws Exception {
SpawnAction action = createCopyFromWelcomeToDestination(ImmutableMap.<String, String>of());
ExtraActionInfo info = action.getExtraActionInfo().build();
assertEquals("Dummy", info.getMnemonic());
SpawnInfo spawnInfo = info.getExtension(SpawnInfo.spawnInfo);
assertNotNull(spawnInfo);
assertThat(spawnInfo.getArgumentList()).containsExactlyElementsIn(action.getArguments());
Iterable<String> inputPaths = Artifact.toExecPaths(action.getInputs());
Iterable<String> outputPaths = Artifact.toExecPaths(action.getOutputs());
assertThat(spawnInfo.getInputFileList()).containsExactlyElementsIn(inputPaths);
assertThat(spawnInfo.getOutputFileList()).containsExactlyElementsIn(outputPaths);
Map<String, String> environment = action.getEnvironment();
assertEquals(environment.size(), spawnInfo.getVariableCount());
for (EnvironmentVariable variable : spawnInfo.getVariableList()) {
assertThat(environment).containsEntry(variable.getName(), variable.getValue());
}
}
use of com.google.devtools.build.lib.actions.extra.ExtraActionInfo in project bazel by bazelbuild.
the class CcLibraryConfiguredTargetTest method testCppLinkActionExtraActionInfoWithoutSharedLibraries.
@Test
public void testCppLinkActionExtraActionInfoWithoutSharedLibraries() throws Exception {
useConfiguration("--nointerface_shared_objects");
ConfiguredTarget hello = getConfiguredTarget("//hello:hello");
Artifact sharedObject = getOnlyElement(FileType.filter(getFilesToBuild(hello), CppFileTypes.SHARED_LIBRARY));
CppLinkAction action = (CppLinkAction) getGeneratingAction(sharedObject);
ExtraActionInfo.Builder builder = action.getExtraActionInfo();
ExtraActionInfo info = builder.build();
assertEquals("CppLink", info.getMnemonic());
CppLinkInfo cppLinkInfo = info.getExtension(CppLinkInfo.cppLinkInfo);
assertNotNull(cppLinkInfo);
Iterable<String> inputs = Artifact.asExecPaths(LinkerInputs.toLibraryArtifacts(action.getLinkCommandLine().getLinkerInputs()));
assertThat(cppLinkInfo.getInputFileList()).containsExactlyElementsIn(inputs);
assertEquals(action.getPrimaryOutput().getExecPathString(), cppLinkInfo.getOutputFile());
assertFalse(cppLinkInfo.hasInterfaceOutputFile());
assertEquals(action.getLinkCommandLine().getLinkTargetType().name(), cppLinkInfo.getLinkTargetType());
assertEquals(action.getLinkCommandLine().getLinkStaticness().name(), cppLinkInfo.getLinkStaticness());
Iterable<String> linkstamps = Artifact.asExecPaths(action.getLinkCommandLine().getLinkstamps().values());
assertThat(cppLinkInfo.getLinkStampList()).containsExactlyElementsIn(linkstamps);
Iterable<String> buildInfoHeaderArtifacts = Artifact.asExecPaths(action.getLinkCommandLine().getBuildInfoHeaderArtifacts());
assertThat(cppLinkInfo.getBuildInfoHeaderArtifactList()).containsExactlyElementsIn(buildInfoHeaderArtifacts);
assertThat(cppLinkInfo.getLinkOptList()).containsExactlyElementsIn(action.getLinkCommandLine().getRawLinkArgv());
}
use of com.google.devtools.build.lib.actions.extra.ExtraActionInfo in project heron by twitter.
the class CppCheckstyle method getSourceFiles.
@SuppressWarnings("unchecked")
private static Collection<String> getSourceFiles(String extraActionFile) {
ExtraActionInfo info = ExtraActionUtils.getExtraActionInfo(extraActionFile);
CppCompileInfo cppInfo = info.getExtension(CppCompileInfo.cppCompileInfo);
return Collections2.filter(cppInfo.getSourcesAndHeadersList(), Predicates.and(Predicates.not(Predicates.containsPattern("third_party/")), Predicates.not(Predicates.containsPattern("config/heron-config.h")), Predicates.not(Predicates.containsPattern(".*pb.h$")), Predicates.not(Predicates.containsPattern(".*cc_wrapper.sh$")), Predicates.not(Predicates.containsPattern(".*pb.cc$"))));
}
Aggregations