@@ -81,11 +81,13 @@ def emit_compilepkg(
81
81
fail ("sources is a required parameter" )
82
82
if out_lib == None :
83
83
fail ("out_lib is a required parameter" )
84
- if bool (nogo ) != bool (out_facts ):
84
+
85
+ have_nogo = nogo != None
86
+ if have_nogo != (out_facts != None ):
85
87
fail ("nogo must be specified if and only if out_facts is specified" )
86
- if bool ( nogo ) != bool (out_nogo_log ):
88
+ if have_nogo != (out_nogo_log != None ):
87
89
fail ("nogo must be specified if and only if out_nogo_log is specified" )
88
- if bool ( nogo ) != bool (out_nogo_validation ):
90
+ if have_nogo != (out_nogo_validation != None ):
89
91
fail ("nogo must be specified if and only if out_nogo_validation is specified" )
90
92
91
93
if cover and go .coverdata :
@@ -97,52 +99,53 @@ def emit_compilepkg(
97
99
inputs_transitive = [sdk .headers , sdk .tools , go .stdlib .libs ]
98
100
outputs = [out_lib , out_export ]
99
101
100
- args = go .builder_args (go , "compilepkg" , use_path_mapping = True )
101
- args .add_all (sources , before_each = "-src" )
102
- args .add_all (embedsrcs , before_each = "-embedsrc" , expand_directories = False )
103
- args .add_all (
102
+ shared_args = go .builder_args (go , use_path_mapping = True )
103
+ shared_args .add_all (sources , before_each = "-src" )
104
+
105
+ compile_args = go .tool_args (go )
106
+ compile_args .add_all (embedsrcs , before_each = "-embedsrc" , expand_directories = False )
107
+ compile_args .add_all (
104
108
sources + [out_lib ] + embedsrcs ,
105
109
map_each = _embedroot_arg ,
106
110
before_each = "-embedroot" ,
107
111
uniquify = True ,
108
112
expand_directories = False ,
109
113
)
110
- args .add_all (
114
+ compile_args .add_all (
111
115
sources + [out_lib ],
112
116
map_each = _embedlookupdir_arg ,
113
117
before_each = "-embedlookupdir" ,
114
118
uniquify = True ,
115
119
expand_directories = False ,
116
120
)
117
121
118
- cover_mode = None
119
122
if cover and go .coverdata :
120
123
if go .mode .race :
121
124
cover_mode = "atomic"
122
125
else :
123
126
cover_mode = "set"
124
- args .add ("-cover_mode" , cover_mode )
125
- args .add ("-cover_format" , go .mode .cover_format )
126
- args .add_all (cover , before_each = "-cover" )
127
+ shared_args .add ("-cover_mode" , cover_mode )
128
+ compile_args .add ("-cover_format" , go .mode .cover_format )
129
+ compile_args .add_all (cover , before_each = "-cover" )
127
130
128
- args .add_all (archives , before_each = "-arc" , map_each = _archive )
131
+ shared_args .add_all (archives , before_each = "-arc" , map_each = _archive )
129
132
if recompile_internal_deps :
130
- args .add_all (recompile_internal_deps , before_each = "-recompile_internal_deps" )
133
+ shared_args .add_all (recompile_internal_deps , before_each = "-recompile_internal_deps" )
131
134
if importpath :
132
- args .add ("-importpath" , importpath )
135
+ shared_args .add ("-importpath" , importpath )
133
136
else :
134
- args .add ("-importpath" , go .label .name )
137
+ shared_args .add ("-importpath" , go .label .name )
135
138
if importmap :
136
- args .add ("-p" , importmap )
137
- args .add ("-package_list" , sdk .package_list )
139
+ shared_args .add ("-p" , importmap )
140
+ shared_args .add ("-package_list" , sdk .package_list )
138
141
139
- args .add ("-lo" , out_lib )
140
- args .add ("-o" , out_export )
142
+ compile_args .add ("-lo" , out_lib )
143
+ compile_args .add ("-o" , out_export )
141
144
if out_cgo_export_h :
142
- args .add ("-cgoexport" , out_cgo_export_h )
145
+ compile_args .add ("-cgoexport" , out_cgo_export_h )
143
146
outputs .append (out_cgo_export_h )
144
147
if testfilter :
145
- args .add ("-testfilter" , testfilter )
148
+ shared_args .add ("-testfilter" , testfilter )
146
149
147
150
link_mode_flag = link_mode_arg (go .mode )
148
151
@@ -156,10 +159,10 @@ def emit_compilepkg(
156
159
gc_flags .extend (go .toolchain .flags .compile )
157
160
if link_mode_flag :
158
161
gc_flags .append (link_mode_flag )
159
- args .add ("-gcflags" , quote_opts (gc_flags ))
162
+ compile_args .add ("-gcflags" , quote_opts (gc_flags ))
160
163
161
164
if link_mode_flag :
162
- args .add ("-asmflags" , link_mode_flag )
165
+ compile_args .add ("-asmflags" , link_mode_flag )
163
166
164
167
# cgo and the linker action don't support path mapping yet
165
168
# TODO: Remove the second condition after https://github.com/bazelbuild/bazel/pull/21921.
@@ -175,33 +178,33 @@ def emit_compilepkg(
175
178
if nogo :
176
179
cgo_go_srcs_for_nogo = go .declare_directory (go , path = out_lib .basename + ".cgo" )
177
180
outputs .append (cgo_go_srcs_for_nogo )
178
- args .add ("-cgo_go_srcs" , cgo_go_srcs_for_nogo .path )
181
+ compile_args .add ("-cgo_go_srcs" , cgo_go_srcs_for_nogo .path )
179
182
inputs_transitive .append (cgo_inputs )
180
183
inputs_transitive .append (go .cc_toolchain_files )
181
184
env ["CC" ] = go .cgo_tools .c_compiler_path
182
185
if cppopts :
183
- args .add ("-cppflags" , quote_opts (cppopts ))
186
+ compile_args .add ("-cppflags" , quote_opts (cppopts ))
184
187
if copts :
185
- args .add ("-cflags" , quote_opts (copts ))
188
+ compile_args .add ("-cflags" , quote_opts (copts ))
186
189
if cxxopts :
187
- args .add ("-cxxflags" , quote_opts (cxxopts ))
190
+ compile_args .add ("-cxxflags" , quote_opts (cxxopts ))
188
191
if objcopts :
189
- args .add ("-objcflags" , quote_opts (objcopts ))
192
+ compile_args .add ("-objcflags" , quote_opts (objcopts ))
190
193
if objcxxopts :
191
- args .add ("-objcxxflags" , quote_opts (objcxxopts ))
194
+ compile_args .add ("-objcxxflags" , quote_opts (objcxxopts ))
192
195
if clinkopts :
193
- args .add ("-ldflags" , quote_opts (clinkopts ))
196
+ compile_args .add ("-ldflags" , quote_opts (clinkopts ))
194
197
195
198
if go .mode .pgoprofile :
196
- args .add ("-pgoprofile" , go .mode .pgoprofile )
199
+ compile_args .add ("-pgoprofile" , go .mode .pgoprofile )
197
200
inputs_direct .append (go .mode .pgoprofile )
198
201
199
202
go .actions .run (
200
203
inputs = depset (inputs_direct , transitive = inputs_transitive ),
201
204
outputs = outputs ,
202
205
mnemonic = "GoCompilePkgExternal" if is_external_pkg else "GoCompilePkg" ,
203
206
executable = go .toolchain ._builder ,
204
- arguments = [args ],
207
+ arguments = ["compilepkg" , shared_args , compile_args ],
205
208
env = env ,
206
209
toolchain = GO_TOOLCHAIN_LABEL ,
207
210
execution_requirements = execution_requirements ,
@@ -210,14 +213,10 @@ def emit_compilepkg(
210
213
if nogo :
211
214
_run_nogo (
212
215
go ,
216
+ shared_args = shared_args ,
213
217
sources = sources ,
214
218
cgo_go_srcs = cgo_go_srcs_for_nogo ,
215
- importpath = importpath ,
216
- importmap = importmap ,
217
219
archives = archives ,
218
- recompile_internal_deps = recompile_internal_deps ,
219
- cover_mode = cover_mode ,
220
- testfilter = testfilter ,
221
220
out_facts = out_facts ,
222
221
out_log = out_nogo_log ,
223
222
out_validation = out_nogo_validation ,
@@ -226,15 +225,11 @@ def emit_compilepkg(
226
225
227
226
def _run_nogo (
228
227
go ,
228
+ shared_args ,
229
229
* ,
230
230
sources ,
231
231
cgo_go_srcs ,
232
- importpath ,
233
- importmap ,
234
232
archives ,
235
- recompile_internal_deps ,
236
- cover_mode ,
237
- testfilter ,
238
233
out_facts ,
239
234
out_log ,
240
235
out_validation ,
@@ -248,30 +243,15 @@ def _run_nogo(
248
243
inputs_transitive = [sdk .tools , sdk .headers , go .stdlib .libs ]
249
244
outputs = [out_facts , out_log ]
250
245
251
- args = go .builder_args (go , "nogo" , use_path_mapping = True )
252
- args .add_all (sources , before_each = "-src" )
246
+ nogo_args = go .tool_args (go )
253
247
if cgo_go_srcs :
254
248
inputs_direct .append (cgo_go_srcs )
255
- args .add_all ([cgo_go_srcs ], before_each = "-ignore_src" )
256
- if cover_mode :
257
- args .add ("-cover_mode" , cover_mode )
258
- if recompile_internal_deps :
259
- args .add_all (recompile_internal_deps , before_each = "-recompile_internal_deps" )
260
- args .add_all (archives , before_each = "-arc" , map_each = _archive )
261
- if importpath :
262
- args .add ("-importpath" , importpath )
263
- else :
264
- args .add ("-importpath" , go .label .name )
265
- if importmap :
266
- args .add ("-p" , importmap )
267
- args .add ("-package_list" , sdk .package_list )
268
- if testfilter :
269
- args .add ("-testfilter" , testfilter )
249
+ nogo_args .add_all ([cgo_go_srcs ], before_each = "-ignore_src" )
270
250
271
- args .add_all (archives , before_each = "-facts" , map_each = _facts )
272
- args .add ("-out_facts" , out_facts )
273
- args .add ("-out_log" , out_log )
274
- args .add ("-nogo" , nogo )
251
+ nogo_args .add_all (archives , before_each = "-facts" , map_each = _facts )
252
+ nogo_args .add ("-out_facts" , out_facts )
253
+ nogo_args .add ("-out_log" , out_log )
254
+ nogo_args .add ("-nogo" , nogo )
275
255
276
256
# This action runs nogo and produces the facts files for downstream nogo actions.
277
257
# It is important that this action doesn't fail if nogo produces findings, which allows users
@@ -285,7 +265,7 @@ def _run_nogo(
285
265
outputs = outputs ,
286
266
mnemonic = "RunNogo" ,
287
267
executable = go .toolchain ._builder ,
288
- arguments = [args ],
268
+ arguments = ["nogo" , shared_args , nogo_args ],
289
269
env = go .env_for_path_mapping ,
290
270
toolchain = GO_TOOLCHAIN_LABEL ,
291
271
execution_requirements = SUPPORTS_PATH_MAPPING_REQUIREMENT ,
0 commit comments