• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 19015773527

02 Nov 2025 05:33PM UTC coverage: 17.872% (-62.4%) from 80.3%
19015773527

Pull #22816

github

web-flow
Merge a12d75757 into 6c024e162
Pull Request #22816: Update Pants internal Python to 3.14

4 of 5 new or added lines in 3 files covered. (80.0%)

28452 existing lines in 683 files now uncovered.

9831 of 55007 relevant lines covered (17.87%)

0.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/python/pants/backend/go/subsystems/golang.py
1
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

UNCOV
4
from __future__ import annotations
×
5

UNCOV
6
import logging
×
UNCOV
7
import os
×
8

UNCOV
9
from pants.core.util_rules.asdf import AsdfPathString
×
UNCOV
10
from pants.option.option_types import BoolOption, StrListOption, StrOption
×
UNCOV
11
from pants.option.subsystem import Subsystem
×
UNCOV
12
from pants.util.memo import memoized_property
×
UNCOV
13
from pants.util.ordered_set import OrderedSet
×
UNCOV
14
from pants.util.strutil import softwrap
×
15

UNCOV
16
logger = logging.getLogger(__name__)
×
17

18

UNCOV
19
_DEFAULT_COMPILER_FLAGS = ("-g", "-O2")
×
20

21

UNCOV
22
class GolangSubsystem(Subsystem):
×
UNCOV
23
    options_scope = "golang"
×
UNCOV
24
    help = "Options for Golang support."
×
25

UNCOV
26
    class EnvironmentAware(Subsystem.EnvironmentAware):
×
UNCOV
27
        env_vars_used_by_options = ("PATH",)
×
28

UNCOV
29
        _go_search_paths = StrListOption(
×
30
            default=["<PATH>"],
31
            help=softwrap(
32
                f"""
33
                A list of paths to search for Go and extra tools needed by go.
34

35
                Specify absolute paths to directories with the `go` binary, e.g. `/usr/bin`.
36
                Earlier entries will be searched first.
37

38
                The following special strings are supported:
39

40
                * `<PATH>`, the contents of the PATH environment variable
41
                * `{AsdfPathString.STANDARD}`, {AsdfPathString.STANDARD.description("Go")}
42
                * `{AsdfPathString.LOCAL}`, {AsdfPathString.LOCAL.description("binary")}
43
                """
44
            ),
45
        )
UNCOV
46
        _subprocess_env_vars = StrListOption(
×
47
            default=["LANG", "LC_CTYPE", "LC_ALL", "PATH"],
48
            help=softwrap(
49
                """
50
            Environment variables to set when invoking the `go` tool.
51
            Entries are either strings in the form `ENV_VAR=value` to set an explicit value;
52
            or just `ENV_VAR` to copy the value from Pants's own environment.
53
            """
54
            ),
55
            advanced=True,
56
        )
57

UNCOV
58
        _cgo_tool_search_paths = StrListOption(
×
59
            default=["<PATH>"],
60
            help=softwrap(
61
                """
62
                A list of paths to search for tools needed by CGo (e.g., gcc, g++).
63

64
                Specify absolute paths to directories with tools needed by CGo , e.g. `/usr/bin`.
65
                Earlier entries will be searched first.
66

67
                The following special strings are supported:
68

69
                * `<PATH>`, the contents of the PATH environment variable
70
                """
71
            ),
72
        )
73

UNCOV
74
        _extra_tools = StrListOption(
×
75
            default=[],
76
            help=softwrap(
77
                """
78
                List any additional executable tools required for the `go` tool to work.
79
                The paths to these tools will be included in the PATH used in the execution sandbox.
80
                E.g. `go mod download` may require the `git` tool to download private modules.
81
                """
82
            ),
83
            advanced=True,
84
        )
85

UNCOV
86
        cgo_gcc_binary_name = StrOption(
×
87
            default="gcc",
88
            advanced=True,
89
            help=softwrap(
90
                """
91
                Name of the tool to use to compile C code included via CGo in a Go package.
92
                Pants will search for the tool using the paths specified by the
93
                `[golang].cgo_tool_search_paths` option.
94
                """
95
            ),
96
        )
97

UNCOV
98
        cgo_gxx_binary_name = StrOption(
×
99
            default="g++",
100
            advanced=True,
101
            help=softwrap(
102
                """
103
                Name of the tool to use to compile C++ code included via CGo in a Go package.
104
                Pants will search for the tool using the paths specified by the
105
                `[golang].cgo_tool_search_paths` option.
106
                """
107
            ),
108
        )
109

UNCOV
110
        cgo_fortran_binary_name = StrOption(
×
111
            default="gfortran",
112
            advanced=True,
113
            help=softwrap(
114
                """
115
                Name of the tool to use to compile fortran code included via CGo in a Go package.
116
                Pants will search for the tool using the paths specified by the
117
                `[golang].cgo_tool_search_paths` option.
118
                """
119
            ),
120
        )
121

UNCOV
122
        external_linker_binary_name = StrOption(
×
123
            default="gcc",
124
            advanced=True,
125
            help=softwrap(
126
                """
127
                Name of the tool to use as the "external linker" when invoking `go tool link`.
128
                Pants will search for the tool using the paths specified by the
129
                `[golang].cgo_tool_search_paths` option.
130
                """
131
            ),
132
        )
133

UNCOV
134
        cgo_c_flags = StrListOption(
×
135
            default=lambda _: list(_DEFAULT_COMPILER_FLAGS),
136
            advanced=True,
137
            help=softwrap(
138
                """
139
                Compiler options used when compiling C code when Cgo is enabled. Equivalent to setting the
140
                CGO_CFLAGS environment variable when invoking `go`.
141
                """
142
            ),
143
        )
