You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-10-23 21:28:56 +03:00
The build tool in src/build becomes build/build.py with its library in build/lib, and the C part of the documentation tool in doc/src becomes doc/doc.py with its library in doc/lib. They migrate together because doc/src was built on src/build, linking its config and help parsing along with its extensions to the core types. doc.pl runs doc.py rather than building and running a C binary, and meson runs build.py for the code it generates as it builds. The three libraries form the hierarchy the C include path did: build/lib is the base, doc/lib sits on it, and test/lib sits on both. They are implicit namespace packages so a package spans them, and a module lives in exactly one library and holds the union of what the tools need from it, since Python resolves a module name to a single file and cannot extend one the way the C included a core module and added to it. define.yaml declares which libraries each tool may import and the test runner puts only those on the path, so a test of the build library cannot reach the doc or test library any more than the build tool can. The declarations move with the code. config.yaml, error.yaml, and postgres.yaml are now at the root of build, and help.xml becomes doc/xml/reference.xml since it is documentation that the help happens to be generated from, so the generator is told where it is rather than knowing. dist.sh moves to build as well. The documentation tool's own option declarations are gone because they existed only to generate the option parser for the C binary and doc.py parses its command line directly. Three modules in src/build/common were never build tool code. exec, regExp, and string extend the core types for the test harness and the unit tests, which were their only users, so they move to test/src/harness. The json and xml extensions had no users outside the two tools and are removed with them, and the tests for both are trimmed to the core functions that remain. The help unit test built its fixture by calling the generator's C functions directly, which was the last thing outside the tools that depended on them. It now runs build.py help-data to write the packed help and loads that, so it still runs against the current declarations without needing the generated C, which may not have been written when the test runs. The manual page wrapping is a port of the wrapper the binary uses for its own help, so the manual page and pgbackrest help break lines the same way, including where a word longer than a line is left unbroken. libyaml is no longer needed to build pgBackRest since the only thing that read yaml was the C generator. It is dropped from the development container and from every CI platform, and meson no longer looks for it. Code generation needs nothing compiled first either, so a test run no longer builds a generator before it can select the tests. The common source list is merged into the pgbackrest source list since it existed only so the generator could be built from the same files, and the entries that were out of alphabetical order are put in order while the list is being rewritten anyway. Every file the generator writes is byte identical to what the C wrote, for the project declarations and for the documentation's own. The documentation is checked the same way: the HTML rendered on this branch is byte identical to the HTML rendered on integration, every file of it, which exercises the whole pipeline on the real content rather than only the four files the tool writes. Every module in both libraries is declared in define.yaml and has full line and branch coverage. The coverage list is keyed by file rather than by module name, since the same name in two languages is two files and one of them would have silently lost its requirement while both existed. TestError becomes ToolError, since it is the error type for three tools now rather than for the harness alone.
121 lines
5.1 KiB
Python
121 lines
5.1 KiB
Python
"""Build Command.
|
|
|
|
Parses the command line and runs the requested generator. Each generator reads a declaration from the repository and writes the C it
|
|
describes into the build path, which is the repository itself for the files that are committed and the build directory for the files
|
|
meson generates as it builds.
|
|
|
|
The documentation generates its own option parse tables and help from its own declarations, so it runs these same generators with the
|
|
repository set to the documentation directory."""
|
|
|
|
####################################################################################################################################
|
|
import argparse
|
|
import os
|
|
|
|
from config.parse import bld_cfg_parse
|
|
from config.render import bld_cfg_render
|
|
from error.parse import bld_err_parse
|
|
from error.render import bld_err_render
|
|
from help.parse import bld_hlp_parse
|
|
from help.render import bld_hlp_render, bld_hlp_render_data
|
|
|
|
# The help declaration, which lives with the documentation because that is what most of it is for
|
|
_PATH_HELP = "doc/xml/reference.xml"
|
|
from postgres.parse import bld_pg_parse
|
|
from postgres.render import bld_pg_render, bld_pg_version_render
|
|
|
|
|
|
####################################################################################################################################
|
|
def _path_help(config):
|
|
"""Path of the help declaration."""
|
|
|
|
return os.path.join(config.repo_path, _PATH_HELP)
|
|
|
|
|
|
####################################################################################################################################
|
|
def _build_config(config):
|
|
"""Generate the command and option configuration."""
|
|
|
|
bld_cfg_render(config.build_path, bld_cfg_parse(config.repo_path), True)
|
|
|
|
|
|
####################################################################################################################################
|
|
def _build_error(config):
|
|
"""Generate the error types."""
|
|
|
|
bld_err_render(config.build_path, bld_err_parse(config.repo_path))
|
|
|
|
|
|
####################################################################################################################################
|
|
def _build_help(config):
|
|
"""Generate the help the binary carries for itself."""
|
|
|
|
bld_cfg = bld_cfg_parse(config.repo_path)
|
|
|
|
bld_hlp_render(config.build_path, bld_cfg, bld_hlp_parse(_path_help(config), bld_cfg, False))
|
|
|
|
|
|
####################################################################################################################################
|
|
def _build_help_data(config):
|
|
"""Generate the help as raw data, which is what the help unit test loads."""
|
|
|
|
bld_cfg = bld_cfg_parse(config.repo_path)
|
|
|
|
bld_hlp_render_data(config.build_path, bld_cfg, bld_hlp_parse(_path_help(config), bld_cfg, False))
|
|
|
|
|
|
####################################################################################################################################
|
|
def _build_postgres(config):
|
|
"""Generate the PostgreSQL interfaces."""
|
|
|
|
bld_pg_render(config.build_path, bld_pg_parse(config.repo_path))
|
|
|
|
|
|
####################################################################################################################################
|
|
def _build_postgres_version(config):
|
|
"""Generate the PostgreSQL version constants."""
|
|
|
|
bld_pg_version_render(config.build_path, bld_pg_parse(config.repo_path))
|
|
|
|
|
|
####################################################################################################################################
|
|
# Generators, in the order they are listed in the help
|
|
_COMMAND_LIST = {
|
|
"config": _build_config,
|
|
"error": _build_error,
|
|
"help": _build_help,
|
|
"help-data": _build_help_data,
|
|
"postgres": _build_postgres,
|
|
"postgres-version": _build_postgres_version,
|
|
}
|
|
|
|
|
|
####################################################################################################################################
|
|
def cfg_load(arg_list, path_repo):
|
|
"""Parse the command line."""
|
|
|
|
parser = argparse.ArgumentParser(prog="build.py", description="Generate code for pgBackRest.")
|
|
parser.add_argument("command", choices=_COMMAND_LIST, metavar="COMMAND", help="what to generate: %s" % ", ".join(_COMMAND_LIST))
|
|
parser.add_argument("--repo-path", default=path_repo, metavar="PATH", help="path the declarations are read from")
|
|
parser.add_argument("--build-path", metavar="PATH", help="path the generated code is written to, defaults to the repository")
|
|
|
|
result = parser.parse_args(arg_list)
|
|
|
|
# A relative path is made absolute so it does not depend on where the tool was run from, which meson does not promise
|
|
result.repo_path = os.path.abspath(result.repo_path)
|
|
|
|
# The generated code goes into the repository unless the caller sends it somewhere else, which meson does for the files it
|
|
# generates as it builds rather than the files that are committed
|
|
if result.build_path is None:
|
|
result.build_path = result.repo_path
|
|
else:
|
|
result.build_path = os.path.abspath(result.build_path)
|
|
|
|
return result
|
|
|
|
|
|
####################################################################################################################################
|
|
def cmd_build(config):
|
|
"""Run the requested generator."""
|
|
|
|
_COMMAND_LIST[config.command](config)
|