@@ -45,7 +45,17 @@ def sphinx_build_binary(name, py_binary_rule = py_binary, **kwargs):
4545 ** kwargs
4646 )
4747
48- def sphinx_docs (name , * , srcs = [], sphinx , config , formats , strip_prefix = "" , extra_opts = [], ** kwargs ):
48+ def sphinx_docs (
49+ name ,
50+ * ,
51+ srcs = [],
52+ renamed_srcs = {},
53+ sphinx ,
54+ config ,
55+ formats ,
56+ strip_prefix = "" ,
57+ extra_opts = [],
58+ ** kwargs ):
4959 """Generate docs using Sphinx.
5060
5161 This generates three public targets:
@@ -62,6 +72,9 @@ def sphinx_docs(name, *, srcs = [], sphinx, config, formats, strip_prefix = "",
6272 Args:
6373 name: (str) name of the docs rule.
6474 srcs: (label list) The source files for Sphinx to process.
75+ renamed_srcs: (label_keyed_string_dict) Doc source files for Sphinx that
76+ are renamed. This is typically used for files elsewhere, such as top
77+ level files in the repo.
6578 sphinx: (label) the Sphinx tool to use for building
6679 documentation. Because Sphinx supports various plugins, you must
6780 construct your own binary with the necessary dependencies. The
@@ -83,6 +96,7 @@ def sphinx_docs(name, *, srcs = [], sphinx, config, formats, strip_prefix = "",
8396 _sphinx_docs (
8497 name = name ,
8598 srcs = srcs ,
99+ renamed_srcs = renamed_srcs ,
86100 sphinx = sphinx ,
87101 config = config ,
88102 formats = formats ,
@@ -143,6 +157,12 @@ _sphinx_docs = rule(
143157 "other options, but before the source/output args." ,
144158 ),
145159 "formats" : attr .string_list (doc = "Output formats for Sphinx to create." ),
160+ "renamed_srcs" : attr .label_keyed_string_dict (
161+ allow_files = True ,
162+ doc = "Doc source files for Sphinx that are renamed. This is " +
163+ "typically used for files elsewhere, such as top level " +
164+ "files in the repo." ,
165+ ),
146166 "sphinx" : attr .label (
147167 executable = True ,
148168 cfg = "exec" ,
@@ -189,6 +209,23 @@ def _create_sphinx_source_tree(ctx):
189209 for orig_file in ctx .files .srcs :
190210 _symlink_source (orig_file )
191211
212+ for src_target , dest in ctx .attr .renamed_srcs .items ():
213+ src_files = src_target .files .to_list ()
214+ if len (src_files ) != 1 :
215+ fail ("A single file must be specified to be renamed. Target {} " +
216+ "generate {} files: {}" .format (
217+ src_target ,
218+ len (src_files ),
219+ src_files ,
220+ ))
221+ sphinx_src = ctx .actions .declare_file (paths .join (source_prefix , dest ))
222+ ctx .actions .symlink (
223+ output = sphinx_src ,
224+ target_file = src_files [0 ],
225+ progress_message = "Symlinking (renamed) Sphinx source %{input} to %{output}" ,
226+ )
227+ sphinx_source_files .append (sphinx_src )
228+
192229 return sphinx_source_dir_path , source_conf_file , sphinx_source_files
193230
194231def _run_sphinx (ctx , format , source_path , inputs , output_prefix ):
0 commit comments