144

UNCOV
145
        cgo_cxx_flags = StrListOption(
×
146
            default=lambda _: list(_DEFAULT_COMPILER_FLAGS),
147
            advanced=True,
148
            help=softwrap(
149
                """
150
                Compiler options used when compiling C++ code when Cgo is enabled. Equivalent to setting the
151
                CGO_CXXFLAGS environment variable when invoking `go`.
152
                """
153
            ),
154
        )
155

UNCOV
156
        cgo_fortran_flags = StrListOption(
×
157
            default=lambda _: list(_DEFAULT_COMPILER_FLAGS),
158
            advanced=True,
159
            help=softwrap(
160
                """
161
                Compiler options used when compiling Fortran code when Cgo is enabled. Equivalent to setting the
162
                CGO_FFLAGS environment variable when invoking `go`.
163
                """
164
            ),
165
        )
166

UNCOV
167
        cgo_linker_flags = StrListOption(
×
168
            default=lambda _: list(_DEFAULT_COMPILER_FLAGS),
169
            advanced=True,
170
            help=softwrap(
171
                """
172
                Compiler options used when linking native code when Cgo is enabled. Equivalent to setting the
173
                CGO_LDFLAGS environment variable when invoking `go`.
174
                """
175
            ),
176
        )
177

UNCOV
178
        @property
×
UNCOV
179
        def raw_go_search_paths(self) -> tuple[str, ...]:
×
180
            return tuple(self._go_search_paths)
×
181

UNCOV
182
        @property
×
UNCOV
183
        def env_vars_to_pass_to_subprocesses(self) -> tuple[str, ...]:
×
184
            return tuple(sorted(set(self._subprocess_env_vars)))
×
185

UNCOV
186
        @memoized_property
×
UNCOV
187
        def cgo_tool_search_paths(self) -> tuple[str, ...]:
×
188
            def iter_path_entries():
×
189
                for entry in self._cgo_tool_search_paths:
×
190
                    if entry == "<PATH>":
×
191
                        path = self._options_env.get("PATH")
×
192
                        if path:
×
193
                            yield from path.split(os.pathsep)
×
194
                    else:
195
                        yield entry
×
196

197
            return tuple(OrderedSet(iter_path_entries()))
×
198

UNCOV
199
        @property
×
UNCOV
200
        def extra_tools(self) -> tuple[str, ...]:
×
201
            return tuple(sorted(set(self._extra_tools)))
×
202

UNCOV
203
    minimum_expected_version = StrOption(
×
204
        default="1.17",
205
        help=softwrap(
206
            """
207
            The minimum Go version the distribution discovered by Pants must support.
208

209
            For example, if you set `'1.17'`, then Pants will look for a Go binary that is 1.17+,
210
            e.g. 1.17 or 1.18.
211

212
            You should still set the Go version for each module in your `go.mod` with the `go`
213
            directive.
214

215
            Do not include the patch version.
216
            """
217
        ),
218
    )
UNCOV
219
    tailor_go_mod_targets = BoolOption(
×
220
        default=True,
221
        help=softwrap(
222
            """
223
            If true, add a `go_mod` target with the `tailor` goal wherever there is a
224
            `go.mod` file.
225
            """
226
        ),
227
        advanced=True,
228
    )
UNCOV
229
    tailor_package_targets = BoolOption(
×
230
        default=True,
231
        help=softwrap(
232
            """
233
            If true, add a `go_package` target with the `tailor` goal in every directory with a
234
            `.go` file.
235
            """
236
        ),
237
        advanced=True,
238
    )
UNCOV
239
    tailor_binary_targets = BoolOption(
×
240
        default=True,
241
        help=softwrap(
242
            """
243
            If true, add a `go_binary` target with the `tailor` goal in every directory with a
244
            `.go` file with `package main`.
245
            """
246
        ),
247
        advanced=True,
248
    )
249

UNCOV
250
    cgo_enabled = BoolOption(
×
251
        default=True,
252
        help=softwrap(
253
            """\
254
            Enable Cgo support, which allows Go and C code to interact. This option must be enabled for any
255
            packages making use of Cgo to actually be compiled with Cgo support.
256

257
            See https://go.dev/blog/cgo and https://pkg.go.dev/cmd/cgo for additional information about Cgo.
258
            """
259
        ),
260
    )
261

UNCOV
262
    asdf_tool_name = StrOption(
×
263
        default="go-sdk",
264
        help=softwrap(
265
            """
266
            The ASDF tool name to use when searching for installed Go distributions using the ASDF tool
267
            manager (https://asdf-vm.com/). The default value for this option is for the `go-sdk` ASDF plugin
268
            (https://github.com/yacchi/asdf-go-sdk.git). There are other plugins. If you wish to use one of them,
269
            then set this option to the ASDF tool name under which that other plugin was installed into ASDF.
270
            """
271
        ),
272
        advanced=True,
273
    )
274

UNCOV
275
    asdf_bin_relpath = StrOption(
×
276
        default="bin",
277
        help=softwrap(
278
            """
279
            The path relative to an ASDF install directory to use to find the `bin` directory within an installed
280
            Go distribution. The default value for this option works for the `go-sdk` ASDF plugin. Other ASDF
281
            plugins that install Go may have a different relative path to use.
282
            """
283
        ),
284
        advanced=True,
285
    )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc