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;
}
};
}
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();
}
}
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;
}
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());
}
}
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);
}
Aggregations