aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--tools/build_defs/pkg/BUILD15
-rw-r--r--tools/build_defs/pkg/README.md15
-rwxr-xr-xtools/build_defs/pkg/build_test.sh39
-rw-r--r--tools/build_defs/pkg/make_deb.py88
-rw-r--r--tools/build_defs/pkg/pkg.bzl11
-rwxr-xr-xtools/build_defs/pkg/testenv.sh7
6 files changed, 138 insertions, 37 deletions
diff --git a/tools/build_defs/pkg/BUILD b/tools/build_defs/pkg/BUILD
index 65429abceb..6144bc1641 100644
--- a/tools/build_defs/pkg/BUILD
+++ b/tools/build_defs/pkg/BUILD
@@ -46,8 +46,8 @@ py_binary(
srcs = ["build_tar.py"],
visibility = ["//visibility:public"],
deps = [
- "@bazel_tools//third_party/py/gflags",
":archive",
+ "@bazel_tools//third_party/py/gflags",
],
)
@@ -56,8 +56,8 @@ py_binary(
srcs = ["make_deb.py"],
visibility = ["//visibility:public"],
deps = [
- "@bazel_tools//third_party/py/gflags",
":archive",
+ "@bazel_tools//third_party/py/gflags",
],
)
@@ -75,6 +75,7 @@ genrule(
[pkg_tar(
name = "test-tar-%s" % ext[1:],
+ build_tar = ":build_tar",
extension = "tar%s" % ext,
files = [
":etc/nsswitch.conf",
@@ -94,6 +95,7 @@ genrule(
[pkg_tar(
name = "test-tar-inclusion-%s" % ext,
+ build_tar = ":build_tar",
deps = [":test-tar-%s" % ext],
) for ext in [
"",
@@ -104,6 +106,7 @@ genrule(
pkg_tar(
name = "test-tar-strip_prefix-empty",
+ build_tar = ":build_tar",
files = [
":etc/nsswitch.conf",
],
@@ -112,6 +115,7 @@ pkg_tar(
pkg_tar(
name = "test-tar-strip_prefix-none",
+ build_tar = ":build_tar",
files = [
":etc/nsswitch.conf",
],
@@ -119,6 +123,7 @@ pkg_tar(
pkg_tar(
name = "test-tar-strip_prefix-etc",
+ build_tar = ":build_tar",
files = [
":etc/nsswitch.conf",
],
@@ -127,6 +132,7 @@ pkg_tar(
pkg_tar(
name = "test-tar-strip_prefix-dot",
+ build_tar = ":build_tar",
files = [
":etc/nsswitch.conf",
],
@@ -135,6 +141,10 @@ pkg_tar(
pkg_deb(
name = "test-deb",
+ conffiles = [
+ "/etc/nsswitch.conf",
+ "/etc/other",
+ ],
data = ":test-tar-gz.tar.gz",
depends = [
"dep1",
@@ -142,6 +152,7 @@ pkg_deb(
],
description = "toto",
maintainer = "someone@somewhere.com",
+ make_deb = ":make_deb",
package = "titi",
version = "test",
)
diff --git a/tools/build_defs/pkg/README.md b/tools/build_defs/pkg/README.md
index 4e6b8a600b..47f6ffa1ac 100644
--- a/tools/build_defs/pkg/README.md
+++ b/tools/build_defs/pkg/README.md
@@ -296,6 +296,21 @@ for more details on this.
</p>
<p>
See <a href="http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html">http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html</a>.
+ </p>
+ </td>
+ </tr>
+ <tr>
+ <td><code>conffiles</code>, <code>conffiles_file</code></td>
+ <td>
+ <code>String list or File, optional</code>
+ <p>
+ 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.
+ </p>
+ <p>
+ See <a href="https://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html#s-conffile">https://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html#s-conffile</a>.
+ </p>
</td>
</tr>
<tr>
diff --git a/tools/build_defs/pkg/build_test.sh b/tools/build_defs/pkg/build_test.sh
index 986e1fe6ae..cbb44c3e04 100755
--- a/tools/build_defs/pkg/build_test.sh
+++ b/tools/build_defs/pkg/build_test.sh
@@ -51,6 +51,32 @@ function get_deb_permission() {
dpkg-deb -c "${test_data}" | fgrep "00 $file" | cut -d " " -f 1
}
+function get_deb_ctl_file() {
+ local input=$1
+ local file=$2
+ local test_data="${TEST_DATA_DIR}/${input}"
+ dpkg-deb -I "${test_data}" "${file}"
+}
+
+function get_deb_ctl_listing() {
+ local input=$1
+ local test_data="${TEST_DATA_DIR}/${input}"
+ dpkg-deb --ctrl-tarfile "${test_data}" | tar tf - | sort
+}
+
+function get_deb_ctl_permission() {
+ local input=$1
+ local file=$2
+ local test_data="${TEST_DATA_DIR}/${input}"
+ dpkg-deb --ctrl-tarfile "${test_data}" | tar tvf - | egrep " $file\$" | cut -d " " -f 1
+}
+
+function dpkg_deb_supports_ctrl_tarfile() {
+ local input=$1
+ local test_data="${TEST_DATA_DIR}/${input}"
+ dpkg-deb --ctrl-tarfile "${test_data}" > /dev/null 2> /dev/null
+}
+
function test_tar() {
local listing="./
@@ -100,6 +126,19 @@ function test_deb() {
expect_log "Description: toto"
expect_log "Package: titi"
expect_log "Depends: dep1, dep2"
+
+ if ! dpkg_deb_supports_ctrl_tarfile test-deb.deb ; then
+ echo "Unable to test deb control files, too old dpkg-deb!" >&2
+ return 0
+ fi
+ local ctrl_listing="conffiles
+control"
+ check_eq "$ctrl_listing" "$(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 control)"
+ local conffiles="/etc/nsswitch.conf
+/etc/other"
+ check_eq "$conffiles" "$(get_deb_ctl_file test-deb.deb conffiles)"
}
run_suite "build_test"
diff --git a/tools/build_defs/pkg/make_deb.py b/tools/build_defs/pkg/make_deb.py
index c2329282a1..d606d5b900 100644
--- a/tools/build_defs/pkg/make_deb.py
+++ b/tools/build_defs/pkg/make_deb.py
@@ -57,6 +57,13 @@ gflags.DEFINE_string('postrm', None,
'The postrm script (prefix with @ to provide a path).')
+# see
+# https://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html#s-conffile
+gflags.DEFINE_multistring(
+ 'conffile', None,
+ 'List of conffiles (prefix item with @ to provide a path)')
+
+
def MakeGflags():
for field in DEBIAN_FIELDS:
fieldname = field[0].replace('-', '_').lower()
@@ -119,28 +126,36 @@ def CreateDebControl(extrafiles=None, **kwargs):
tarinfo.size = len(controlfile)
f.addfile(tarinfo, fileobj=StringIO(controlfile))
if extrafiles:
- for name in extrafiles:
+ for name, (data, mode) in extrafiles.iteritems():
tarinfo = tarfile.TarInfo(name)
- tarinfo.size = len(extrafiles[name])
- tarinfo.mode = 0o755
- f.addfile(tarinfo, fileobj=StringIO(extrafiles[name]))
+ tarinfo.size = len(data)
+ tarinfo.mode = mode
+ f.addfile(tarinfo, fileobj=StringIO(data))
control = tar.getvalue()
tar.close()
return control
-def CreateDeb(output, data,
- preinst=None, postinst=None, prerm=None, postrm=None, **kwargs):
+def CreateDeb(output,
+ data,
+ preinst=None,
+ postinst=None,
+ prerm=None,
+ postrm=None,
+ conffiles=None,
+ **kwargs):
"""Create a full debian package."""
extrafiles = {}
if preinst:
- extrafiles['preinst'] = preinst
+ extrafiles['preinst'] = (preinst, 0o755)
if postinst:
- extrafiles['postinst'] = postinst
+ extrafiles['postinst'] = (postinst, 0o755)
if prerm:
- extrafiles['prerm'] = prerm
+ extrafiles['prerm'] = (prerm, 0o755)
if postrm:
- extrafiles['postrm'] = postrm
+ extrafiles['postrm'] = (postrm, 0o755)
+ if conffiles:
+ extrafiles['conffiles'] = ('\n'.join(conffiles), 0o644)
control = CreateDebControl(extrafiles=extrafiles, **kwargs)
# Write the final AR archive (the deb package)
@@ -247,29 +262,38 @@ def GetFlagValue(flagvalue, strip=True):
return flagvalue
+def GetFlagValues(flagvalues):
+ if flagvalues:
+ return [GetFlagValue(f, False) for f in flagvalues]
+ else:
+ return None
+
+
def main(unused_argv):
- CreateDeb(FLAGS.output,
- FLAGS.data,
- preinst=GetFlagValue(FLAGS.preinst, False),
- postinst=GetFlagValue(FLAGS.postinst, False),
- prerm=GetFlagValue(FLAGS.prerm, False),
- postrm=GetFlagValue(FLAGS.postrm, False),
- package=FLAGS.package,
- version=GetFlagValue(FLAGS.version),
- description=GetFlagValue(FLAGS.description),
- maintainer=FLAGS.maintainer,
- section=FLAGS.section,
- architecture=FLAGS.architecture,
- depends=FLAGS.depends,
- suggests=FLAGS.suggests,
- enhances=FLAGS.enhances,
- preDepends=FLAGS.pre_depends,
- recommends=FLAGS.recommends,
- homepage=FLAGS.homepage,
- builtUsing=GetFlagValue(FLAGS.built_using),
- priority=FLAGS.priority,
- conflicts=FLAGS.conflicts,
- installedSize=GetFlagValue(FLAGS.installed_size))
+ CreateDeb(
+ FLAGS.output,
+ FLAGS.data,
+ preinst=GetFlagValue(FLAGS.preinst, False),
+ postinst=GetFlagValue(FLAGS.postinst, False),
+ prerm=GetFlagValue(FLAGS.prerm, False),
+ postrm=GetFlagValue(FLAGS.postrm, False),
+ conffiles=GetFlagValues(FLAGS.conffile),
+ package=FLAGS.package,
+ version=GetFlagValue(FLAGS.version),
+ description=GetFlagValue(FLAGS.description),
+ maintainer=FLAGS.maintainer,
+ section=FLAGS.section,
+ architecture=FLAGS.architecture,
+ depends=FLAGS.depends,
+ suggests=FLAGS.suggests,
+ enhances=FLAGS.enhances,
+ preDepends=FLAGS.pre_depends,
+ recommends=FLAGS.recommends,
+ homepage=FLAGS.homepage,
+ builtUsing=GetFlagValue(FLAGS.built_using),
+ priority=FLAGS.priority,
+ conflicts=FLAGS.conflicts,
+ installedSize=GetFlagValue(FLAGS.installed_size))
CreateChanges(
FLAGS.changes,
FLAGS.output,
diff --git a/tools/build_defs/pkg/pkg.bzl b/tools/build_defs/pkg/pkg.bzl
index 65be303f75..e2f7c79f33 100644
--- a/tools/build_defs/pkg/pkg.bzl
+++ b/tools/build_defs/pkg/pkg.bzl
@@ -77,6 +77,15 @@ def _pkg_deb_impl(ctx):
args += ["--postrm=@" + ctx.file.postrm.path]
files += [ctx.file.postrm]
+ # Conffiles can be specified by a file or a string list
+ if ctx.attr.conffiles_file:
+ if ctx.attr.conffiles:
+ fail("Both conffiles and conffiles_file attributes were specified")
+ args += ["--conffile=@" + ctx.file.conffiles_file.path]
+ files += [ctx.file.conffiles_file]
+ elif ctx.attr.conffiles:
+ args += ["--conffile=%s" % cf for cf in ctx.attr.conffiles]
+
# Version and description can be specified by a file or inlined
if ctx.attr.version_file:
if ctx.attr.version:
@@ -170,6 +179,8 @@ pkg_deb = rule(
"postinst": attr.label(allow_files=True, single_file=True),
"prerm": attr.label(allow_files=True, single_file=True),
"postrm": attr.label(allow_files=True, single_file=True),
+ "conffiles_file": attr.label(allow_files=True, single_file=True),
+ "conffiles": attr.string_list(default=[]),
"version_file": attr.label(allow_files=True, single_file=True),
"version": attr.string(),
"description_file": attr.label(allow_files=True, single_file=True),
diff --git a/tools/build_defs/pkg/testenv.sh b/tools/build_defs/pkg/testenv.sh
index 0a61815bb6..b0a634081d 100755
--- a/tools/build_defs/pkg/testenv.sh
+++ b/tools/build_defs/pkg/testenv.sh
@@ -14,12 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Integration test for docker, test environment.
+# Integration test for pkg, test environment.
[ -z "$TEST_SRCDIR" ] && { echo "TEST_SRCDIR not set!" >&2; exit 1; }
+[ -z "$TEST_WORKSPACE" ] && { echo "TEST_WORKSPACE not set!" >&2; exit 1; }
# Load the unit-testing framework
-source "${TEST_SRCDIR}/src/test/shell/unittest.bash" || \
+source "${TEST_SRCDIR}/${TEST_WORKSPACE}/src/test/shell/unittest.bash" || \
{ echo "Failed to source unittest.bash" >&2; exit 1; }
-readonly TEST_DATA_DIR="${TEST_SRCDIR}/tools/build_defs/pkg"
+readonly TEST_DATA_DIR="${TEST_SRCDIR}/${TEST_WORKSPACE}/tools/build_defs/pkg"