Search in sources :

Example 51 with TransitiveInfoCollection

use of com.google.devtools.build.lib.analysis.TransitiveInfoCollection in project bazel by bazelbuild.

the class PyCommon method checkForSharedLibraries.

/**
   * Returns true if this target has an .so file in its transitive dependency closure.
   */
public static boolean checkForSharedLibraries(Iterable<TransitiveInfoCollection> deps) throws EvalException {
    for (TransitiveInfoCollection dep : deps) {
        SkylarkProviders providers = dep.getProvider(SkylarkProviders.class);
        SkylarkClassObject provider = null;
        if (providers != null) {
            provider = providers.getValue(PYTHON_SKYLARK_PROVIDER_NAME, SkylarkClassObject.class);
        }
        if (provider != null) {
            Boolean isUsingSharedLibrary = provider.getValue(IS_USING_SHARED_LIBRARY, Boolean.class);
            if (Boolean.TRUE.equals(isUsingSharedLibrary)) {
                return true;
            }
        } else if (FileType.contains(dep.getProvider(FileProvider.class).getFilesToBuild(), CppFileTypes.SHARED_LIBRARY)) {
            return true;
        }
    }
    return false;
}
Also used : SkylarkProviders(com.google.devtools.build.lib.analysis.SkylarkProviders) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) FileProvider(com.google.devtools.build.lib.analysis.FileProvider) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection)

Example 52 with TransitiveInfoCollection

use of com.google.devtools.build.lib.analysis.TransitiveInfoCollection in project bazel by bazelbuild.

the class PyCommon method collectTransitivePythonImports.

private void collectTransitivePythonImports(NestedSetBuilder<PathFragment> builder) {
    for (TransitiveInfoCollection dep : getTargetDeps()) {
        if (dep.getProvider(PythonImportsProvider.class) != null) {
            PythonImportsProvider provider = dep.getProvider(PythonImportsProvider.class);
            builder.addTransitive(provider.getTransitivePythonImports());
        }
    }
}
Also used : TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection)

Example 53 with TransitiveInfoCollection

use of com.google.devtools.build.lib.analysis.TransitiveInfoCollection in project bazel by bazelbuild.

the class TestResultAnalyzer method incrementalAnalyze.

/**
   * Incrementally updates a TestSummary given an existing summary
   * and a new TestResult. Only call on built targets.
   *
   * @param summaryBuilder Existing unbuilt test summary associated with a target.
   * @param result New test result to aggregate into the summary.
   * @return The updated TestSummary.
   */
public TestSummary.Builder incrementalAnalyze(TestSummary.Builder summaryBuilder, TestResult result) {
    // Cache retrieval should have been performed already.
    Preconditions.checkNotNull(result);
    Preconditions.checkNotNull(summaryBuilder);
    TestSummary existingSummary = Preconditions.checkNotNull(summaryBuilder.peek());
    TransitiveInfoCollection target = existingSummary.getTarget();
    Preconditions.checkNotNull(target, "The existing TestSummary must be associated with a target");
    BlazeTestStatus status = existingSummary.getStatus();
    int numCached = existingSummary.numCached();
    int numLocalActionCached = existingSummary.numLocalActionCached();
    // If a test was neither cached locally nor remotely we say action was taken.
    if (!(result.isCached() || result.getData().getRemotelyCached())) {
        summaryBuilder.setActionRan(true);
    } else {
        numCached++;
    }
    if (result.isCached()) {
        numLocalActionCached++;
    }
    PathFragment coverageData = result.getCoverageData();
    if (coverageData != null) {
        summaryBuilder.addCoverageFiles(Collections.singletonList(execRoot.getRelative(coverageData)));
    }
    if (!executionOptions.runsPerTestDetectsFlakes) {
        status = aggregateStatus(status, result.getData().getStatus());
    } else {
        int shardNumber = result.getShardNum();
        int runsPerTestForLabel = target.getProvider(TestProvider.class).getTestParams().getRuns();
        List<BlazeTestStatus> singleShardStatuses = summaryBuilder.addShardStatus(shardNumber, result.getData().getStatus());
        if (singleShardStatuses.size() == runsPerTestForLabel) {
            BlazeTestStatus shardStatus = BlazeTestStatus.NO_STATUS;
            int passes = 0;
            for (BlazeTestStatus runStatusForShard : singleShardStatuses) {
                shardStatus = aggregateStatus(shardStatus, runStatusForShard);
                if (TestResult.isBlazeTestStatusPassed(runStatusForShard)) {
                    passes++;
                }
            }
            // If all results pass or fail, aggregate the passing/failing shardStatus.
            if (passes == 0 || passes == runsPerTestForLabel) {
                status = aggregateStatus(status, shardStatus);
            } else {
                status = aggregateStatus(status, BlazeTestStatus.FLAKY);
            }
        }
    }
    List<Path> passed = new ArrayList<>();
    if (result.getData().hasPassedLog()) {
        passed.add(result.getTestAction().getTestLog().getPath().getRelative(result.getData().getPassedLog()));
    }
    List<Path> failed = new ArrayList<>();
    for (String path : result.getData().getFailedLogsList()) {
        failed.add(result.getTestAction().getTestLog().getPath().getRelative(path));
    }
    summaryBuilder.addTestTimes(result.getData().getTestTimesList()).addPassedLogs(passed).addFailedLogs(failed).addWarnings(result.getData().getWarningList()).collectFailedTests(result.getData().getTestCase()).setRanRemotely(result.getData().getIsRemoteStrategy());
    List<String> warnings = new ArrayList<>();
    if (status == BlazeTestStatus.PASSED && shouldEmitTestSizeWarningInSummary(summaryOptions.testVerboseTimeoutWarnings, warnings, result.getData().getTestProcessTimesList(), target)) {
        summaryBuilder.setWasUnreportedWrongSize(true);
    }
    return summaryBuilder.setStatus(status).setNumCached(numCached).setNumLocalActionCached(numLocalActionCached).addWarnings(warnings);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) BlazeTestStatus(com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ArrayList(java.util.ArrayList) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection)

Example 54 with TransitiveInfoCollection

use of com.google.devtools.build.lib.analysis.TransitiveInfoCollection in project bazel by bazelbuild.

the class SkylarkRuleContextTest method shouldGetPrerequisite.

@Test
public void shouldGetPrerequisite() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:asr");
    Object result = evalRuleContextCode(ruleContext, "ruleContext.attr.srcjar");
    TransitiveInfoCollection tic = (TransitiveInfoCollection) result;
    assertThat(tic).isInstanceOf(FileConfiguredTarget.class);
    assertEquals("asr-src.jar", tic.getLabel().getName());
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) TransitiveInfoCollection(com.google.devtools.build.lib.analysis.TransitiveInfoCollection) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Aggregations

TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)54 Artifact (com.google.devtools.build.lib.actions.Artifact)27 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)14 FileProvider (com.google.devtools.build.lib.analysis.FileProvider)11 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)11 Label (com.google.devtools.build.lib.cmdline.Label)10 ImmutableList (com.google.common.collect.ImmutableList)8 ArrayList (java.util.ArrayList)8 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)7 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)5 Test (org.junit.Test)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 FilesToRunProvider (com.google.devtools.build.lib.analysis.FilesToRunProvider)4 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)4 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)4 Pair (com.google.devtools.build.lib.util.Pair)4 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 Map (java.util.Map)4 CustomCommandLine (com.google.devtools.build.lib.analysis.actions.CustomCommandLine)3 CcLinkParamsProvider (com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider)3