// Copyright 2017 The Bazel Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.google.devtools.build.lib.packages; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; import com.google.devtools.build.lib.syntax.BaseFunction; import com.google.devtools.build.lib.syntax.Environment; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.FuncallExpression; import com.google.devtools.build.lib.syntax.FunctionSignature; import com.google.devtools.build.lib.syntax.SkylarkType; import javax.annotation.Nullable; /** * Declared Provider (a constructor for {@link SkylarkClassObject}). * *
Declared providers can be declared either natively ({@link NativeClassObjectConstructor} or in * Skylark {@link SkylarkClassObjectConstructor}. * *
{@link ClassObjectConstructor} serves both as "type identifier" for declared provider * instances and as a function that can be called to construct a provider. * *
Prefer to use {@link Key} as a serializable identifier of {@link ClassObjectConstructor}. In
* particular, {@link Key} should be used in all data structures exposed to Skyframe.
*/
@SkylarkModule(
name = "Provider",
doc =
"A constructor for simple value objects, known as provider instances."
+ "
"
+ "This value has a dual purpose:"
+ "
DataInfo = provider()\n" + "d = DataInfo(x = 2, y = 3)\n" + "print(d.x + d.y) # prints 5" + " Some providers, defined internally, do not allow instance creation" + "
DataInfo = provider()\n" + "def _rule_impl(ctx)\n" + " ... ctx.attr.dep[DataInfo]" + "
Provider
using the "
+ "provider function."
)
@Immutable
public abstract class ClassObjectConstructor extends BaseFunction {
protected ClassObjectConstructor(String name,
FunctionSignature.WithValues