Skip to content

Commit 0631617

Browse files
committed
Update pkg_deb to use ctx.action.args() for building the command line.
This has better UTF-8 fidelity.
1 parent 89465ed commit 0631617

File tree

2 files changed

+61
-45
lines changed

2 files changed

+61
-45
lines changed

pkg/private/deb/deb.bzl

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -34,120 +34,135 @@ def _pkg_deb_impl(ctx):
3434
package_file_name = package_file_name,
3535
)
3636

37-
changes_file = ctx.actions.declare_file(output_name.rsplit(".", 1)[0] + ".changes")
37+
out_file_name_base = output_name.rsplit(".", 1)[0]
38+
changes_file = ctx.actions.declare_file(out_file_name_base + ".changes")
3839
outputs.append(changes_file)
3940

4041
files = [ctx.file.data]
41-
args = [
42-
"--output=" + output_file.path,
43-
"--changes=" + changes_file.path,
44-
"--data=" + ctx.file.data.path,
45-
"--package=" + ctx.attr.package,
46-
"--maintainer=" + ctx.attr.maintainer,
47-
]
42+
args = ctx.actions.args()
43+
args.add("--output", output_file.path)
44+
args.add("--changes", changes_file.path)
45+
args.add("--data", ctx.file.data.path)
46+
args.add("--package", ctx.attr.package)
47+
args.add("--maintainer", ctx.attr.maintainer)
4848

49-
# Version and description can be specified by a file or inlined
5049
if ctx.attr.architecture_file:
5150
if ctx.attr.architecture != "all":
5251
fail("Both architecture and architecture_file attributes were specified")
53-
args += ["--architecture=@" + ctx.file.architecture_file.path]
52+
args.add("--architecture", "@" + ctx.file.architecture_file.path)
5453
files += [ctx.file.architecture_file]
5554
else:
56-
args += ["--architecture=" + ctx.attr.architecture]
55+
args.add("--architecture", ctx.attr.architecture)
5756

5857
if ctx.attr.preinst:
59-
args += ["--preinst=@" + ctx.file.preinst.path]
58+
args.add("--preinst", "@" + ctx.file.preinst.path)
6059
files += [ctx.file.preinst]
6160
if ctx.attr.postinst:
62-
args += ["--postinst=@" + ctx.file.postinst.path]
61+
args.add("--postinst", "@" + ctx.file.postinst.path)
6362
files += [ctx.file.postinst]
6463
if ctx.attr.prerm:
65-
args += ["--prerm=@" + ctx.file.prerm.path]
64+
args.add("--prerm", "@" + ctx.file.prerm.path)
6665
files += [ctx.file.prerm]
6766
if ctx.attr.postrm:
68-
args += ["--postrm=@" + ctx.file.postrm.path]
67+
args.add("--postrm", "@" + ctx.file.postrm.path)
6968
files += [ctx.file.postrm]
7069
if ctx.attr.config:
71-
args += ["--config=@" + ctx.file.config.path]
70+
args.add("--config", "@" + ctx.file.config.path)
7271
files += [ctx.file.config]
7372
if ctx.attr.templates:
74-
args += ["--templates=@" + ctx.file.templates.path]
73+
args.add("--templates", "@" + ctx.file.templates.path)
7574
files += [ctx.file.templates]
7675
if ctx.attr.triggers:
77-
args += ["--triggers=@" + ctx.file.triggers.path]
76+
args.add("--triggers", "@" + ctx.file.triggers.path)
7877
files += [ctx.file.triggers]
7978

8079
# Conffiles can be specified by a file or a string list
8180
if ctx.attr.conffiles_file:
8281
if ctx.attr.conffiles:
8382
fail("Both conffiles and conffiles_file attributes were specified")
84-
args += ["--conffile=@" + ctx.file.conffiles_file.path]
83+
args.add("--conffile", "@" + ctx.file.conffiles_file.path)
8584
files += [ctx.file.conffiles_file]
8685
elif ctx.attr.conffiles:
87-
args += ["--conffile=%s" % cf for cf in ctx.attr.conffiles]
86+
for cf in ctx.attr.conffiles:
87+
args.add("--conffile", cf)
8888

8989
# Version and description can be specified by a file or inlined
9090
if ctx.attr.version_file:
9191
if ctx.attr.version:
9292
fail("Both version and version_file attributes were specified")
93-
args += ["--version=@" + ctx.file.version_file.path]
93+
args.add("--version", "@" + ctx.file.version_file.path)
9494
files += [ctx.file.version_file]
9595
elif ctx.attr.version:
96-
args += ["--version=" + ctx.attr.version]
96+
args.add("--version", ctx.attr.version)
9797
else:
9898
fail("Neither version_file nor version attribute was specified")
9999

