-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose CoverageOutputGenerator on a Fragment
This allows Starlark rules to define _lcov_merger as a late-bound Starlark configuration_field in order not to pay the cost of building it when coverage isn't enabled.
- Loading branch information
Showing
6 changed files
with
196 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/com/google/devtools/build/lib/analysis/test/CoverageConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.google.devtools.build.lib.analysis.test; | ||
|
||
import com.google.devtools.build.lib.analysis.config.BuildOptions; | ||
import com.google.devtools.build.lib.analysis.config.CoreOptionConverters.LabelConverter; | ||
import com.google.devtools.build.lib.analysis.config.CoreOptions; | ||
import com.google.devtools.build.lib.analysis.config.Fragment; | ||
import com.google.devtools.build.lib.analysis.config.FragmentOptions; | ||
import com.google.devtools.build.lib.analysis.config.RequiresOptions; | ||
import com.google.devtools.build.lib.analysis.starlark.annotations.StarlarkConfigurationField; | ||
import com.google.devtools.build.lib.cmdline.Label; | ||
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; | ||
import com.google.devtools.build.lib.starlarkbuildapi.test.CoverageConfigurationApi; | ||
import com.google.devtools.common.options.Option; | ||
import com.google.devtools.common.options.OptionDocumentationCategory; | ||
import com.google.devtools.common.options.OptionEffectTag; | ||
import javax.annotation.Nullable; | ||
|
||
@Immutable | ||
@RequiresOptions(options = {CoreOptions.class, CoverageConfiguration.CoverageOptions.class}) | ||
public class CoverageConfiguration extends Fragment implements CoverageConfigurationApi { | ||
|
||
/** | ||
* Command-line options. | ||
*/ | ||
public static class CoverageOptions extends FragmentOptions { | ||
|
||
@Option( | ||
name = "coverage_output_generator", | ||
converter = LabelConverter.class, | ||
defaultValue = "@bazel_tools//tools/test:lcov_merger", | ||
documentationCategory = OptionDocumentationCategory.TOOLCHAIN, | ||
effectTags = { | ||
OptionEffectTag.CHANGES_INPUTS, | ||
OptionEffectTag.AFFECTS_OUTPUTS, | ||
OptionEffectTag.LOADING_AND_ANALYSIS | ||
}, | ||
help = | ||
"Location of the binary that is used to postprocess raw coverage reports. This must " | ||
+ "currently be a filegroup that contains a single file, the binary. Defaults to " | ||
+ "'//tools/test:lcov_merger'." | ||
) | ||
public Label coverageOutputGenerator; | ||
} | ||
|
||
private final CoverageOptions coverageOptions; | ||
|
||
public CoverageConfiguration(BuildOptions buildOptions) { | ||
if (!buildOptions.get(CoreOptions.class).collectCodeCoverage) { | ||
this.coverageOptions = null; | ||
return; | ||
} | ||
this.coverageOptions = buildOptions.get(CoverageOptions.class); | ||
} | ||
|
||
@Override | ||
@StarlarkConfigurationField( | ||
name = "output_generator", | ||
doc = "Label for the coverage output generator.") | ||
@Nullable | ||
public Label outputGenerator() { | ||
if (coverageOptions == null) { | ||
return null; | ||
} | ||
return coverageOptions.coverageOutputGenerator; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...in/java/com/google/devtools/build/lib/starlarkbuildapi/test/CoverageConfigurationApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.google.devtools.build.lib.starlarkbuildapi.test; | ||
|
||
import com.google.devtools.build.docgen.annot.DocCategory; | ||
import com.google.devtools.build.lib.cmdline.Label; | ||
import javax.annotation.Nullable; | ||
import net.starlark.java.annot.StarlarkBuiltin; | ||
import net.starlark.java.annot.StarlarkMethod; | ||
import net.starlark.java.eval.StarlarkValue; | ||
|
||
@StarlarkBuiltin( | ||
name = "coverage", | ||
category = DocCategory.CONFIGURATION_FRAGMENT, | ||
doc = "A configuration fragment representing the coverage configuration.") | ||
public interface CoverageConfigurationApi extends StarlarkValue { | ||
|
||
@StarlarkMethod( | ||
name = "output_generator", | ||
allowReturnNones = true, | ||
structField = true, | ||
doc = | ||
"Returns label pointed to by " | ||
+ "<a href=\"../../user-manual.html#flag--coverage_output_generator\">" | ||
+ "<code>--coverage_output_generator</code></a> option. Can be accessed with" | ||
+ " <a href=\"globals.html#configuration_field\"><code>configuration_field" | ||
+ "</code></a>:<br/>" | ||
+ "<pre>attr.label(<br/>" | ||
+ " default = configuration_field(<br/>" | ||
+ " fragment = \"coverage\",<br/>" | ||
+ " name = \"output_generator\"<br/>" | ||
+ " )<br/>" | ||
+ ")</pre>") | ||
@Nullable | ||
Label outputGenerator(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters