@@ -69,23 +69,30 @@ def _rewrite_needs_json_to_sourcelinks(labels):
6969 out .append (s )
7070 return out
7171
72- def _merge_sourcelinks (name , sourcelinks ):
72+ def _merge_sourcelinks (name , sourcelinks , known_good = None ):
7373 """Merge multiple sourcelinks JSON files into a single file.
7474
7575 Args:
7676 name: Name for the merged sourcelinks target
7777 sourcelinks: List of sourcelinks JSON file targets
7878 """
7979
80+ extra_srcs = []
81+ known_good_arg = ""
82+ if known_good != None :
83+ extra_srcs = [known_good ]
84+ known_good_arg = "--known_good $(location %s)" % known_good
85+
8086 native .genrule (
8187 name = name ,
82- srcs = sourcelinks ,
88+ srcs = sourcelinks + extra_srcs ,
8389 outs = [name + ".json" ],
8490 cmd = """
8591 $(location @score_docs_as_code//scripts_bazel:merge_sourcelinks) \
8692 --output $@ \
93+ {known_good_arg} \
8794 $(SRCS)
88- """ ,
95+ """ . format ( known_good_arg = known_good_arg ) ,
8996 tools = ["@score_docs_as_code//scripts_bazel:merge_sourcelinks" ],
9097 )
9198
@@ -120,7 +127,7 @@ def _missing_requirements(deps):
120127 fail (msg )
121128 fail ("This case should be unreachable?!" )
122129
123- def docs (source_dir = "docs" , data = [], deps = [], scan_code = []):
130+ def docs (source_dir = "docs" , data = [], deps = [], scan_code = [], known_good = None ):
124131 """Creates all targets related to documentation.
125132
126133 By using this function, you'll get any and all updates for documentation targets in one place.
@@ -175,34 +182,45 @@ def docs(source_dir = "docs", data = [], deps = [], scan_code = []):
175182
176183 data_with_docs_sources = _rewrite_needs_json_to_docs_sources (data )
177184 additional_combo_sourcelinks = _rewrite_needs_json_to_sourcelinks (data )
178- _merge_sourcelinks (name = "merged_sourcelinks" , sourcelinks = [":sourcelinks_json" ] + additional_combo_sourcelinks )
185+ _merge_sourcelinks (name = "merged_sourcelinks" , sourcelinks = [":sourcelinks_json" ] + additional_combo_sourcelinks , known_good = known_good )
186+ docs_data = data + [":sourcelinks_json" ]
187+ combo_data = data_with_docs_sources + [":merged_sourcelinks" ]
188+
189+ docs_env = {
190+ "SOURCE_DIRECTORY" : source_dir ,
191+ "DATA" : str (data ),
192+ "SCORE_SOURCELINKS" : "$(location :sourcelinks_json)" ,
193+ }
194+ docs_sources_env = {
195+ "SOURCE_DIRECTORY" : source_dir ,
196+ "DATA" : str (data_with_docs_sources ),
197+ "SCORE_SOURCELINKS" : "$(location :merged_sourcelinks)" ,
198+ }
199+ if known_good :
200+ docs_env ["KNOWN_GOOD_JSON" ] = "$(location " + known_good + ")"
201+ docs_sources_env ["KNOWN_GOOD_JSON" ] = "$(location " + known_good + ")"
202+ docs_data .append (known_good )
203+ combo_data .append (known_good )
204+
205+ docs_env ["ACTION" ] = "incremental"
179206
180207 py_binary (
181208 name = "docs" ,
182209 tags = ["cli_help=Build documentation:\n bazel run //:docs" ],
183210 srcs = ["@score_docs_as_code//src:incremental.py" ],
184- data = data + [ ":sourcelinks_json" ] ,
211+ data = docs_data ,
185212 deps = deps ,
186- env = {
187- "SOURCE_DIRECTORY" : source_dir ,
188- "DATA" : str (data ),
189- "ACTION" : "incremental" ,
190- "SCORE_SOURCELINKS" : "$(location :sourcelinks_json)" ,
191- },
213+ env = docs_env
192214 )
193215
216+ docs_sources_env ["ACTION" ] = "incremental"
194217 py_binary (
195218 name = "docs_combo" ,
196219 tags = ["cli_help=Build full documentation with all dependencies:\n bazel run //:docs_combo" ],
197220 srcs = ["@score_docs_as_code//src:incremental.py" ],
198- data = data_with_docs_sources + [ ":merged_sourcelinks" ] ,
221+ data = combo_data ,
199222 deps = deps ,
200- env = {
201- "SOURCE_DIRECTORY" : source_dir ,
202- "DATA" : str (data_with_docs_sources ),
203- "ACTION" : "incremental" ,
204- "SCORE_SOURCELINKS" : "$(location :merged_sourcelinks)" ,
205- },
223+ env = docs_sources_env
206224 )
207225
208226 native .alias (
@@ -211,59 +229,44 @@ def docs(source_dir = "docs", data = [], deps = [], scan_code = []):
211229 deprecation = "Target '//:docs_combo_experimental' is deprecated. Use '//:docs_combo' instead." ,
212230 )
213231
232+ docs_env ["ACTION" ] = "linkcheck"
214233 py_binary (
215234 name = "docs_link_check" ,
216235 tags = ["cli_help=Verify Links inside Documentation:\n bazel run //:link_check\n (Note: this could take a long time)" ],
217236 srcs = ["@score_docs_as_code//src:incremental.py" ],
218- data = data ,
237+ data = docs_data ,
219238 deps = deps ,
220- env = {
221- "SOURCE_DIRECTORY" : source_dir ,
222- "DATA" : str (data ),
223- "ACTION" : "linkcheck" ,
224- },
239+ env = docs_env
225240 )
226241
242+ docs_env ["ACTION" ] = "check"
227243 py_binary (
228244 name = "docs_check" ,
229245 tags = ["cli_help=Verify documentation:\n bazel run //:docs_check" ],
230246 srcs = ["@score_docs_as_code//src:incremental.py" ],
231- data = data + [ ":sourcelinks_json" ] ,
247+ data = docs_data ,
232248 deps = deps ,
233- env = {
234- "SOURCE_DIRECTORY" : source_dir ,
235- "DATA" : str (data ),
236- "ACTION" : "check" ,
237- "SCORE_SOURCELINKS" : "$(location :sourcelinks_json)" ,
238- },
249+ env = docs_env
239250 )
240251
252+ docs_env ["ACTION" ] = "live_preview"
241253 py_binary (
242254 name = "live_preview" ,
243255 tags = ["cli_help=Live preview documentation in the browser:\n bazel run //:live_preview" ],
244256 srcs = ["@score_docs_as_code//src:incremental.py" ],
245- data = data + [ ":sourcelinks_json" ] ,
257+ data = docs_data ,
246258 deps = deps ,
247- env = {
248- "SOURCE_DIRECTORY" : source_dir ,
249- "DATA" : str (data ),
250- "ACTION" : "live_preview" ,
251- "SCORE_SOURCELINKS" : "$(location :sourcelinks_json)" ,
252- },
259+ env = docs_env
253260 )
254261
262+ docs_sources_env ["ACTION" ] = "live_preview"
255263 py_binary (
256264 name = "live_preview_combo_experimental" ,
257265 tags = ["cli_help=Live preview full documentation with all dependencies in the browser:\n bazel run //:live_preview_combo_experimental" ],
258266 srcs = ["@score_docs_as_code//src:incremental.py" ],
259- data = data_with_docs_sources + [ ":merged_sourcelinks" ] ,
267+ data = combo_data ,
260268 deps = deps ,
261- env = {
262- "SOURCE_DIRECTORY" : source_dir ,
263- "DATA" : str (data_with_docs_sources ),
264- "ACTION" : "live_preview" ,
265- "SCORE_SOURCELINKS" : "$(location :merged_sourcelinks)" ,
266- },
269+ env = docs_sources_env
267270 )
268271
269272 score_virtualenv (
0 commit comments