100100
if ctx.attr.description_file:
101101
if ctx.attr.description:
102102
fail("Both description and description_file attributes were specified")
103-
args += ["--description=@" + ctx.file.description_file.path]
103+
args.add("--description", "@" + ctx.file.description_file.path)
104104
files += [ctx.file.description_file]
105105
elif ctx.attr.description:
106-
args += ["--description=" + ctx.attr.description]
106+
desc_file = ctx.actions.declare_file(out_file_name_base + ".description")
107+
ctx.actions.write(desc_file, ctx.attr.description)
108+
files.append(desc_file)
109+
args.add("--description", "@" + desc_file.path)
107110
else:
108111
fail("Neither description_file nor description attribute was specified")
109112

110113
# Built using can also be specified by a file or inlined (but is not mandatory)
111114
if ctx.attr.built_using_file:
112115
if ctx.attr.built_using:
113116
fail("Both build_using and built_using_file attributes were specified")
114-
args += ["--built_using=@" + ctx.file.built_using_file.path]
117+
args.add("--built_using", "@" + ctx.file.built_using_file.path)
115118
files += [ctx.file.built_using_file]
116119
elif ctx.attr.built_using:
117-
args += ["--built_using=" + ctx.attr.built_using]
120+
args.add("--built_using", ctx.attr.built_using)
118121

119122
if ctx.attr.depends_file:
120123
if ctx.attr.depends:
121124
fail("Both depends and depends_file attributes were specified")
122-
args += ["--depends=@" + ctx.file.depends_file.path]
125+
args.add("--depends", "@" + ctx.file.depends_file.path)
123126
files += [ctx.file.depends_file]
124127
elif ctx.attr.depends:
125-
args += ["--depends=" + d for d in ctx.attr.depends]
128+
for d in ctx.attr.depends:
129+
args.add("--depends", d)
126130

127131
if ctx.attr.priority:
128-
args += ["--priority=" + ctx.attr.priority]
132+
args.add("--priority", ctx.attr.priority)
129133
if ctx.attr.section:
130-
args += ["--section=" + ctx.attr.section]
134+
args.add("--section", ctx.attr.section)
131135
if ctx.attr.homepage:
132-
args += ["--homepage=" + ctx.attr.homepage]
136+
args.add("--homepage", ctx.attr.homepage)
133137
if ctx.attr.license:
134-
args += ["--license=" + ctx.attr.license]
138+
args.add("--license", ctx.attr.license)
135139

136-
args += ["--distribution=" + ctx.attr.distribution]
137-
args += ["--urgency=" + ctx.attr.urgency]
138-
args += ["--suggests=" + d for d in ctx.attr.suggests]
139-
args += ["--enhances=" + d for d in ctx.attr.enhances]
140-
args += ["--conflicts=" + d for d in ctx.attr.conflicts]
141-
args += ["--breaks=" + d for d in ctx.attr.breaks]
142-
args += ["--pre_depends=" + d for d in ctx.attr.predepends]
143-
args += ["--recommends=" + d for d in ctx.attr.recommends]
144-
args += ["--replaces=" + d for d in ctx.attr.replaces]
145-
args += ["--provides=" + d for d in ctx.attr.provides]
140+
args.add("--distribution", ctx.attr.distribution)
141+
args.add("--urgency", ctx.attr.urgency)
142+
for d in ctx.attr.suggests:
143+
args.add("--suggests", d)
144+
for d in ctx.attr.enhances:
145+
args.add("--enhances", d)
146+
for d in ctx.attr.conflicts:
147+
args.add("--conflicts", d)
148+
for d in ctx.attr.breaks:
149+
args.add("--breaks", d)
150+
for d in ctx.attr.predepends:
151+
args.add("--pre_depends", d)
152+
for d in ctx.attr.recommends:
153+
args.add("--recommends", d)
154+
for d in ctx.attr.replaces:
155+
args.add("--replaces", d)
156+
for d in ctx.attr.provides:
157+
args.add("--provides", d)
146158

159+
args.set_param_file_format("flag_per_line")
160+
args.use_param_file("@%s", use_always = True)
161+
print(args)
147162
ctx.actions.run(
148163
mnemonic = "MakeDeb",
149164
executable = ctx.executable._make_deb,
150-
arguments = args,
165+
arguments = [args],
151166
inputs = files,
152167
outputs = [output_file, changes_file],
153168
env = {

pkg/private/deb/make_deb.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def CreateChanges(output,
288288

289289
changesdata = u''.join([
290290
MakeDebianControlField('Format', '1.8'),
291-
MakeDebianControlField('Date', time.ctime(timestamp)),
291+
MakeDebianControlField('Date', time.asctime(time.gmtime(timestamp))),
292292
MakeDebianControlField('Source', package),
293293
MakeDebianControlField('Binary', package),
294294
MakeDebianControlField('Architecture', architecture),
@@ -333,7 +333,8 @@ def GetFlagValues(flagvalues):
333333

334334
def main():
335335
parser = argparse.ArgumentParser(
336-
description='Helper for building deb packages')
336+
description='Helper for building deb packages',
337+
fromfile_prefix_chars='@')
337338

338339
parser.add_argument('--output', required=True,
339340
help='The output file, mandatory')

0 commit comments

Comments
 (0)