use of com.google.devtools.build.lib.packages.ClassObjectConstructor in project bazel by bazelbuild.
the class AbstractConfiguredTarget method getIndex.
@Override
public Object getIndex(Object key, Location loc) throws EvalException {
if (!(key instanceof ClassObjectConstructor)) {
throw new EvalException(loc, String.format("Type Target only supports indexing by object constructors, got %s instead", EvalUtils.getDataTypeName(key)));
}
ClassObjectConstructor constructor = (ClassObjectConstructor) key;
SkylarkProviders provider = getProvider(SkylarkProviders.class);
if (provider != null) {
Object declaredProvider = provider.getDeclaredProvider(constructor.getKey());
if (declaredProvider != null) {
return declaredProvider;
}
}
// Either provider or declaredProvider is null
throw new EvalException(loc, String.format("Object of type Target doesn't contain declared provider %s", constructor.getPrintableName()));
}
use of com.google.devtools.build.lib.packages.ClassObjectConstructor in project bazel by bazelbuild.
the class RuleConfiguredTargetBuilder method addNativeDeclaredProvider.
/**
* Adds a "declared provider" defined in native code to the rule.
* Use this method for declared providers in definitions of native rules.
*
* Use {@link #addSkylarkDeclaredProvider(SkylarkClassObject, Location)}
* for Skylark rule implementations.
*/
public RuleConfiguredTargetBuilder addNativeDeclaredProvider(SkylarkClassObject provider) {
ClassObjectConstructor constructor = provider.getConstructor();
Preconditions.checkState(constructor.isExported());
skylarkDeclaredProviders.put(constructor.getKey(), provider);
return this;
}
use of com.google.devtools.build.lib.packages.ClassObjectConstructor in project bazel by bazelbuild.
the class RuleConfiguredTargetBuilder method addSkylarkDeclaredProvider.
/**
* Adds a "declared provider" defined in Skylark to the rule.
* Use this method for declared providers defined in Skyark.
*
* Use {@link #addNativeDeclaredProvider(SkylarkClassObject)} in definitions of
* native rules.
*/
public RuleConfiguredTargetBuilder addSkylarkDeclaredProvider(SkylarkClassObject provider, Location loc) throws EvalException {
ClassObjectConstructor constructor = provider.getConstructor();
SkylarkProviderValidationUtil.validateAndThrowEvalException(constructor.getPrintableName(), provider, loc);
if (!constructor.isExported()) {
throw new EvalException(constructor.getLocation(), "All providers must be top level values");
}
skylarkDeclaredProviders.put(constructor.getKey(), provider);
return this;
}
use of com.google.devtools.build.lib.packages.ClassObjectConstructor in project bazel by bazelbuild.
the class AbstractConfiguredTarget method containsKey.
@Override
public boolean containsKey(Object key, Location loc) throws EvalException {
if (!(key instanceof ClassObjectConstructor)) {
throw new EvalException(loc, String.format("Type Target only supports querying by object constructors, got %s instead", EvalUtils.getDataTypeName(key)));
}
ClassObjectConstructor constructor = (ClassObjectConstructor) key;
SkylarkProviders provider = getProvider(SkylarkProviders.class);
if (provider != null) {
Object declaredProvider = provider.getDeclaredProvider(constructor.getKey());
if (declaredProvider != null) {
return true;
}
}
return false;
}
Aggregations