Search in sources :

Example 11 with Rule

use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.

the class CrosstoolConfigurationLoader method getCrosstoolProtofromBuildFile.

private static CrosstoolProto getCrosstoolProtofromBuildFile(ConfigurationEnvironment env, Label crosstoolTop) throws InterruptedException {
    Target target;
    try {
        target = env.getTarget(crosstoolTop);
    } catch (NoSuchThingException e) {
        // Should have beeen evaluated by RedirectChaser
        throw new IllegalStateException(e);
    }
    if (!(target instanceof Rule)) {
        return null;
    }
    Rule rule = (Rule) target;
    if (!(rule.getRuleClass().equals("cc_toolchain_suite")) || !rule.isAttributeValueExplicitlySpecified("proto")) {
        return null;
    }
    final String contents = NonconfigurableAttributeMapper.of(rule).get("proto", Type.STRING);
    byte[] md5 = new Fingerprint().addBytes(contents.getBytes(UTF_8)).digestAndReset();
    return new CrosstoolProto(md5, "cc_toolchain_suite rule " + crosstoolTop.toString()) {

        @Override
        public String getContents() throws IOException {
            return contents;
        }
    };
}
Also used : Target(com.google.devtools.build.lib.packages.Target) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) Fingerprint(com.google.devtools.build.lib.util.Fingerprint) Rule(com.google.devtools.build.lib.packages.Rule)

Example 12 with Rule

use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.

the class XcodeConfig method resolveXcodeVersion.

/**
   * Uses the {@link AppleCommandLineOptions#xcodeVersion} and {@link
   * AppleCommandLineOptions#xcodeVersionConfig} command line options to determine and return the
   * effective xcode version and its properties.
   *
   * @param env the current configuration environment
   * @param xcodeConfigLabel the label for the xcode_config target to parse
   * @param xcodeVersionOverrideFlag the value of the command line flag to override the default
   *     xcode version, absent if unspecified
   * @param errorDescription a description of the origin of {@code #xcodeConfigLabel} for messaging
   *     parse errors
   * @throws InvalidConfigurationException if the options given (or configuration targets) were
   *     malformed and thus the xcode version could not be determined
   */
static XcodeVersionProperties resolveXcodeVersion(ConfigurationEnvironment env, Label xcodeConfigLabel, Optional<DottedVersion> xcodeVersionOverrideFlag, String errorDescription) throws InvalidConfigurationException, InterruptedException {
    Rule xcodeConfigRule = getRuleForLabel(xcodeConfigLabel, "xcode_config", env, errorDescription);
    XcodeVersionRuleData xcodeVersion = resolveExplicitlyDefinedVersion(env, xcodeConfigRule, xcodeVersionOverrideFlag);
    if (xcodeVersion != null) {
        return xcodeVersion.getXcodeVersionProperties();
    } else if (xcodeVersionOverrideFlag.isPresent()) {
        return new XcodeVersionProperties(xcodeVersionOverrideFlag.get());
    } else {
        return XcodeVersionProperties.unknownXcodeVersionProperties();
    }
}
Also used : Rule(com.google.devtools.build.lib.packages.Rule)

Example 13 with Rule

use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.

the class XcodeConfig method aliasesToVersionMap.

/**
   * Returns a map where keys are "names" of xcode versions as defined by the configuration target,
   * and values are the rule data objects which contain information regarding that xcode version.
   *
   * @throws InvalidConfigurationException if there are duplicate aliases (if two xcode versions
   *     were registered to the same alias)
   */
