diff options
author | 2018-05-07 05:47:23 -0700 | |
---|---|---|
committer | 2018-05-07 05:48:57 -0700 | |
commit | 1442054f23c171bc16238e9ee845921c48082a5a (patch) | |
tree | ed59e92d46277128a0b54ae35883b8007223e0f3 /src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkLateBoundDefault.java | |
parent | 321138f412df405e2f7c8d0963a02375f1990ac6 (diff) |
Relax requirements of skylark-exposed configuration fragments
Since configuration fragments will extend from build API classes, @SkylarkConfigurationField no longer needs to annotate a method defined on a @SkylarkModule class. Ideally, we would ensure that a configuration fragment with a @SkylarkConfigurationField method implements an interface with @SkylarkModule, but this seems impossible to perform at the level of an annotation processor.
RELNOTES: None.
PiperOrigin-RevId: 195651344
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkLateBoundDefault.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkLateBoundDefault.java | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkLateBoundDefault.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkLateBoundDefault.java index bf91cafbab..139f8656cb 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkLateBoundDefault.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkLateBoundDefault.java @@ -28,6 +28,7 @@ import com.google.devtools.build.lib.packages.AttributeMap; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.skylarkbuildapi.LateBoundDefaultApi; +import com.google.devtools.build.lib.skylarkinterface.SkylarkInterfaceUtils; import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter; import java.lang.reflect.InvocationTargetException; @@ -192,27 +193,31 @@ public class SkylarkLateBoundDefault<FragmentT> extends AbstractLabelLateBoundDe ImmutableMap.Builder<String, SkylarkLateBoundDefault<?>> lateBoundDefaultMap = new ImmutableMap.Builder<>(); Class<?> fragmentClass = key.fragmentClass; - String fragmentName = SkylarkModule.Resolver.resolveName(fragmentClass); - for (Method method : fragmentClass.getMethods()) { - if (method.isAnnotationPresent(SkylarkConfigurationField.class)) { - // TODO(b/68817606): Use annotation processors to verify these constraints. - Preconditions.checkArgument( - method.getReturnType() == Label.class, - String.format("Method %s must have return type 'Label'", method)); - Preconditions.checkArgument( - method.getParameterTypes().length == 0, - String.format("Method %s must not accept arguments", method)); + SkylarkModule fragmentModule = + SkylarkInterfaceUtils.getSkylarkModule(fragmentClass); - SkylarkConfigurationField configField = - method.getAnnotation(SkylarkConfigurationField.class); - lateBoundDefaultMap.put( - configField.name(), - new SkylarkLateBoundDefault<>( - configField, - fragmentClass, - fragmentName, - method, - key.toolsRepository)); + if (fragmentModule != null) { + for (Method method : fragmentClass.getMethods()) { + if (method.isAnnotationPresent(SkylarkConfigurationField.class)) { + // TODO(b/68817606): Use annotation processors to verify these constraints. + Preconditions.checkArgument( + method.getReturnType() == Label.class, + String.format("Method %s must have return type 'Label'", method)); + Preconditions.checkArgument( + method.getParameterTypes().length == 0, + String.format("Method %s must not accept arguments", method)); + + SkylarkConfigurationField configField = + method.getAnnotation(SkylarkConfigurationField.class); + lateBoundDefaultMap.put( + configField.name(), + new SkylarkLateBoundDefault<>( + configField, + fragmentClass, + fragmentModule.name(), + method, + key.toolsRepository)); + } } } return lateBoundDefaultMap.build(); |