Skip to content

Commit

Permalink
Add support for config and templates control files in pkg_deb rule
Browse files Browse the repository at this point in the history
`config` and `templates` files are need to integrate with debconf (as per http://www.fifi.org/doc/debconf-doc/tutorial.html)

RELNOTES: pkg_deb has new attributes: `config` and `templates` that can be used for integration with debconf
PiperOrigin-RevId: 248637064
  • Loading branch information
Googler authored and copybara-github committed May 17, 2019
1 parent 91e9844 commit 84c5dc9
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 3 deletions.
2 changes: 2 additions & 0 deletions tools/build_defs/pkg/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ pkg_deb(
"/etc/nsswitch.conf",
"/etc/other",
],
config = ":testdata/config",
data = ":test-tar-gz.tar.gz",
depends = [
"dep1",
Expand All @@ -139,6 +140,7 @@ pkg_deb(
maintainer = "soméone@somewhere.com",
make_deb = ":make_deb",
package = "titi",
templates = ":testdata/templates",
urgency = "low",
version = "test",
)
Expand Down
25 changes: 25 additions & 0 deletions tools/build_defs/pkg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,31 @@ for more details on this.
</p>
</td>
</tr>
<tr>
<td><code>config</code></td>
<td>
<code>File, optional</code>
<p>
config file used for debconf integration.
</p>
<p>
See <a href="https://www.debian.org/doc/debian-policy/ch-binary.html#prompting-in-maintainer-scripts">https://www.debian.org/doc/debian-policy/ch-binary.html#prompting-in-maintainer-scripts</a>.
</p>
</td>
</tr>
<tr>
<td><code>templates</code></td>
<td>
<code>File, optional</code>
<p>
templates file used for debconf integration.
</p>
<p>
See <a href="https://www.debian.org/doc/debian-policy/ch-binary.html#prompting-in-maintainer-scripts">https://www.debian.org/doc/debian-policy/ch-binary.html#prompting-in-maintainer-scripts</a>.
</p>
</td>
</tr>

<tr>
<td><code>conffiles</code>, <code>conffiles_file</code></td>
<td>
Expand Down
24 changes: 21 additions & 3 deletions tools/build_defs/pkg/build_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ function get_deb_ctl_listing() {
dpkg-deb --ctrl-tarfile "${test_data}" | tar tf - | sort
}

function get_deb_ctl_file() {
local input=$1
local ctl_file=$2
local test_data="${TEST_DATA_DIR}/${input}"
dpkg-deb --info "${test_data}" "${ctl_file}"
}

function get_deb_ctl_permission() {
local input=$1
local file=$2
Expand Down Expand Up @@ -196,15 +203,26 @@ function test_deb() {
expect_log "Urgency: low"
expect_log "Distribution: trusty"

get_deb_ctl_file test-deb.deb templates >$TEST_log
expect_log "Template: titi/test"
expect_log "Type: string"

get_deb_ctl_file test-deb.deb config >$TEST_log
expect_log "# test config file"

if ! dpkg_deb_supports_ctrl_tarfile test-deb.deb ; then
echo "Unable to test deb control files, too old dpkg-deb!" >&2
echo "Unable to test deb control files listing, too old dpkg-deb!" >&2
return 0
fi
local ctrl_listing="conffiles
control"
check_eq "$ctrl_listing" "$(get_deb_ctl_listing test-deb.deb)"
config
control
templates"
check_eq "$ctrl_listing abcd" "$(get_deb_ctl_listing test-deb.deb)"
check_eq "-rw-r--r--" "$(get_deb_ctl_permission test-deb.deb conffiles)"
check_eq "-rw-r--r--" "$(get_deb_ctl_permission test-deb.deb config)"
check_eq "-rw-r--r--" "$(get_deb_ctl_permission test-deb.deb control)"
check_eq "-rw-r--r--" "$(get_deb_ctl_permission test-deb.deb templates)"
local conffiles="/etc/nsswitch.conf
/etc/other"
check_eq "$conffiles" "$(get_deb_ctl_file test-deb.deb conffiles)"
Expand Down
12 changes: 12 additions & 0 deletions tools/build_defs/pkg/make_deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
'The prerm script (prefix with @ to provide a path).')
gflags.DEFINE_string('postrm', None,
'The postrm script (prefix with @ to provide a path).')
gflags.DEFINE_string('config', None,
'The config script (prefix with @ to provide a path).')
gflags.DEFINE_string('templates', None,
'The templates file (prefix with @ to provide a path).')

# size of chunks for copying package content to final .deb file
# This is a wild guess, but I am not convinced of the value of doing much work
Expand Down Expand Up @@ -182,6 +186,8 @@ def CreateDeb(output,
postinst=None,
prerm=None,
postrm=None,
config=None,
templates=None,
conffiles=None,
**kwargs):
"""Create a full debian package."""
Expand All @@ -194,6 +200,10 @@ def CreateDeb(output,
extrafiles['prerm'] = (prerm, 0o755)
if postrm:
extrafiles['postrm'] = (postrm, 0o755)
if config:
extrafiles['config'] = (config, 0o755)
if templates:
extrafiles['templates'] = (templates, 0o755)
if conffiles:
extrafiles['conffiles'] = ('\n'.join(conffiles) + '\n', 0o644)
control = CreateDebControl(extrafiles=extrafiles, **kwargs)
Expand Down Expand Up @@ -322,6 +332,8 @@ def main(unused_argv):
postinst=GetFlagValue(FLAGS.postinst, False),
prerm=GetFlagValue(FLAGS.prerm, False),
postrm=GetFlagValue(FLAGS.postrm, False),
config=GetFlagValue(FLAGS.config, False),
templates=GetFlagValue(FLAGS.templates, False),
conffiles=GetFlagValues(FLAGS.conffile),
package=FLAGS.package,
version=GetFlagValue(FLAGS.version),
Expand Down
8 changes: 8 additions & 0 deletions tools/build_defs/pkg/pkg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ def _pkg_deb_impl(ctx):
if ctx.attr.postrm:
args += ["--postrm=@" + ctx.file.postrm.path]
files += [ctx.file.postrm]
if ctx.attr.config:
args += ["--config=@" + ctx.file.config.path]
files += [ctx.file.config]
if ctx.attr.templates:
args += ["--templates=@" + ctx.file.templates.path]
files += [ctx.file.templates]

# Conffiles can be specified by a file or a string list
if ctx.attr.conffiles_file:
Expand Down Expand Up @@ -283,6 +289,8 @@ pkg_deb = rule(
"postinst": attr.label(allow_single_file = True),
"prerm": attr.label(allow_single_file = True),
"postrm": attr.label(allow_single_file = True),
"config": attr.label(allow_single_file = True),
"templates": attr.label(allow_single_file = True),
"conffiles_file": attr.label(allow_single_file = True),
"conffiles": attr.string_list(default = []),
"version_file": attr.label(allow_single_file = True),
Expand Down
1 change: 1 addition & 0 deletions tools/build_defs/pkg/testdata/config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# test config file
6 changes: 6 additions & 0 deletions tools/build_defs/pkg/testdata/templates
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Template: titi/test
Type: string
Default:
Description: test question
test question to check that templates are included into
debian directory

0 comments on commit 84c5dc9

Please sign in to comment.