Skip to content

Commit

Permalink
Remove coverageredesign config field (#292)
Browse files Browse the repository at this point in the history
Go 1.20 made breaking changes to the way in which coverage is computed.
This required the `coverageredesign` GOEXPERIMENT to be enabled when
using go-rules with Go 1.20 onwards.

Go 1.19 has now been EOL for almost a year, and the `coveragedesign`
GOEXPERIMENT will be removed from Go shortly, having been the default
for around 18 months. Remove support for the pre-`coverageredesign`
coverage method and deprecate the `coverageredesign` config field.

This increases the minimum Go version required by go-rules to 1.20.
  • Loading branch information
chrisnovakovic authored Aug 27, 2024
1 parent 2a9b43c commit c356931
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
5 changes: 2 additions & 3 deletions .plzconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Stdlib = //third_party/go:std
PleaseGoTool = //tools/please_go:bootstrap
ImportPath = github.com/please-build/go-rules
ValidateModuleVersions = true
CoverageRedesign = true

[Plugin "cc"]
Target = //plugins:cc
Expand Down Expand Up @@ -148,9 +147,9 @@ Help = Flags to enable in-development features, or toggle breaking changes

[PluginConfig "coverageredesign"]
Type = bool
DefaultValue = false
DefaultValue = true
Inherit = true
Help = Support Go 1.20's coverage redesign. Will break coverage on 1.19, required for 1.20.
Help = Support Go 1.20's coverage redesign. This option now has no effect and will be removed in a future major version of the go-rules plugin.

[PluginConfig "buildmode"]
Optional = true
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Go Rules
This repo provides Golang build rules for the [Please](https://please.build) build system.
This repo provides Golang build rules for the [Please](https://please.build) build system. It supports Go >= 1.20.

# Basic usage

Expand Down
28 changes: 4 additions & 24 deletions build_defs/go.build_defs
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,6 @@ def go_library(name:str, srcs:list, resources:list=[], asm_srcs:list=None, hdrs:
else:
exported_deps = []

if cover and not CONFIG.GO.COVERAGEREDESIGN:
cover_vars = build_rule(
name = name,
tag = "cover_vars",
srcs = srcs,
cmd = f"$TOOL covervars --import_path {package_path} $($TOOL filter $SRCS) > $OUT",
tools = [CONFIG.GO.PLEASE_GO_TOOL],
outs = [f"{name}.cover_vars"],
visibility = visibility,
test_only = test_only,
)
deps += [cover_vars]
if resources:
embedcfg = build_rule(
name = name,
Expand Down Expand Up @@ -432,8 +420,6 @@ def go_library(name:str, srcs:list, resources:list=[], asm_srcs:list=None, hdrs:
deps = [transitive_headers],
)
provides = {'go': ':' + name, 'go_src': lib_rule, 'modinfo': modinfo, 'hdrs': hdrs_rule}
if cover and not CONFIG.GO.COVERAGEREDESIGN:
provides['cover_vars'] = cover_vars
return build_rule(
name = name,
srcs = {
Expand Down Expand Up @@ -499,8 +485,6 @@ def go_library(name:str, srcs:list, resources:list=[], asm_srcs:list=None, hdrs:

cmds, tools = _go_library_cmds(name, import_path=package_path, complete=complete, all_srcs=_all_srcs, cover=cover, filter_srcs=filter_srcs, abi=_abi, embedcfg=embedcfg, pgo_file=pgo_file)

if cover and not CONFIG.GO.COVERAGEREDESIGN:
provides['cover_vars'] = cover_vars
return build_rule(
name = name,
srcs = srcs,
Expand Down Expand Up @@ -809,7 +793,7 @@ def go_test(name:str, srcs:list, resources:list=None, data:list|dict=None, deps:
name=f'_{name}#main_lib',
srcs = [main_rule],
deps = deps,
_needs_transitive_deps = CONFIG.BUILD_CONFIG == "cover" and not CONFIG.GO.COVERAGEREDESIGN,
_needs_transitive_deps = False,
test_only = True,
_generate_import_config = False,
labels = labels,
Expand Down Expand Up @@ -1032,8 +1016,8 @@ def go_test_main(name:str, srcs:list, test_package:str="", test_only:bool=False,
outs = [name + '_main.go'],
deps = deps,
cmd = cmds,
needs_transitive_deps = cover and not CONFIG.GO.COVERAGEREDESIGN, # Need all dependencies to template coverage variables
requires = ['go', 'cover_vars'] if cover else ['go'],
needs_transitive_deps = False,
requires = ['go'],
test_only = test_only,
tools = {
'plz': [CONFIG.GO.PLEASE_GO_TOOL],
Expand Down Expand Up @@ -1659,11 +1643,7 @@ def _go_library_cmds(name, import_path:str="", complete=True, all_srcs=False, co
'opt': f'{prefix}; {filter_cmd}{compile_cmd}{package_flag} $SRCS_GO',
}
if cover:
if CONFIG.GO.COVERAGEREDESIGN:
cmds['cover'] = f'{prefix}; {filter_cmd} $TOOLS_PLEASE_GO cover -c covcfg.json -o covfiles.txt {package_flag} $SRCS_GO && {compile_cmd} -coveragecfg covcfg.json {package_flag} `cat covfiles.txt`'
else:
cover_cmd = 'for SRC in $SRCS_GO; do BN=$(basename $SRC); "$TOOLS_GO" tool cover -mode=set -var=GoCover_${BN//[.-]/_} $SRC > _tmp.go && mv -f _tmp.go $SRC; done'
cmds['cover'] = f'{prefix}; {filter_cmd}{cover_cmd} && {compile_cmd}{package_flag} $SRCS_GO'
cmds['cover'] = f'{prefix}; {filter_cmd} $TOOLS_PLEASE_GO cover -c covcfg.json -o covfiles.txt {package_flag} $SRCS_GO && {compile_cmd} -coveragecfg covcfg.json {package_flag} `cat covfiles.txt`'
tools['please_go'] = [CONFIG.GO.PLEASE_GO_TOOL]
if CONFIG.GO.GO_COVER_TOOL:
tools['cover'] = CONFIG.GO.GO_COVER_TOOL
Expand Down

0 comments on commit c356931

Please sign in to comment.