Skip to content

Commit 91c7d2f

Browse files
committed
Add extra_control_file attr to pkg_deb
1 parent a77183a commit 91c7d2f

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

pkg/private/deb/deb.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ def _pkg_deb_impl(ctx):
178178
for d in ctx.attr.provides:
179179
args.add("--provides", d)
180180

181+
if ctx.attr.extra_control_file:
182+
args.add("--extra_control_file", ctx.file.extra_control_file.path)
183+
files.append(ctx.file.extra_control_file)
184+
181185
args.set_param_file_format("flag_per_line")
182186
args.use_param_file("@%s", use_always = True)
183187
ctx.actions.run(
@@ -393,6 +397,10 @@ See https://www.debian.org/doc/debian-policy/ch-files.html#s-config-files.""",
393397
doc = """See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps.""",
394398
default = [],
395399
),
400+
"extra_control_file": attr.label(
401+
doc = """File with extra control fields appended verbatim to the control file.""",
402+
allow_single_file = True,
403+
),
396404

397405
# Common attributes
398406
"out": attr.output(

pkg/private/deb/make_deb.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def MakeDebianControlField(name: str, value: str, multiline:Multiline=Multiline.
157157
return result
158158

159159

160-
def CreateDebControl(extrafiles=None, **kwargs):
160+
def CreateDebControl(extrafiles=None, extra_control_content=None, **kwargs):
161161
"""Create the control.tar.gz file."""
162162
# create the control file
163163
controlfile = u''
@@ -168,6 +168,8 @@ def CreateDebControl(extrafiles=None, **kwargs):
168168
key = fieldname[0].lower() + fieldname[1:].replace('-', '')
169169
if mandatory or (key in kwargs and kwargs[key]):
170170
controlfile += MakeDebianControlField(fieldname, kwargs[key], multiline)
171+
if extra_control_content:
172+
controlfile += extra_control_content
171173
# Create the control.tar file
172174
tar = io.BytesIO()
173175
with gzip.GzipFile('control.tar.gz', mode='w', fileobj=tar, mtime=0) as gz:
@@ -201,6 +203,7 @@ def CreateDeb(output,
201203
md5sums=None,
202204
conffiles=None,
203205
changelog=None,
206+
extra_control_content=None,
204207
**kwargs):
205208
"""Create a full debian package."""
206209
extrafiles = OrderedDict()
@@ -224,7 +227,7 @@ def CreateDeb(output,
224227
extrafiles['conffiles'] = ('\n'.join(conffiles) + '\n', 0o644)
225228
if changelog:
226229
extrafiles['changelog'] = (changelog, 0o644)
227-
control = CreateDebControl(extrafiles=extrafiles, **kwargs)
230+
control = CreateDebControl(extrafiles=extrafiles, extra_control_content=extra_control_content, **kwargs)
228231

229232
# Write the final AR archive (the deb package)
230233
with open(output, 'wb') as f:
@@ -381,9 +384,17 @@ def main():
381384
parser.add_argument(
382385
'--changelog',
383386
help='The changelog file (prefix item with @ to provide a path).')
387+
parser.add_argument(
388+
'--extra_control_file',
389+
help='File with extra control fields to append verbatim to the control file.')
384390
AddControlFlags(parser)
385391
options = parser.parse_args()
386392

393+
extra_control_content = None
394+
if options.extra_control_file:
395+
with open(options.extra_control_file, 'r') as f:
396+
extra_control_content = f.read()
397+
387398
CreateDeb(
388399
options.output,
389400
options.data,
@@ -397,6 +408,7 @@ def main():
397408
md5sums=helpers.GetFlagValue(options.md5sums, False),
398409
conffiles=GetFlagValues(options.conffile),
399410
changelog=helpers.GetFlagValue(options.changelog, False),
411+
extra_control_content=extra_control_content,
400412
package=options.package,
401413
version=helpers.GetFlagValue(options.version),
402414
description=helpers.GetFlagValue(options.description),

0 commit comments

Comments
 (0)