diff options
author | cparsons <cparsons@google.com> | 2018-05-07 05:47:23 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-05-07 05:48:57 -0700 |
commit | 1442054f23c171bc16238e9ee845921c48082a5a (patch) | |
tree | ed59e92d46277128a0b54ae35883b8007223e0f3 /src/test/java/com/google/devtools/build | |
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/test/java/com/google/devtools/build')
3 files changed, 65 insertions, 6 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/skylark/annotations/processor/SkylarkConfigurationFieldProcessorTest.java b/src/test/java/com/google/devtools/build/lib/analysis/skylark/annotations/processor/SkylarkConfigurationFieldProcessorTest.java index 4f6bc4dfb6..d17b226ccd 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/skylark/annotations/processor/SkylarkConfigurationFieldProcessorTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/skylark/annotations/processor/SkylarkConfigurationFieldProcessorTest.java @@ -50,6 +50,18 @@ public final class SkylarkConfigurationFieldProcessorTest { } @Test + public void testGoldenConfigurationFieldThroughApi() throws Exception { + // TODO(b/71644521): Compile-testing is not fully functional on Windows; test sources are + // unable to resolve cross-package dependencies. + assumeTrue(OS.getCurrent() != OS.WINDOWS); + + assertAbout(javaSource()) + .that(getFile("GoldenConfigurationFieldThroughApi.java")) + .processedWith(new SkylarkConfigurationFieldProcessor()) + .compilesWithoutError(); + } + + @Test public void testHasMethodParameters() throws Exception { // TODO(b/71644521): Compile-testing is not fully functional on Windows; test sources are // unable to resolve cross-package dependencies. @@ -99,8 +111,8 @@ public final class SkylarkConfigurationFieldProcessorTest { .that(getFile("NonConfigurationFragment.java")) .processedWith(new SkylarkConfigurationFieldProcessor()) .failsToCompile() - .withErrorContaining("@SkylarkConfigurationField annotated methods must be methods of " - + "configuration fragments with the @SkylarkModule annotation."); + .withErrorContaining("@SkylarkConfigurationField annotated methods must be methods " + + "of configuration fragments."); } @Test @@ -112,9 +124,7 @@ public final class SkylarkConfigurationFieldProcessorTest { assertAbout(javaSource()) .that(getFile("NonExposedConfigurationFragment.java")) .processedWith(new SkylarkConfigurationFieldProcessor()) - .failsToCompile() - .withErrorContaining("@SkylarkConfigurationField annotated methods must be methods of " - + "configuration fragments with the @SkylarkModule annotation."); + .compilesWithoutError(); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/analysis/skylark/annotations/processor/optiontestsources/GoldenConfigurationFieldThroughApi.java b/src/test/java/com/google/devtools/build/lib/analysis/skylark/annotations/processor/optiontestsources/GoldenConfigurationFieldThroughApi.java new file mode 100644 index 0000000000..29bca7fe24 --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/analysis/skylark/annotations/processor/optiontestsources/GoldenConfigurationFieldThroughApi.java @@ -0,0 +1,49 @@ +// 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.analysis.skylark.annotations.processor.optiontestsources; + +import com.google.devtools.build.lib.analysis.config.BuildConfiguration; +import com.google.devtools.build.lib.analysis.skylark.annotations.SkylarkConfigurationField; +import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; + +/** + * A test case of SkylarkConfigurationFieldProcessorTest. + */ +public class GoldenConfigurationFieldThroughApi + extends BuildConfiguration.Fragment implements ApiInterface { + + /** + * Returns the label of the xcode_config rule to use for resolving the host system xcode version. + */ + @SkylarkConfigurationField( + name = "some_field", + doc = "Documentation ", + defaultLabel = "defaultLabel", + defaultInToolRepository = true + ) + public Label getXcodeConfigLabel() { + return null; + } +} + +@SkylarkModule( + name = "module_name", + doc = "A fake configuration fragment for a test.", + category = SkylarkModuleCategory.CONFIGURATION_FRAGMENT +) +interface ApiInterface { +} diff --git a/src/test/java/com/google/devtools/build/lib/analysis/skylark/annotations/processor/optiontestsources/NonConfigurationFragment.java b/src/test/java/com/google/devtools/build/lib/analysis/skylark/annotations/processor/optiontestsources/NonConfigurationFragment.java index 221493775f..f21175f2fb 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/skylark/annotations/processor/optiontestsources/NonConfigurationFragment.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/skylark/annotations/processor/optiontestsources/NonConfigurationFragment.java @@ -25,7 +25,7 @@ import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; @SkylarkModule( name = "module_name", doc = "A fake configuration fragment for a test.", - category = SkylarkModuleCategory.CONFIGURATION_FRAGMENT + category = SkylarkModuleCategory.BUILTIN // Not a configuration fragment! ) public class NonConfigurationFragment { |