/** Returns a human readable representation of the critical path stats with all the details. */
 @Override
 public String toString() {
   String currentTime = "still running ";
   if (!isRunning) {
     currentTime = String.format("%.2f", getElapsedTimeMillis() / 1000.0) + "s ";
   }
   return currentTime + action.describe();
 }
 /**
  * Generating the same output from two targets is ok if we build them on successive builds and
  * invalidate the first target before we build the second target. This is a strictly weaker test
  * than if we didn't invalidate the first target, but since Skyframe can't pass then, this test
  * could be useful for it. Actually, since Skyframe makes multiple update calls, it manages to
  * unregister actions even when it shouldn't, and so this test can incorrectly pass. However,
  * {@code SkyframeExecutorTest#testNoActionConflictWithInvalidatedTarget} tests it more
  * rigorously.
  */
 public void testNoActionConflictWithInvalidatedTarget() throws Exception {
   scratch.file(
       "conflict/BUILD",
       "cc_library(name='x', srcs=['foo.cc'])",
       "cc_binary(name='_objs/x/conflict/foo.pic.o', srcs=['bar.cc'])");
   update("//conflict:x");
   ConfiguredTarget conflict = getConfiguredTarget("//conflict:x");
   Action oldAction = getGeneratingAction(getBinArtifact("_objs/x/conflict/foo.pic.o", conflict));
   assertEquals("//conflict:x", oldAction.getOwner().getLabel().toString());
   scratch.overwriteFile(
       "conflict/BUILD",
       "cc_library(name='newx', srcs=['foo.cc'])", // Rename target.
       "cc_binary(name='_objs/x/conflict/foo.pic.o', srcs=['bar.cc'])");
   update(defaultFlags(), "//conflict:_objs/x/conflict/foo.pic.o");
   ConfiguredTarget objsConflict = getConfiguredTarget("//conflict:_objs/x/conflict/foo.pic.o");
   Action newAction =
       getGeneratingAction(getBinArtifact("_objs/x/conflict/foo.pic.o", objsConflict));
   assertEquals(
       "//conflict:_objs/x/conflict/foo.pic.o", newAction.getOwner().getLabel().toString());
 }
Example #3
0
 private void setDeserializedArtifactOwners() throws ViewCreationFailedException {
   Map<PathFragment, Artifact> deserializedArtifactMap =
       artifactFactory.getDeserializedArtifacts();
   Set<Artifact> deserializedArtifacts = new HashSet<>();
   for (Artifact artifact : deserializedArtifactMap.values()) {
     if (!artifact.getExecPath().getBaseName().endsWith(".gcda")) {
       // gcda files are classified as generated artifacts, but are not actually generated. All
       // others need owners.
       deserializedArtifacts.add(artifact);
     }
   }
   if (deserializedArtifacts.isEmpty()) {
     // If there are no deserialized artifacts to process, don't pay the price of iterating over
     // the graph.
     return;
   }
   for (Map.Entry<SkyKey, ActionLookupValue> entry :
       skyframeExecutor.getActionLookupValueMap().entrySet()) {
     for (Action action : entry.getValue().getActionsForFindingArtifactOwners()) {
       for (Artifact output : action.getOutputs()) {
         Artifact deserializedArtifact = deserializedArtifactMap.get(output.getExecPath());
         if (deserializedArtifact != null) {
           deserializedArtifact.setArtifactOwner((ActionLookupKey) entry.getKey().argument());
           deserializedArtifacts.remove(deserializedArtifact);
         }
       }
     }
   }
   if (!deserializedArtifacts.isEmpty()) {
     throw new ViewCreationFailedException(
         "These artifacts were read in from the FDO profile but"
             + " have no generating action that could be found. If you are confident that your profile was"
             + " collected from the same source state at which you're building, please report this:\n"
             + Artifact.asExecPaths(deserializedArtifacts));
   }
   artifactFactory.clearDeserializedArtifacts();
 }
  @Test
  public void testActionTemplateExpansionFunction() throws Exception {
    Artifact inputTreeArtifact =
        createAndPopulateTreeArtifact("inputTreeArtifact", "child0", "child1", "child2");
    Artifact outputTreeArtifact = createTreeArtifact("outputTreeArtifact");

    SpawnActionTemplate spawnActionTemplate =
        ActionsTestUtil.createDummySpawnActionTemplate(inputTreeArtifact, outputTreeArtifact);
    List<Action> actions = evaluate(spawnActionTemplate);
    assertThat(actions).hasSize(3);

    ArtifactOwner owner =
        ActionTemplateExpansionValue.createActionTemplateExpansionKey(spawnActionTemplate);
    int i = 0;
    for (Action action : actions) {
      String childName = "child" + i;
      assertThat(Artifact.toExecPaths(action.getInputs()))
          .contains("out/inputTreeArtifact/" + childName);
      assertThat(Artifact.toExecPaths(action.getOutputs()))
          .containsExactly("out/outputTreeArtifact/" + childName);
      assertThat(Iterables.getOnlyElement(action.getOutputs()).getArtifactOwner()).isEqualTo(owner);
      ++i;
    }
  }