dh_assistant
tool for supporting debhelper tools and provide introspection
- Provided by: debhelper (Version: 13.31ubuntu1)
- Report a bug
tool for supporting debhelper tools and provide introspection
dh_assistant command [additional options]
dh_assistant is a debhelper program that provides introspection into the debhelper stack to assist third-party tools (e.g. linters) or third-party debhelper implementations not using the debhelper script API (e.g., because they are not written in Perl).
The dh_assistant supports the following commands:
Synopsis: dh_assistant active-compat-level
Outputs information about which compat level the package is using.
For packages without valid debhelper compatibility information (whether missing, ambiguous, not supported or simply invalid), this command operates on a "best effort" basis and may abort when error instead of providing data.
The returned JSON dictionary contains the following key-value pairs:
X-DH-Compat: 15
Build-Depends: debhelper-compat (= 15)
Synopsis: dh_assistant supported-compat-levels
Outputs information about which compat levels, this build of debhelper knows about.
This command accepts no options or arguments.
Synopsis: dh_assistant which-build-system [build step] [build system options]
Output information about which build system would be used for a particular build step. The build step must be one of configure, build, test, install or clean and must be the first argument after which-build-system when provided. If omitted, it defaults to configure as it is the most reliable step to use auto-detection on in a clean source directory. Note that build steps do not always agree when using auto-detection - particularly if the configure step has not been run.
Additionally, the clean step can also provide "surprising" results for builds that rely on a separate build directory. In such cases, debhelper will return the first build system that uses a separate build directory rather than the one build system that configure would detect. This is generally a cosmetic issue as both build systems are all basically a glorified rm -fr builddir and more precise detection is functionally irrelevant as far as debhelper is concerned.
The option accepts all debhelper build system arguments - i.e., options you can pass to all of the dh_auto_* commands plus (for the install step) the --destdir option. These options affect the output and auto-detection in various ways. Passing -S or --buildsystem overrides the auto-detection (as it does for dh_auto_*) but it still provides introspection into the chosen build system.
Things that are useful to know about the output:
The value is valid as a parameter for the --buildsystem option.
The special value "none" is used to denote that no build system would be used (that is, a JSON string). This value is not present in --list parameter for the dh_auto_* commands, but since debhelper/12.9 the value is accepted for the --buildsystem option.
Note that auto-detection is subject to limitations in regards to third-party build systems. While debhelper does support auto-detecting some third-party build systems, they must be installed for the detection to work. If they are not installed, the detection logic silently skips that build system (often resulting in build-system being "none" in the output).
Note that if not specified, this value is currently null by default.
Synopsis: dh_assistant parse-dh-cli-args dh_assistant-options -- command-line-options
Parses command-line-options like a dh_* command would and output a JSON document with the result.
This subcommand is aimed at supporting third-party commands in implementing the debhelper command-line parsing logic. The rules look deceptively simple but turns out to be very complex, which means that tools not written using the Debian::Debhelper::Dh_Lib module will be at a massive disadvantage. As a consequence, consumers get a mixed result since some times behave differently to the same options than others.
This command reacts to option parsing like any built debhelper command and therefore accounts for DH_OPTIONS and other such environment variables. However, since dh_assistant has to parse the options without knowing all arguments, it might get command specific options wrong if the value looks like option. As an example, if dh_assistant sees --foo -a, it assumes -a is the debhelper -a and leaves --foo as unparsed. If --foo always takes a parameter in the caller, then this is the wrong behavior. This ambiguity can be avoided if --foo=-a is passed instead. This problem can also occur due to "bundling" such as -fa (which debhelper reads as the two independent options -f -a. This is for the caller to avoid.
If the command returns successfully, the output will be JSON describing the options (see description below for the details). Otherwise, there will be a human readable error on stderr for what went wrong. Note that stderr can also be used to emit warnings on a successful run.
The command-line-options should be the command line options the caller wish to have parsed on their behalf.
Options specific for dh_assistant
The command accepts the following arguments in the place of dh_assistant-options:
By default, it will use its own name but mention the calling command. When --masquerade is passed, only the calling commands name will be listed in the log file. The difference being whether the user sees:
dh_assistant (for dh_command): ...
vs.
dh_command: ...
Though, this option is only relevant if the stderr of the dh_assistant process is not redirected away.
This is necessary for --remaining-packages to work correctly in hook targets.
If --no-inhibit-log is passed, the caller must update the log themselves on successful completion of the command.
Generally, the correct answer here is to output a warning and exit successfully despite having done nothing. By default (--noop-warnings), dh_assistant emits these warnings on behalf of the caller. The --no-noop-warnings can be used if the warning is undesirable for some reason.
JSON output format
The output of this command is a JSON document of
{
"active-packages": ["debhelper"],
"debhelper-settings": {
"exclude": [],
"no-act": false,
"no-scripts": false,
"quiet": false,
"requested-staging-dir": null,
"verbose": false
},
"options": {
"--all": false,
"--name": null,
"-d": null,
"-v": null,
"args": [],
"try-args": []
},
"packages": {
"debhelper": {
"binary-arch": "all",
"declared-arch": "all",
"package-type": "deb"
}
}
}
The keys have the following definition:
This list can be empty if the user requested packages that cannot be built. This can occur with -a when all packages are Architecture: all as an example.
The value is always included and never null.
The object is always included and never null.
The following key-value pairs are defined in this object:
The verbose option is triggered by options like -v, --verbose or the DH_VERBOSE environment variable. The quiet option is triggered things like DEB_BUILD_OPTIONS containing terse.
The values are always set, boolean and never null.
The value is always set, boolean and never null.
They typically control whether the command should generate maintscripts. When true, the command should skip generation of such script snippets.
Some command also use this to control whether triggers are generated for historical reasons.
The value is always set, boolean and never null.
It is up to the command to define how exclusions affect them if at all or even how they match. Common examples include substring matching or regexes on filenames.
The value is always set, a list and never null, but the list can be empty.
It only makes sense when there is at most one active package. Note it can appear with no active packages if the command is called unconditionally with -p PKG and the provided package should not be built for some reason.
Note: The directory (when provided) can be either relative or absolute based on how the value for the option was defined. Additionally, the directory is not required to exist as tools are expected to create directories as necessary.
The object is always present and never null.
The following key-value pairs are defined in this object:
This is a niche option and many commands ignore it.
Many commands ignore this option.
The -d is a boolean option (never null). The value is true if -d was passed and false otherwise. The -V is an parameter that optionally takes a string. It will be null, if -V is not passed otherwise it will be a string. The empty string means no value was passed to -V.
The value is always present, a list and never null. It can be and often is empty.
The caller should try to parse each of them individually and accept the ones it understands. Unknown arguments should be ignored silently.
When parameters that accept values are passed via -O they must always be passed with their value as a single argument (such as -O--foo=bar). This is a deeply root assumption in debhelper and caller is expected to follow that assumption rather than conditionally parsing an extra argument.
The value is always present, a list and never null. It can be and often is empty.
The object is always present and never null.
Each key is the name of a package defined in debian/control. The values are an object. There is always a key for every package defined in debian/control even if they are not listed in active-packages.
The following key-value pairs are defined in the per package object object:
If the value is equal to all, then the package is an "arch:all" package.
If the value is equal to all, then the package is an "arch:all" package.
One can be forgiving for assuming this value is always either all or the value of DEB_HOST_ARCH. While that holds in 99.9% of the cases, debhelper supports some very special cases where that is not true. Consumers are recommended to use this value rather than doing their own computation here.
Most commonly the value will be deb. However, udeb is another known value.
Synopsis: dh_assistant detect-hook-targets
Detects possible override targets and hook targets that dh(1) might use (provided that the relevant command is in the sequence).
**UNSAFE**: This command relies on the output of make. Even it its dry-run mode, make may execute commands from debian/rules. Avoid using on packages from untrusted sources, where you have not reviewed the packaging for backdoors.
The detection is based on scanning the rules file for any target that might look like a hook target and can therefore list targets that are in fact not hook targets (or are but will never be triggered for other reasons).
The detection uses a similar logic for scanning the rules file and is therefore subject to makefile conditionals (i.e., the truth value of makefile conditionals can change whether a hook target is visible in the output of this command). In theory, you would have to setup up the environment to look like it would during a build for getting the most accurate output. Though, a lot of packages will not have conditional hook targets, so the "out of the box" behaviour will work well in most cases.
The output looks something like this:
{
"commands-not-in-path": [
"dh_foo"
],
"hook-targets": [
{
"command": "dh_strip_nondeterminism",
"is-empty": true,
"package-section-param": null,
"filename": "debian/rules",
"target-name": "override_dh_strip_nondeterminism"
},
{
"command": "dh_foo",
"is-empty": false,
"package-section-param": "-a",
"filename": "debian/rules",
"target-name": "override_dh_foo-arch"
}
]
}
In more details:
If you are using this command to verify an hook target is present, please double check that the command is spelled correctly.
Note this accuracy of this attribute is limited about what data dh_assistant can read out from the following command:
LC_ALL=C make -Rrnpsf debian/rules debhelper-fail-me 2>/dev/null
This command accepts no options or arguments.
Synopsis: dh_assistant detect-unknown-hook-targets [--output-format=json] [command-options]
Detects unknown and possibly misspelled override targets and hook targets in debian/rules that will most likely not be used by dh(1).
**UNSAFE**: This command relies on the output of make. Even it its dry-run mode, make may execute commands from debian/rules. Avoid using on packages from untrusted sources, where you have not reviewed the packaging for backdoors.
This command differs from detect-hook-targets subtly in the scope. The detect-hook-targets will list all targets that looks like hook targets whether they are applicable or not. This command show all hook targets, for which a command cannot be found in any sequence. Accordingly, this command is better for linting purposes whereas detect-hook-targets is better if you want to know which hook targets are present. All the limitations listed in detect-hook-targets about scanning the rules file apply equally to this command.
This command will attempt will attempt to load any sequence add-on listed via build-dependencies and therefore these must be installed. Additional modules can be passed via --with like with dh(1) as needed.
This command will also need one of the following perl modules to be available: Text::Levenshtein, Text::LevenshteinXS, Text::Levenshtein::XS. The first one can be installed via apt install libtext-levenshtein-perl.
The text output is intended for human consumption and should be self-explanatory. Since it is not stable, it will not be documented. The JSON output looks something like this:
{
"unknown-hook-targets": [
{
"target-name": "execute_before_dh_instlal",
"filename": "debian/rules",
"candidates": [
"execute_before_dh_install"
]
}
],
"hook-targets-for-disabled-commands": [
{
"filename": "debian/rules",
"target-name": "override_dh_builddeb",
"removed-by": "zz-debputy"
}
],
}
In more details:
Note this accuracy of this attribute is limited about what data dh_assistant can read out from the following command:
LC_ALL=C make -Rrnpsf debian/rules debhelper-fail-me 2>/dev/null
Note this accuracy of this attribute is limited about what data dh_assistant can read out from the following command:
LC_ALL=C make -Rrnpsf debian/rules debhelper-fail-me 2>/dev/null
Note this field is not present in all cases. As an example, as obsolete commands (such as dh_gconf) are not part of any sequence by the time they are marked as obsolete.
If you (as a consumer) need to know whether a command is obsolete or the particular reason why a command was disabled, please file a feature request to get that data. The absence of removed-by is not guaranteed to imply the command is obsolete.
Parsers should assume new issue types may appear in the future.
This command accepts the following options:
The text format is intended for human consumption and may change between versions without any regard for machine consumption. If you want to use this command for machine consumption, please use the JSON format.
Synopsis: dh_assistant list-commands [--output-format=json] [command-options]
Load all dh sequence add-ons and extract a full list of all commands that will be invoked across all sequences. The command makes no attempt to filter out commands that will not be run due to override targets or due to certain sequences not being run (by dh or at all).
As the command will attempt to load all plugins, they must be installed.
The text output is intended for human consumption and should be self-explanatory. Since it is not stable, it will not be documented. The JSON output looks something like this:
{
"commands": [
{
"command": "dh_auto_build"
},
{
"command": "dh_auto_clean"
},
[... more commands listed here... ]
],
"removed-commands": [
{
"command": "dh_gconf"
},
]
"issues": [
{
"issue": "load-addon",
"addon": "foo"
}
]
}
While most commands are resolved via PATH, a sequence add-on could register a command via a full path (by passing the path search). If so, the command provided in this output will also use the full path.
While most commands are resolved via PATH, a sequence add-on could register a command via a full path (by passing the path search). If so, the command provided in this output will also use the full path.
Note this field is not present in all cases. As an example, as obsolete commands (such as dh_gconf) are not part of any sequence by the time they are marked as obsolete.
If you (as a consumer) need to know whether a command is obsolete or the particular reason why a command was disabled, please file a feature request to get that data. The absence of removed-by is not guaranteed to imply the command is obsolete.
Parsers should assume new issue types may appear in the future.
This command accepts the following options:
The text format is intended for human consumption and may change between versions without any regard for machine consumption. If you want to use this command for machine consumption, please use the JSON format.
Synopsis: dh_assistant list-guessed-dh-config-files [command-options]
Load all dh sequence add-ons declaratively depended on, determine the full list of commands could be relevant for this source package and for each command used, then attempt to guess which "config files" these commands are interested in.
The command will include config files for commands that are not active with current add-ons, since the commands might be run manually from hook targets.
Note this command only guesses "per command config files". Standard global config files such as debian/control, debian/rules, and debian/compat are not included in this output.
As the command name implies, the resulting output is not a full list (and will never be). The dh_assistant tool have to derive this from optional metadata that commands can choose to provide and dh_assistant has no means to validate that this metadata is up to date.
As the command will attempt to load all plugins referenced by the package, they must be installed.
The text output is intended for human consumption and should be self-explanatory. Since it is not stable, it will not be documented. The JSON output looks something like this:
{
"config-files": [
{
"commands": [
{
"command": "dh_autoreconf_clean"
"is-active": true
}
],
"file-type": "pkgfile",
"pkgfile": "autoreconf.before"
},
{
"commands": [
{
"command": "dh_installgsettings"
"is-active": true
}
],
"file-type": "pkgfile",
"pkgfile": "gsettings-override"
},
# [ ... more entries here ...]
],
"issues": [
{
"issue": "load-addon",
"addon": "foo"
}
]
}
When it is pkgfile, then the config file is a debhelper pkgfile (named after the pkgfile sub in Debian::Debhelper::Dh_Lib that locates the file). The value denoted by the pkgfile key will be the stem of the pkgfile (the install in debian/package. install).
When file-type is not pkgfile, then this key will be absent.
Typically names for these files are:
debian/PKGFILE
debian/PACKAGE.PKGFILE
However, there are more variants caused by --name plus architecture specific suffixes.
When file-type is not path, then this key will be absent.
It used for document certain specific implementation details such as bug compatibility and may change as the situation changes.
Note that commands that are not "active" can often still be invoked manually from debian/rules via hook targets. Therefore, this reflects whether dh would call the command directly or provide its standard hook targets for the command.
Note this field is not present in all cases regardless of the value of is-active. As an example, as obsolete commands (such as dh_gconf) are not part of any sequence by the time they are marked as obsolete.
If you (as a consumer) need to know whether a command is obsolete or the particular reason why a command was disabled, please file a feature request to get that data. The absence of removed-by plus is-active being false is not guaranteed to imply the command is obsolete.
Parsers should assume new issue types may appear in the future.
This command accepts the following options:
Synopsis: dh_assistant log-installed-files -ppkg [--on-behalf-of-cmd=dh_foo] path ...
Mark one or more paths as installed for a given package. This is useful for telling dh_missing(1) that the paths have been installed manually.
The --on-behalf-of-cmd option can be used by third-party tools to have dh_assistant list them as the installer of the provided paths. The convention is to use the basename of the tool itself as its name (e.g. dh_install).
Please keep in mind that:
Note this command only marks paths as installed. It does not actually install them - the caller should ensure that the paths are in fact handled (or installed).
Synopsis: dh_assistant restore-file-on-clean FILE ...
This command will take a backup of listed files and tell dh_clean(1) to restore them when it runs.
Note that generally you do not need to restore modified files on clean. Often you can get away with just removing them if they are regenerated anyway (which is the most common case for files being modified during builds). Use this command when something taints a file and the build does not cope with the file being removed.
The file is stored in debian/.debhelper. If you remove this directory manually without calling dh_clean(1) then your dh_assistant provided backup is gone permanently and the restore will never occur. At this point, only a version control system or another backup can restore the files.
The command has the following limitations:
While most dh_* commands does not use the underlying function, any of them could do so. Avoid running another dh_* command while dh_assistant processes this command (especially running multiple concurrent instances of dh_assistant restore-file-on-clean is asking for corruption!).
Additionally, if the directory containing the file is removed, the restore will fail (as debhelper does not track the directory, it cannot restore it reliably). If this happens, you can do a mkdir to restore the directory and run dh_clean(1) again to get the files back. After that, consider what went wrong and whether you are using the correct tool(s).
These checks are here to ensure you do not accidentally trash important data that would help you undo mistakes.
Synopsis: dh_assistant compat-upgrade-checklist [--target-compat N]
This command generates a compat upgrade checklist for the current package.
The upgrade checklist is intended as an aid for contributors that upgrade a package to a newer compat level. Where possible, dh_assistant will attempt to detect whether some of the items are likely to be irrelevant and mark them as such. The logic will in many cases be a heuristic that can have false-positives and false-negatives.
The output is a markdown based checklist template aimed at being human-readable (output stability is not a goal). Typically, the user will want to direct standard output and then edit the checklist as they process to a file a la:
dh_assistant compat-upgrade-checklist > debian/compat-upgrade-checklist.md
editor debian/compat-upgrade-checklist.md
# Iterate through the checklist, tweak the packaging, cross off items from the checklist (rinse and repeat)
# Finally, remove the checklist.
rm -f debian/compat-upgrade-checklist.md # when the migration is complete
The command will provide a checklist up to latest stable compat level or the compat level provided via the --target-compat option.
This command accepts the following options:
The option cannot be used to generate a checklist for downgrading to a previous compat level. Trying to do so will result in an error message.
Note: If you run this command from a git checkout of debhelper, the behavior is slight different, since it will not correctly track which compat levels are stable (it is a build-time inserted property). As such, you will see experimental compat levels in the checklists by default, and they will not be marked as such. If you use the git checkout, it falls on you to be extra careful with these limitations of the generated checklist.
Synopsis: dh_assistant supports COMMAND
This command is a scripting aid to programmatically determine whether dh_assistant knows about a given subcommand. Pass the name of a subcommand and this command will exit successfully if the subcommand was known and unsuccessfully otherwise.
Most commands have one or more of the following "tags" associated with them. Their meaning is defined here.
Note: This tag only applies if the command will out of the box be unsafe. As an example, commands that parse the output of make is inherently unsafe, because it is trivial make to have make run code even in --dry-run mode. As a counter example, commands that only loads dh add-ons will be considered safe, because PERL5LIB is assumed to be curated to only include trusted plugins.
Note that commands may have options that redefine what is considered an "important" issue.
Most commands must be run inside a source package root directory (a directory containing debian/control) because debhelper will need the package metadata to lookup the information. Any command with this tag are exempt from this requirement and is expected to work regardless of where they are run.
Most commands uses JSON format as output. Consumers need to be aware that:
The output will be prettified when stdout is detected as a terminal. If you need to pipe the output to a pager/file (etc.) and still want it prettified, please use an external JSON formatter. An example of this:
dh_assistant supported-compat-levels | json_pp | less
This program is a part of debhelper.