private static Map<String, XcodeVersionRuleData> aliasesToVersionMap(ConfigurationEnvironment env, Rule xcodeConfigTarget) throws InvalidConfigurationException, InterruptedException {
    List<Label> xcodeVersionLabels = NonconfigurableAttributeMapper.of(xcodeConfigTarget).get(XcodeConfigRule.VERSIONS_ATTR_NAME, BuildType.LABEL_LIST);
    ImmutableList.Builder<XcodeVersionRuleData> xcodeVersionRuleListBuilder = ImmutableList.builder();
    for (Label label : xcodeVersionLabels) {
        Rule xcodeVersionRule = getRuleForLabel(label, "xcode_version", env, "xcode_version");
        xcodeVersionRuleListBuilder.add(new XcodeVersionRuleData(label, xcodeVersionRule));
    }
    ImmutableList<XcodeVersionRuleData> xcodeVersionRules = xcodeVersionRuleListBuilder.build();
    Map<String, XcodeVersionRuleData> aliasesToXcodeRules = Maps.newLinkedHashMap();
    for (XcodeVersionRuleData xcodeVersionRule : xcodeVersionRules) {
        for (String alias : xcodeVersionRule.getAliases()) {
            if (aliasesToXcodeRules.put(alias, xcodeVersionRule) != null) {
                configErrorDuplicateAlias(alias, xcodeVersionRules);
            }
        }
        // definition, as it's silly to error if a version is aliased to its own version.
        if (!xcodeVersionRule.getAliases().contains(xcodeVersionRule.getVersion().toString())) {
            if (aliasesToXcodeRules.put(xcodeVersionRule.getVersion().toString(), xcodeVersionRule) != null) {
                configErrorDuplicateAlias(xcodeVersionRule.getVersion().toString(), xcodeVersionRules);
            }
        }
    }
    return aliasesToXcodeRules;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Label(com.google.devtools.build.lib.cmdline.Label) Rule(com.google.devtools.build.lib.packages.Rule)

Example 14 with Rule

use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.

the class DependencyResolver method resolveEarlyBoundAttributes.

/**
   * Resolves the dependencies for all attributes in this rule except late-bound attributes
   * (which require special processing: see {@link #resolveLateBoundAttributes}).
   */
private void resolveEarlyBoundAttributes(RuleResolver depResolver) throws EvalException, InterruptedException, InconsistentAspectOrderException {
    Rule rule = depResolver.rule;
    resolveExplicitAttributes(depResolver);
    resolveImplicitAttributes(depResolver);
    // Add the rule's visibility labels (which may come from the rule or from package defaults).
    addExplicitDeps(depResolver, "visibility", rule.getVisibility().getDependencyLabels());
    // make the user responsible for resolving ambiguities.
    if (!rule.isAttributeValueExplicitlySpecified(RuleClass.COMPATIBLE_ENVIRONMENT_ATTR)) {
        addExplicitDeps(depResolver, RuleClass.COMPATIBLE_ENVIRONMENT_ATTR, rule.getPackage().getDefaultCompatibleWith());
    }
    if (!rule.isAttributeValueExplicitlySpecified(RuleClass.RESTRICTED_ENVIRONMENT_ATTR)) {
        addExplicitDeps(depResolver, RuleClass.RESTRICTED_ENVIRONMENT_ATTR, rule.getPackage().getDefaultRestrictedTo());
    }
}
Also used : Rule(com.google.devtools.build.lib.packages.Rule)

Example 15 with Rule

use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.

the class DependencyResolver method visitRule.

private void visitRule(TargetAndConfiguration node, BuildConfiguration hostConfig, Iterable<Aspect> aspects, ImmutableMap<Label, ConfigMatchingProvider> configConditions, NestedSetBuilder<Label> rootCauses, OrderedSetMultimap<Attribute, Dependency> outgoingEdges) throws EvalException, InvalidConfigurationException, InconsistentAspectOrderException, InterruptedException {
    Preconditions.checkArgument(node.getTarget() instanceof Rule);
    BuildConfiguration ruleConfig = Preconditions.checkNotNull(node.getConfiguration());
    Rule rule = (Rule) node.getTarget();
    ConfiguredAttributeMapper attributeMap = ConfiguredAttributeMapper.of(rule, configConditions);
    attributeMap.validateAttributes();
    RuleResolver depResolver = new RuleResolver(rule, ruleConfig, aspects, attributeMap, rootCauses, outgoingEdges);
    visitTargetVisibility(node, rootCauses, outgoingEdges.get(null));
    resolveEarlyBoundAttributes(depResolver);
    resolveLateBoundAttributes(depResolver, ruleConfig, hostConfig);
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) Rule(com.google.devtools.build.lib.packages.Rule)

Aggregations

Rule (com.google.devtools.build.lib.packages.Rule)79 Test (org.junit.Test)27 Label (com.google.devtools.build.lib.cmdline.Label)26 Attribute (com.google.devtools.build.lib.packages.Attribute)20 Target (com.google.devtools.build.lib.packages.Target)19 Nullable (javax.annotation.Nullable)10 RawAttributeMapper (com.google.devtools.build.lib.packages.RawAttributeMapper)9 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)9 OutputFile (com.google.devtools.build.lib.packages.OutputFile)8 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)7 NoSuchThingException (com.google.devtools.build.lib.packages.NoSuchThingException)7 SkyKey (com.google.devtools.build.skyframe.SkyKey)7 ImmutableList (com.google.common.collect.ImmutableList)6 InputFile (com.google.devtools.build.lib.packages.InputFile)6 IOException (java.io.IOException)6 LinkedHashSet (java.util.LinkedHashSet)6 AggregatingAttributeMapper (com.google.devtools.build.lib.packages.AggregatingAttributeMapper)5 Package (com.google.devtools.build.lib.packages.Package)5 Artifact (com.google.devtools.build.lib.actions.Artifact)4 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)4