diff --git a/doc_build/BUILD b/doc_build/BUILD index b47c1798..e4e3678c 100644 --- a/doc_build/BUILD +++ b/doc_build/BUILD @@ -11,16 +11,39 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +"""Generate the reference documentation. + +How to: + bazel build //doc_build:reference + cp bazel-bin/doc_build/reference.md docs/latest.md + git commit -m 'update docs' docs/latest.md +""" load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_stardoc//stardoc:stardoc.bzl", "stardoc") +load("@rules_python//python:defs.bzl", "py_library") load("//:version.bzl", "version") -# HOW TO: -# bazel build //doc_build:reference -# cp bazel-bin/doc_build/reference.md docs/latest.md -# git commit -m 'update docs' docs/latest.md +filegroup( + name = "standard_package", + srcs = [ + "BUILD", + ] + glob([ + "*.bzl", + "*.py", + ]), + visibility = ["//distro:__pkg__"], +) +exports_files( + glob([ + "*.bzl", + ]), + visibility = [ + "//distro:__pkg__", + "//doc_build:__pkg__", + ], +) # pairs of rule name and the source file to get it from # buildifier: leave-alone, do not sort @@ -42,9 +65,8 @@ genrule( name = "reference", srcs = ["%s.md" % rule for rule, _ in ORDER], outs = ["reference.md"], - # Compensate for https://github.com/bazelbuild/stardoc/issues/118. - # Convert escaped HTML
  • back to raw text - cmd = "cat $(SRCS) | sed -e 's/<li>/
  • /g' >$@", + cmd = "$(location :merge) $(SRCS) >$@", + exec_tools = [":merge"], ) [ @@ -107,3 +129,11 @@ bzl_library( ], visibility = ["//visibility:private"], ) + +py_binary( + name = "merge", + srcs = ["merge.py"], + python_version = "PY3", + srcs_version = "PY3", + visibility = ["//visibility:private"], +) diff --git a/doc_build/merge.py b/doc_build/merge.py new file mode 100755 index 00000000..d4a7e550 --- /dev/null +++ b/doc_build/merge.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 +# Copyright 2022 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""merge stardoc output into a single page. + +- concatenates files +- corrects things that stardoc botches +""" + +import re +import sys +import typing + + +ID_RE = re.compile(r'') +WRAPS_RE = re.compile(r'@wraps\((.*)\)') +CENTER_RE = re.compile(r'

    ([^<]*)

    ') + + +def merge_file(file: str, out, wrapper_map:typing.Dict[str, str]) -> None: + with open(file, 'r') as inp: + content = inp.read() + m = ID_RE.search(content) + this_pkg = m.group(1) if m else None + m = WRAPS_RE.search(content) + if m: + # I wrap something, so don't emit me. + wrapper_map[m.group(1)] = this_pkg + return + # If something wraps me, rewrite myself with the wrapper name. + if this_pkg in wrapper_map: + content = content.replace(this_pkg, wrapper_map[this_pkg]) + merge_text(content, out) + + +def merge_text(text: str, out) -> None: + """Merge a block of text into an output stream. + + Args: + text: block of text produced by Starroc. + out: an output file stream. + """ + for line in text.split('\n'): + if line.startswith('| :'): + line = fix_stardoc_table_align(line) + # Compensate for https://github.com/bazelbuild/stardoc/issues/118. + # Convert escaped HTML
  • back to raw text + line = line.replace('<li>', '
  • ') + line = CENTER_RE.sub(r'\1', line) + _ = out.write(line) + _ = out.write('\n') + + +def fix_stardoc_table_align(line: str) -> str: + """Change centered descriptions to left justified.""" + if line.startswith('| :-------------: | :-------------: '): + return '| :------------ | :--------------- | :---------: | :---------: | :----------- |' + return line + + +def main(argv: typing.Sequence[str]) -> None: + wrapper_map = {} + for file in argv[1:]: + merge_file(file, sys.stdout, wrapper_map) + + +if __name__ == '__main__': + main(sys.argv) diff --git a/docs/latest.md b/docs/latest.md index f23aa1be..e8ec2328 100755 --- a/docs/latest.md +++ b/docs/latest.md @@ -26,6 +26,7 @@
  • //pkg:mappings.bzl%strip_prefix
  • + ### Common Attributes @@ -75,6 +76,7 @@ should not be relied upon. Any other attributes should be specified as additional arguments to `pkg_attributes`. + Rule for creating Debian packages. @@ -84,36 +86,12 @@ Rule for creating Debian packages. ## pkg_deb
    -pkg_deb(name, archive_name, kwargs)
    -
    - -Creates a deb file. See pkg_deb_impl. - -**PARAMETERS** - - -| Name | Description | Default Value | -| :------------- | :------------- | :------------- | -| name |

    -

    | none | -| archive_name |

    -

    | None | -| kwargs |

    -

    | none | - - - - -Rule for creating Debian packages. - - - -## pkg_deb_impl - -
    -pkg_deb_impl(name, architecture, architecture_file, breaks, built_using, built_using_file,
    -             conffiles, conffiles_file, config, conflicts, data, depends, depends_file, description,
    -             description_file, distribution, enhances, homepage, maintainer, out, package,
    -             package_file_name, package_variables, postinst, postrm, predepends, preinst, prerm,
    -             priority, provides, recommends, replaces, section, suggests, templates, triggers,
    -             urgency, version, version_file)
    +pkg_deb(name, architecture, architecture_file, breaks, built_using, built_using_file,
    +             conffiles, conffiles_file, config, conflicts, data, depends, depends_file, description,
    +             description_file, distribution, enhances, homepage, maintainer, out, package,
    +             package_file_name, package_variables, postinst, postrm, predepends, preinst, prerm,
    +             priority, provides, recommends, replaces, section, suggests, templates, triggers,
    +             urgency, version, version_file)
     
    @@ -123,45 +101,46 @@ pkg_deb_impl(name, name | A unique name for this target. | Name | required | | -| architecture | Package architecture. Must not be used with architecture_file. | String | optional | "all" | -| architecture_file | File that contains the package architecture. Must not be used with architecture. | Label | optional | None | -| breaks | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | -| built_using | The tool that were used to build this package provided either inline (with built_using) or from a file (with built_using_file). | String | optional | "" | -| built_using_file | The tool that were used to build this package provided either inline (with built_using) or from a file (with built_using_file). | Label | optional | None | -| conffiles | The list of conffiles or a file containing one conffile per line. Each item is an absolute path on the target system where the deb is installed. See https://www.debian.org/doc/debian-policy/ch-files.html#s-config-files. | List of strings | optional | [] | -| conffiles_file | The list of conffiles or a file containing one conffile per line. Each item is an absolute path on the target system where the deb is installed. See https://www.debian.org/doc/debian-policy/ch-files.html#s-config-files. | Label | optional | None | -| config | config file used for debconf integration. See https://www.debian.org/doc/debian-policy/ch-binary.html#prompting-in-maintainer-scripts. | Label | optional | None | -| conflicts | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | -| data | A tar file that contains the data for the debian package. | Label | required | | -| depends | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | -| depends_file | File that contains a list of package dependencies. Must not be used with depends. See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | Label | optional | None | -| description | The package description. Must not be used with description_file. | String | optional | "" | -| description_file | The package description. Must not be used with description. | Label | optional | None | -| distribution | "distribution: See http://www.debian.org/doc/debian-policy. | String | optional | "unstable" | -| enhances | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | -| homepage | The homepage of the project. | String | optional | "" | -| maintainer | The maintainer of the package. | String | required | | -| out | See Common Attributes | Label | required | | -| package | The name of the package | String | required | | -| package_file_name | See Common Attributes. Default: "{package}-{version}-{architecture}.deb | String | optional | "" | -| package_variables | See Common Attributes | Label | optional | None | -| postinst | The post-install script for the package. See http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html. | Label | optional | None | -| postrm | The post-remove script for the package. See http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html. | Label | optional | None | -| predepends | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | -| preinst | "The pre-install script for the package. See http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html. | Label | optional | None | -| prerm | The pre-remove script for the package. See http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html. | Label | optional | None | -| priority | The priority of the package. See http://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities. | String | optional | "" | -| provides | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | -| recommends | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | -| replaces | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | -| section | The section of the package. See http://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections. | String | optional | "" | -| suggests | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | -| templates | templates file used for debconf integration. See https://www.debian.org/doc/debian-policy/ch-binary.html#prompting-in-maintainer-scripts. | Label | optional | None | -| triggers | triggers file for configuring installation events exchanged by packages. See https://wiki.debian.org/DpkgTriggers. | Label | optional | None | -| urgency | "urgency: See http://www.debian.org/doc/debian-policy. | String | optional | "medium" | -| version | Package version. Must not be used with version_file. | String | optional | "" | -| version_file | File that contains the package version. Must not be used with version. | Label | optional | None | +| name | A unique name for this target. | Name | required | | +| architecture | Package architecture. Must not be used with architecture_file. | String | optional | "all" | +| architecture_file | File that contains the package architecture. Must not be used with architecture. | Label | optional | None | +| breaks | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | +| built_using | The tool that were used to build this package provided either inline (with built_using) or from a file (with built_using_file). | String | optional | "" | +| built_using_file | The tool that were used to build this package provided either inline (with built_using) or from a file (with built_using_file). | Label | optional | None | +| conffiles | The list of conffiles or a file containing one conffile per line. Each item is an absolute path on the target system where the deb is installed. See https://www.debian.org/doc/debian-policy/ch-files.html#s-config-files. | List of strings | optional | [] | +| conffiles_file | The list of conffiles or a file containing one conffile per line. Each item is an absolute path on the target system where the deb is installed. See https://www.debian.org/doc/debian-policy/ch-files.html#s-config-files. | Label | optional | None | +| config | config file used for debconf integration. See https://www.debian.org/doc/debian-policy/ch-binary.html#prompting-in-maintainer-scripts. | Label | optional | None | +| conflicts | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | +| data | A tar file that contains the data for the debian package. | Label | required | | +| depends | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | +| depends_file | File that contains a list of package dependencies. Must not be used with depends. See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | Label | optional | None | +| description | The package description. Must not be used with description_file. | String | optional | "" | +| description_file | The package description. Must not be used with description. | Label | optional | None | +| distribution | "distribution: See http://www.debian.org/doc/debian-policy. | String | optional | "unstable" | +| enhances | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | +| homepage | The homepage of the project. | String | optional | "" | +| maintainer | The maintainer of the package. | String | required | | +| out | See Common Attributes | Label | required | | +| package | The name of the package | String | required | | +| package_file_name | See Common Attributes. Default: "{package}-{version}-{architecture}.deb | String | optional | "" | +| package_variables | See Common Attributes | Label | optional | None | +| postinst | The post-install script for the package. See http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html. | Label | optional | None | +| postrm | The post-remove script for the package. See http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html. | Label | optional | None | +| predepends | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | +| preinst | "The pre-install script for the package. See http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html. | Label | optional | None | +| prerm | The pre-remove script for the package. See http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html. | Label | optional | None | +| priority | The priority of the package. See http://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities. | String | optional | "" | +| provides | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | +| recommends | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | +| replaces | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | +| section | The section of the package. See http://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections. | String | optional | "" | +| suggests | See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps. | List of strings | optional | [] | +| templates | templates file used for debconf integration. See https://www.debian.org/doc/debian-policy/ch-binary.html#prompting-in-maintainer-scripts. | Label | optional | None | +| triggers | triggers file for configuring installation events exchanged by packages. See https://wiki.debian.org/DpkgTriggers. | Label | optional | None | +| urgency | "urgency: See http://www.debian.org/doc/debian-policy. | String | optional | "medium" | +| version | Package version. Must not be used with version_file. | String | optional | "" | +| version_file | File that contains the package version. Must not be used with version. | Label | optional | None | + @@ -264,6 +243,7 @@ Creates an RPM format package via `pkg_filegroup` and friends. | version_file | File containing RPM "Version" tag. | Label | optional | None | + Rules for making .tar files. @@ -273,33 +253,10 @@ Rules for making .tar files. ## pkg_tar
    -pkg_tar(name, kwargs)
    -
    - -Creates a .tar file. See pkg_tar_impl. - -**PARAMETERS** - - -| Name | Description | Default Value | -| :------------- | :------------- | :------------- | -| name |

    -

    | none | -| kwargs |

    -

    | none | - - - - -Rules for making .tar files. - - - -## pkg_tar_impl - -
    -pkg_tar_impl(name, build_tar, compressor, compressor_args, deps, empty_dirs, empty_files, extension,
    -             files, include_runfiles, mode, modes, mtime, out, owner, ownername, ownernames, owners,
    -             package_base, package_dir, package_dir_file, package_file_name, package_variables,
    -             portable_mtime, private_stamp_detect, remap_paths, srcs, stamp, strip_prefix, symlinks)
    +pkg_tar(name, build_tar, compressor, compressor_args, deps, empty_dirs, empty_files, extension,
    +             files, include_runfiles, mode, modes, mtime, out, owner, ownername, ownernames, owners,
    +             package_base, package_dir, package_dir_file, package_file_name, package_variables,
    +             portable_mtime, private_stamp_detect, remap_paths, srcs, stamp, strip_prefix, symlinks)
     
    @@ -309,36 +266,37 @@ pkg_tar_impl(name, name | A unique name for this target. | Name | required | | -| build_tar | - | Label | optional | //pkg/private/tar:build_tar | -| compressor | - | Label | optional | None | -| compressor_args | - | String | optional | "" | -| deps | - | List of labels | optional | [] | -| empty_dirs | - | List of strings | optional | [] | -| empty_files | - | List of strings | optional | [] | -| extension | - | String | optional | "tar" | -| files | - | Dictionary: Label -> String | optional | {} | -| include_runfiles | - | Boolean | optional | False | -| mode | - | String | optional | "0555" | -| modes | - | Dictionary: String -> String | optional | {} | -| mtime | - | Integer | optional | -1 | -| out | - | Label | required | | -| owner | - | String | optional | "0.0" | -| ownername | - | String | optional | "." | -| ownernames | - | Dictionary: String -> String | optional | {} | -| owners | - | Dictionary: String -> String | optional | {} | -| package_base | - | String | optional | "./" | -| package_dir | - | String | optional | "" | -| package_dir_file | - | Label | optional | None | -| package_file_name | See Common Attributes | String | optional | "" | -| package_variables | See Common Attributes | Label | optional | None | -| portable_mtime | - | Boolean | optional | True | -| private_stamp_detect | - | Boolean | optional | False | -| remap_paths | - | Dictionary: String -> String | optional | {} | -| srcs | - | List of labels | optional | [] | -| stamp | Enable file time stamping. Possible values:
  • stamp = 1: Use the time of the build as the modification time of each file in the archive.
  • stamp = 0: Use an "epoch" time for the modification time of each file. This gives good build result caching.
  • stamp = -1: Control the chosen modification time using the --[no]stamp flag. | Integer | optional | 0 | -| strip_prefix | - | String | optional | "" | -| symlinks | - | Dictionary: String -> String | optional | {} | +| name | A unique name for this target. | Name | required | | +| build_tar | - | Label | optional | //pkg/private/tar:build_tar | +| compressor | - | Label | optional | None | +| compressor_args | - | String | optional | "" | +| deps | - | List of labels | optional | [] | +| empty_dirs | - | List of strings | optional | [] | +| empty_files | - | List of strings | optional | [] | +| extension | - | String | optional | "tar" | +| files | - | Dictionary: Label -> String | optional | {} | +| include_runfiles | - | Boolean | optional | False | +| mode | - | String | optional | "0555" | +| modes | - | Dictionary: String -> String | optional | {} | +| mtime | - | Integer | optional | -1 | +| out | - | Label | required | | +| owner | - | String | optional | "0.0" | +| ownername | - | String | optional | "." | +| ownernames | - | Dictionary: String -> String | optional | {} | +| owners | - | Dictionary: String -> String | optional | {} | +| package_base | - | String | optional | "./" | +| package_dir | - | String | optional | "" | +| package_dir_file | - | Label | optional | None | +| package_file_name | See Common Attributes | String | optional | "" | +| package_variables | See Common Attributes | Label | optional | None | +| portable_mtime | - | Boolean | optional | True | +| private_stamp_detect | - | Boolean | optional | False | +| remap_paths | - | Dictionary: String -> String | optional | {} | +| srcs | - | List of labels | optional | [] | +| stamp | Enable file time stamping. Possible values:
  • stamp = 1: Use the time of the build as the modification time of each file in the archive.
  • stamp = 0: Use an "epoch" time for the modification time of each file. This gives good build result caching.
  • stamp = -1: Control the chosen modification time using the --[no]stamp flag. | Integer | optional | 0 | +| strip_prefix | - | String | optional | "" | +| symlinks | - | Dictionary: String -> String | optional | {} | + @@ -360,8 +318,9 @@ Creates a .zip file. See pkg_zip_impl. | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| name |

    -

    | none | -| kwargs |

    -

    | none | +| name | - | none | +| kwargs | - | none | + @@ -397,6 +356,7 @@ pkg_zip_impl(name, timestamp | Time stamp to place on all files in the archive, expressed as seconds since the Unix Epoch, as per RFC 3339. The default is January 01, 1980, 00:00 UTC.

    Due to limitations in the format of zip files, values before Jan 1, 1980 will be rounded up and the precision in the zip file is limited to a granularity of 2 seconds. | Integer | optional | 315532800 | + Package creation helper mapping rules. @@ -648,8 +608,8 @@ Create a symlink. | link_name | the path in the package that should point to the target. | none | | target | target path that the link should point to. | none | | attributes | file attributes. | None | -| src |

    -

    | None | -| kwargs |

    -

    | none | +| src | - | None | +| kwargs | - | none | @@ -679,7 +639,7 @@ strip_prefix.from_pkg(path) | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| path |

    -

    | "" | +| path | - | "" | @@ -697,7 +657,8 @@ strip_prefix.from_root(path) | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| path |

    -

    | "" | +| path | - | "" | + @@ -747,3 +708,4 @@ Legacy version | version_file | - | Label | optional | None | + diff --git a/pkg/private/deb/deb.bzl b/pkg/private/deb/deb.bzl index fa852239..bbf3e009 100644 --- a/pkg/private/deb/deb.bzl +++ b/pkg/private/deb/deb.bzl @@ -353,7 +353,7 @@ See https://www.debian.org/doc/debian-policy/ch-files.html#s-config-files.""", ) def pkg_deb(name, archive_name = None, **kwargs): - """Creates a deb file. See pkg_deb_impl.""" + """@wraps(pkg_deb_impl).""" if archive_name: # buildifier: disable=print print("'archive_name' is deprecated. Use 'package_file_name' or 'out' to name the output.") diff --git a/pkg/private/tar/tar.bzl b/pkg/private/tar/tar.bzl index 8a360a0e..9b3a88b3 100644 --- a/pkg/private/tar/tar.bzl +++ b/pkg/private/tar/tar.bzl @@ -299,8 +299,10 @@ pkg_tar_impl = rule( ) def pkg_tar(name, **kwargs): - """Creates a .tar file. See pkg_tar_impl.""" + """Creates a .tar file. See pkg_tar_impl. + @wraps(pkg_tar_impl) + """ # Compatibility with older versions of pkg_tar that define files as # a flat list of labels. if "srcs" not in kwargs: