/**
  * Returns the configurable attribute conditions necessary to evaluate the given configured
  * target, or null if not all dependencies have yet been SkyFrame-evaluated.
  */
 @Nullable
 private Set<ConfigMatchingProvider> getConfigurableAttributeConditions(
     TargetAndConfiguration ctg, Environment env) {
   if (!(ctg.getTarget() instanceof Rule)) {
     return ImmutableSet.of();
   }
   Rule rule = (Rule) ctg.getTarget();
   RawAttributeMapper mapper = RawAttributeMapper.of(rule);
   Set<SkyKey> depKeys = new LinkedHashSet<>();
   for (Attribute attribute : rule.getAttributes()) {
     for (Label label : mapper.getConfigurabilityKeys(attribute.getName(), attribute.getType())) {
       if (!BuildType.Selector.isReservedLabel(label)) {
         depKeys.add(ConfiguredTargetValue.key(label, ctg.getConfiguration()));
       }
     }
   }
   Map<SkyKey, SkyValue> cts = env.getValues(depKeys);
   if (env.valuesMissing()) {
     return null;
   }
   ImmutableSet.Builder<ConfigMatchingProvider> conditions = ImmutableSet.builder();
   for (SkyValue ctValue : cts.values()) {
     ConfiguredTarget ct = ((ConfiguredTargetValue) ctValue).getConfiguredTarget();
     conditions.add(Preconditions.checkNotNull(ct.getProvider(ConfigMatchingProvider.class)));
   }
   return conditions.build();
 }
 public void testGetConfigurabilityKeys() throws Exception {
   RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
   assertSameContents(
       ImmutableSet.of(
           Label.parseAbsolute("//conditions:a"),
           Label.parseAbsolute("//conditions:b"),
           Label.parseAbsolute("//conditions:default")),
       rawMapper.getConfigurabilityKeys("srcs", BuildType.LABEL_LIST));
   assertThat(rawMapper.getConfigurabilityKeys("data", BuildType.LABEL_LIST)).isEmpty();
 }
 /** Tests that RawAttributeMapper can't handle label visitation with configurable attributes. */
 public void testVisitLabels() throws Exception {
   RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
   try {
     rawMapper.visitLabels(
         new AttributeMap.AcceptsLabelAttribute() {
           @Override
           public void acceptLabelAttribute(Label label, Attribute attribute) {
             // Nothing to do.
           }
         });
     fail("Expected label visitation to fail since one attribute is configurable");
   } catch (IllegalArgumentException e) {
     assertThat(e.getCause().getMessage())
         .contains("SelectorList cannot be cast to java.util.List");
   }
 }
  public void testGetAttribute() throws Exception {
    RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
    List<Label> value = rawMapper.get("data", BuildType.LABEL_LIST);
    assertNotNull(value);
    assertThat(value).containsExactly(Label.create("x", "data_a"), Label.create("x", "data_b"));

    // Configurable attribute: trying to directly access from a RawAttributeMapper throws a
    // type mismatch exception.
    try {
      rawMapper.get("srcs", BuildType.LABEL_LIST);
      fail("Expected srcs lookup to fail since the returned type is a SelectorList and not a list");
    } catch (IllegalArgumentException e) {
      assertThat(e.getCause().getMessage())
          .contains("SelectorList cannot be cast to java.util.List");
    }
  }
 public void testGetMergedValues() throws Exception {
   Rule rule =
       createRule(
           "x",
           "myrule",
           "sh_binary(",
           "    name = 'myrule',",
           "    srcs = select({",
           "        '//conditions:a': ['a.sh', 'b.sh'],",
           "        '//conditions:b': ['b.sh', 'c.sh'],",
           "    }))");
   RawAttributeMapper rawMapper = RawAttributeMapper.of(rule);
   assertThat(rawMapper.getMergedValues("srcs", BuildType.LABEL_LIST))
       .containsExactly(
           Label.parseAbsolute("//x:a.sh"),
           Label.parseAbsolute("//x:b.sh"),
           Label.parseAbsolute("//x:c.sh"))
       .inOrder();
 }
 public void testMergedValuesWithConcatenatedSelects() throws Exception {
   Rule rule =
       createRule(
           "x",
           "myrule",
           "sh_binary(",
           "    name = 'myrule',",
           "    srcs = select({",
           "            '//conditions:a1': ['a1.sh'],",
           "            '//conditions:b1': ['b1.sh', 'another_b1.sh']})",
           "        + select({",
           "            '//conditions:a2': ['a2.sh'],",
           "            '//conditions:b2': ['b2.sh']})",
           "    )");
   RawAttributeMapper rawMapper = RawAttributeMapper.of(rule);
   assertThat(rawMapper.getMergedValues("srcs", BuildType.LABEL_LIST))
       .containsExactly(
           Label.parseAbsolute("//x:a1.sh"),
           Label.parseAbsolute("//x:b1.sh"),
           Label.parseAbsolute("//x:another_b1.sh"),
           Label.parseAbsolute("//x:a2.sh"),
           Label.parseAbsolute("//x:b2.sh"))
       .inOrder();
 }
 public void testConfigurabilityCheck() throws Exception {
   RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
   assertFalse(rawMapper.isConfigurable("data", BuildType.LABEL_LIST));
   assertTrue(rawMapper.isConfigurable("srcs", BuildType.LABEL_LIST));
 }
 @Override
 public void testGetAttributeType() throws Exception {
   RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
   assertEquals(BuildType.LABEL_LIST, rawMapper.getAttributeType("data")); // not configurable
   assertEquals(BuildType.LABEL_LIST, rawMapper.getAttributeType("srcs")); // configurable
 }
 @Override
 public void setUp() throws Exception {
   super.setUp();
   // Run AbstractAttributeMapper tests through a RawAttributeMapper.
   mapper = RawAttributeMapper.of(rule);
 }