From 84c5dc9ad7cc9c00572c7e175b09b3979c5052a8 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 16 May 2019 17:50:50 -0700 Subject: [PATCH] Add support for `config` and `templates` control files in pkg_deb rule `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 --- tools/build_defs/pkg/BUILD | 2 ++ tools/build_defs/pkg/README.md | 25 +++++++++++++++++++++++++ tools/build_defs/pkg/build_test.sh | 24 +++++++++++++++++++++--- tools/build_defs/pkg/make_deb.py | 12 ++++++++++++ tools/build_defs/pkg/pkg.bzl | 8 ++++++++ tools/build_defs/pkg/testdata/config | 1 + tools/build_defs/pkg/testdata/templates | 6 ++++++ 7 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 tools/build_defs/pkg/testdata/config create mode 100644 tools/build_defs/pkg/testdata/templates diff --git a/tools/build_defs/pkg/BUILD b/tools/build_defs/pkg/BUILD index f1e3ba8cb6e449..86d6bd02d11157 100644 --- a/tools/build_defs/pkg/BUILD +++ b/tools/build_defs/pkg/BUILD @@ -129,6 +129,7 @@ pkg_deb( "/etc/nsswitch.conf", "/etc/other", ], + config = ":testdata/config", data = ":test-tar-gz.tar.gz", depends = [ "dep1", @@ -139,6 +140,7 @@ pkg_deb( maintainer = "soméone@somewhere.com", make_deb = ":make_deb", package = "titi", + templates = ":testdata/templates", urgency = "low", version = "test", ) diff --git a/tools/build_defs/pkg/README.md b/tools/build_defs/pkg/README.md index d487e3e717bb9e..80a2a039b4eeda 100644 --- a/tools/build_defs/pkg/README.md +++ b/tools/build_defs/pkg/README.md @@ -395,6 +395,31 @@ for more details on this.

+ + config + + File, optional +

+ config file used for debconf integration. +

+

+ See https://www.debian.org/doc/debian-policy/ch-binary.html#prompting-in-maintainer-scripts. +

+ + + + templates + + File, optional +

+ templates file used for debconf integration. +

+

+ See https://www.debian.org/doc/debian-policy/ch-binary.html#prompting-in-maintainer-scripts. +

+ + + conffiles, conffiles_file diff --git a/tools/build_defs/pkg/build_test.sh b/tools/build_defs/pkg/build_test.sh index ad1b8f4e860ccb..7f8ecde914285a 100755 --- a/tools/build_defs/pkg/build_test.sh +++ b/tools/build_defs/pkg/build_test.sh @@ -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 @@ -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)" diff --git a/tools/build_defs/pkg/make_deb.py b/tools/build_defs/pkg/make_deb.py index f58e920654f5ee..45fe47c01e8455 100644 --- a/tools/build_defs/pkg/make_deb.py +++ b/tools/build_defs/pkg/make_deb.py @@ -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 @@ -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.""" @@ -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) @@ -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), diff --git a/tools/build_defs/pkg/pkg.bzl b/tools/build_defs/pkg/pkg.bzl index 2a6396dc1d0046..57e24a47944e1f 100644 --- a/tools/build_defs/pkg/pkg.bzl +++ b/tools/build_defs/pkg/pkg.bzl @@ -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: @@ -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), diff --git a/tools/build_defs/pkg/testdata/config b/tools/build_defs/pkg/testdata/config new file mode 100644 index 00000000000000..d39edc79c40a8c --- /dev/null +++ b/tools/build_defs/pkg/testdata/config @@ -0,0 +1 @@ +# test config file diff --git a/tools/build_defs/pkg/testdata/templates b/tools/build_defs/pkg/testdata/templates new file mode 100644 index 00000000000000..10dacff2ed017e --- /dev/null +++ b/tools/build_defs/pkg/testdata/templates @@ -0,0 +1,6 @@ +Template: titi/test +Type: string +Default: +Description: test question + test question to check that templates are included into + debian directory \ No newline at end of file