1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- ###############################################################################
16- # To regenerate documentation, run the top-level update_docs.sh script. #
17- ###############################################################################
18-
1915load ("@bazel_skylib//:bzl_library.bzl" , "bzl_library" )
16+ load ("@bazel_skylib//rules:diff_test.bzl" , "diff_test" )
17+ load ("@bazel_skylib//rules:write_file.bzl" , "write_file" )
2018load ("@io_bazel_stardoc//stardoc:stardoc.bzl" , "stardoc" )
2119
2220package (default_visibility = ["//visibility:public" ])
2321
2422licenses (["notice" ]) # Apache 2.0
2523
24+ _DOCS = {
25+ "packaging" : "//docs:packaging-docs" ,
26+ "pip" : "//docs:pip-docs" ,
27+ "python" : "//docs:core-docs" ,
28+ "whl" : "//docs:whl-docs" ,
29+ }
30+
2631# We define these bzl_library targets here rather than in the //python package
2732# because they're only used for doc generation. This way, we avoid requiring
2833# our users to depend on Skylib.
@@ -68,7 +73,7 @@ bzl_library(
6873
6974stardoc (
7075 name = "core-docs" ,
71- out = "python.md " ,
76+ out = "python.md_ " ,
7277 input = "//python:defs.bzl" ,
7378 deps = [":defs" ],
7479)
@@ -79,7 +84,7 @@ stardoc(
7984
8085stardoc (
8186 name = "pip-docs" ,
82- out = "pip.md " ,
87+ out = "pip.md_ " ,
8388 input = "//python:pip.bzl" ,
8489 deps = [
8590 ":bazel_repo_tools" ,
@@ -90,12 +95,40 @@ stardoc(
9095
9196stardoc (
9297 name = "whl-docs" ,
93- out = "whl.md " ,
98+ out = "whl.md_ " ,
9499 input = "//python:whl.bzl" ,
95100)
96101
97102stardoc (
98103 name = "packaging-docs" ,
99- out = "packaging.md " ,
104+ out = "packaging.md_ " ,
100105 input = "//python:packaging.bzl" ,
101106)
107+
108+ [
109+ diff_test (
110+ name = "check_" + k ,
111+ failure_message = "Please run: bazel run //docs:update" ,
112+ file1 = k + ".md" ,
113+ file2 = k + ".md_" ,
114+ )
115+ for k in _DOCS .keys ()
116+ ]
117+
118+ write_file (
119+ name = "gen_update" ,
120+ out = "update.sh" ,
121+ content = [
122+ "#!/usr/bin/env bash" ,
123+ "cd $BUILD_WORKSPACE_DIRECTORY" ,
124+ ] + [
125+ "cp -fv bazel-bin/docs/{0}.md_ docs/{0}.md" .format (k )
126+ for k in _DOCS .keys ()
127+ ],
128+ )
129+
130+ sh_binary (
131+ name = "update" ,
132+ srcs = ["update.sh" ],
133+ data = _DOCS .values (),
134+ )
0 commit comments