Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproducibility: pkg_deb_impl with postinst and postrm attribute results in unpredictable control.tar.gz file #114

Closed
andreas-0815-qwertz opened this issue Nov 6, 2019 · 2 comments

Comments

@andreas-0815-qwertz
Copy link
Contributor

Description of the problem / feature request:

Using

http_archive(
    name = "rules_pkg",
    url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz",
    sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a",
)

in my WORKSPACE together with a homegrown wrapper macro for pkg_deb_impl

def atos_pkg_deb(name, basename, **kwargs):
    out_deb = basename + ".deb"
    out_changes = basename + ".changes"
    pkg_deb_impl(
        name = name,
        out = name + ".deb",
        deb = out_deb,
        changes = out_changes,
        **kwargs
    )

results in a non-predictable file order of the postinst and postrm scripts in the generated control.tar.gz, when used in a target definition like

atos_pkg_deb(
    name = "ATOS-trc-target-deb-cpu_a",
    basename = "atos-A-TraceCfg-" + atos_version + "-powerpc",
    architecture = "powerpc",
    data = ":ATOS-trc-target-tarball",
    depends = ["cohpa (>= 2)"],
    description = """
 ATO Service
 Copyright: Bombardier Transportation
 Automatic Train Operation Service software
    """,
    maintainer = "http://www.bombardier.com",
    package = "atos-A-TrcConfig",
    version = atos_version,
    postinst = ":postinstall-trace-cohpa",
    postrm = ":postremove-trace-cohpa",
)

When I am building the target twice in a row with an intermediate bazel clean, I get the output attached with diffoscope 78.

atos-A-TraceCfg-0.3.0.0-powerpc.html.gz

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Please see description above.

What operating system are you running Bazel on?

Debian GNU/Linux 9.11

What's the output of bazel info release?

release 1.1.0

(using bazelisk 1.1.0)

If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.

n.a.

What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?

n.a.

Have you found anything relevant by searching the web?

No, sorry.

Any other information, logs, or outputs that you want to share?

see attachment.

@andreas-0815-qwertz
Copy link
Contributor Author

The following patch seems to fix this for me.

From 62ba0de4702b9764cf3541793efd81f7297f9cf2 Mon Sep 17 00:00:00 2001
From: "andreas-0815-qwertz" <andreas.0815.qwertz@gmail.com>
Date: Thu, 7 Nov 2019 10:56:12 +0100
Subject: [PATCH] Fix issue 114

Make iteration over "extrafiles" variable predictable by using
OrderedDict instead of plain Python dict.
---
 pkg/make_deb.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/pkg/make_deb.py b/pkg/make_deb.py
index 7232f43..2fb52fe 100644
--- a/pkg/make_deb.py
+++ b/pkg/make_deb.py
@@ -23,6 +23,7 @@ import sys
 import tarfile
 import textwrap
 import time
+from collections import OrderedDict


 # list of debian fields : (name, mandatory, wrap[, default])
@@ -166,7 +167,7 @@ def CreateDeb(output,
               conffiles=None,
               **kwargs):
   """Create a full debian package."""
-  extrafiles = {}
+  extrafiles = OrderedDict()
   if preinst:
     extrafiles['preinst'] = (preinst, 0o755)
   if postinst:
@@ -296,7 +297,7 @@ def main():
                       help='The output file, mandatory')
   parser.add_argument('--changes', required=True,
                       help='The changes output file, mandatory.')
-  parser.add_argument('--data', required=True,
+  parser.add_argument('--data', required=True,
                       help='Path to the data tarball, mandatory')
   parser.add_argument(
       '--preinst',
--
2.11.0

I am new to Github and don't know, how to send this in correctly. But it is trivial anyway.

andreas-0815-qwertz added a commit to andreas-0815-qwertz/rules_pkg that referenced this issue Nov 29, 2019
Replacing plain Python dict by an OrderedDict for Python versions
before 3.7, so that iteration order of "extrafiles" is determined by
insertion order.  Since 3.7 iteration order of plain dict itself is
stable.

bazelbuild#114
aiuto pushed a commit that referenced this issue May 19, 2020
Replacing plain Python dict by an OrderedDict for Python versions
before 3.7, so that iteration order of "extrafiles" is determined by
insertion order.  Since 3.7 iteration order of plain dict itself is
stable.

#114
@aiuto
Copy link
Collaborator

aiuto commented May 19, 2020

Fixed in #120

@aiuto aiuto closed this as completed May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants