Merge lp:~jelmer/bzr-builder/force-native into lp:bzr-builder

Proposed by Jelmer Vernooij
Status: Merged
Approved by: James Westby
Approved revision: 115
Merged at revision: 111
Proposed branch: lp:~jelmer/bzr-builder/force-native
Merge into: lp:bzr-builder
Diff against target: 208 lines (+146/-2)
2 files modified
cmds.py (+59/-2)
tests/test_blackbox.py (+87/-0)
To merge this branch: bzr merge lp:~jelmer/bzr-builder/force-native
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+42799@code.launchpad.net

Description of the change

Add a --force-native option to "bzr dailydeb".

This option will apply all quilt patches and update the debian/source/format directory if the package is currently in the "3.0 (quilt)" format.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Hi,

Thanks for doing this, it is fairly unobtrusive and solves a common problem,
so I'm happy to have it.

70 + f.write("3.0 (native)")

Should that have a newline?

75 +def force_native_format(working_tree_path):

Should this die if it doesn't recognise the format marker?

93 + Option("force-native",
94 + help="Force the source package format to be native."),

Should this be an option? I can't really think of a reason why people
wouldn't want this. Is it just being conservative? Maybe have the option,
but invert the default?

Thanks,

James

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

On Tue, 2010-12-07 at 16:56 +0000, James Westby wrote:
> Thanks for doing this, it is fairly unobtrusive and solves a common problem,
> so I'm happy to have it.
>
> 70 + f.write("3.0 (native)")
> Should that have a newline?
Hmm, that's a good point. Both with and without seems to be allowed, but
with is more common. Fixed.

> 75 +def force_native_format(working_tree_path):
> Should this die if it doesn't recognise the format marker?
Yeah, better safe than sorry (and we don't support "2.0" at this point).

> 93 + Option("force-native",
> 94 + help="Force the source package format to be native."),

> Should this be an option? I can't really think of a reason why people
> wouldn't want this. Is it just being conservative? Maybe have the option,
> but invert the default?
Yeah, I was mainly being conservative. But you're right, without this
option things wouldn't really work anyway. I've killed it.

Cheers,

Jelmer

lp:~jelmer/bzr-builder/force-native updated
114. By Jelmer Vernooij

include newline in debian/source/format.

115. By Jelmer Vernooij

Kill --force-native option, error out on unknown source formats.

Revision history for this message
James Westby (james-w) wrote :

Looks good.

Thanks,

James

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'cmds.py'
--- cmds.py 2010-08-25 19:27:04 +0000
+++ cmds.py 2010-12-07 17:56:23 +0000
@@ -251,7 +251,7 @@
251251
252252
253def _run_command(command, basedir, msg, error_msg,253def _run_command(command, basedir, msg, error_msg,
254 not_installed_msg=None):254 not_installed_msg=None, env=None):
255 """ Run a command in a subprocess.255 """ Run a command in a subprocess.
256256
257 :param command: list with command and parameters257 :param command: list with command and parameters
@@ -259,6 +259,7 @@
259 :param error_msg: message to display if something fails.259 :param error_msg: message to display if something fails.
260 :param not_installed_msg: the message to display if the command260 :param not_installed_msg: the message to display if the command
261 isn't available.261 isn't available.
262 :param env: Optional environment to use rather than os.environ.
262 """263 """
263 trace.note(msg)264 trace.note(msg)
264 # Hide output if -q is in use.265 # Hide output if -q is in use.
@@ -267,6 +268,8 @@
267 kwargs = {"stderr": subprocess.STDOUT, "stdout": subprocess.PIPE}268 kwargs = {"stderr": subprocess.STDOUT, "stdout": subprocess.PIPE}
268 else:269 else:
269 kwargs = {}270 kwargs = {}
271 if env is not None:
272 kwargs["env"] = env
270 try:273 try:
271 proc = subprocess.Popen(command, cwd=basedir,274 proc = subprocess.Popen(command, cwd=basedir,
272 stdin=subprocess.PIPE, **kwargs)275 stdin=subprocess.PIPE, **kwargs)
@@ -293,6 +296,59 @@
293 not_installed_msg="debuild is not installed, please install "296 not_installed_msg="debuild is not installed, please install "
294 "the devscripts package.")297 "the devscripts package.")
295298
299def get_source_format(path):
300 """Retrieve the source format name from a package.
301
302 :param path: Path to the package
303 :return: String with package format
304 """
305 source_format_path = os.path.join(path, "debian", "source", "format")
306 if not os.path.exists(source_format_path):
307 return "1.0"
308 f = open(source_format_path, 'r')
309 try:
310 return f.read().strip()
311 finally:
312 f.close()
313
314
315def convert_3_0_quilt_to_native(path):
316 """Convert a package in 3.0 (quilt) format to 3.0 (native).
317
318 This applies all patches in the package and updates the
319 debian/source/format file.
320
321 :param path: Path to the package on disk
322 """
323 path = os.path.abspath(path)
324 patches_dir = os.path.join(path, "debian", "patches")
325 series_file = os.path.join(patches_dir, "series")
326 if os.path.exists(series_file):
327 _run_command(["quilt", "push", "-a", "-v"], path,
328 "Applying quilt patches",
329 "Failed to apply quilt patches",
330 not_installed_msg="quilt is not installed, please install it.",
331 env={"QUILT_SERIES": series_file, "QUILT_PATCHES": patches_dir})
332 shutil.rmtree(os.path.join(path, "debian/patches"))
333 f = open(os.path.join(path, "debian", "source", "format"), 'w')
334 try:
335 f.write("3.0 (native)\n")
336 finally:
337 f.close()
338
339
340def force_native_format(working_tree_path):
341 """Make sure a package is a format that supports native packages.
342
343 :param working_tree_path: Path to the package
344 """
345 current_format = get_source_format(working_tree_path)
346 if current_format == "3.0 (quilt)":
347 convert_3_0_quilt_to_native(working_tree_path)
348 elif current_format not in ("1.0", "3.0 (native)"):
349 raise errors.BzrCommandError("Unknown source format %s" %
350 current_format)
351
296352
297def sign_source_package(basedir, key_id):353def sign_source_package(basedir, key_id):
298 command = ["/usr/bin/debsign", "-S", "-k%s" % key_id]354 command = ["/usr/bin/debsign", "-S", "-k%s" % key_id]
@@ -402,7 +458,7 @@
402 "specified string to the end of the version used "458 "specified string to the end of the version used "
403 "in debian/changelog."),459 "in debian/changelog."),
404 Option("safe", help="Error if the recipe would cause"460 Option("safe", help="Error if the recipe would cause"
405 " arbitrary code execution.")461 " arbitrary code execution."),
406 ]462 ]
407463
408 takes_args = ["recipe_file", "working_basedir?"]464 takes_args = ["recipe_file", "working_basedir?"]
@@ -451,6 +507,7 @@
451 add_changelog_entry(base_branch, working_directory,507 add_changelog_entry(base_branch, working_directory,
452 distribution=distribution, package=package,508 distribution=distribution, package=package,
453 append_version=append_version)509 append_version=append_version)
510 force_native_format(working_directory)
454 package_dir = calculate_package_dir(base_branch,511 package_dir = calculate_package_dir(base_branch,
455 package_name, working_basedir)512 package_name, working_basedir)
456 # working_directory -> package_dir: after this debian stuff works.513 # working_directory -> package_dir: after this debian stuff works.
457514
=== modified file 'tests/test_blackbox.py'
--- tests/test_blackbox.py 2010-08-25 19:27:04 +0000
+++ tests/test_blackbox.py 2010-12-07 17:56:23 +0000
@@ -14,6 +14,7 @@
14# with this program. If not, see <http://www.gnu.org/licenses/>.14# with this program. If not, see <http://www.gnu.org/licenses/>.
1515
16import os16import os
17from textwrap import dedent
1718
18from bzrlib import workingtree19from bzrlib import workingtree
19from bzrlib.tests import (20from bzrlib.tests import (
@@ -284,3 +285,89 @@
284 retcode=3)285 retcode=3)
285 self.assertContainsRe(err, "The 'run' instruction is forbidden.$")286 self.assertContainsRe(err, "The 'run' instruction is forbidden.$")
286287
288 def make_simple_quilt_package(self):
289 source = self.make_simple_package()
290 self.build_tree(["source/debian/source/"])
291 self.build_tree_contents([
292 ("source/debian/source/format", "3.0 (quilt)\n")])
293 source.add(["debian/source", "debian/source/format"])
294 source.commit("set source format")
295 return source
296
297 def test_cmd_dailydeb_force_native(self):
298 self.make_simple_quilt_package()
299 self.build_tree_contents([("test.recipe", "# bzr-builder format 0.3 "
300 "deb-version 1\nsource 2\n")])
301 out, err = self.run_bzr(
302 "dailydeb -q test.recipe working", retcode=0)
303 self.assertFileEqual("3.0 (native)\n",
304 "working/test-1/debian/source/format")
305
306 def test_cmd_dailydeb_force_native_apply_quilt(self):
307 source = self.make_simple_quilt_package()
308 self.build_tree(["source/debian/patches/"])
309 patch = dedent(
310 """diff -ur a/thefile b/thefile
311 --- a/thefile 2010-12-05 20:14:22.000000000 +0100
312 +++ b/thefile 2010-12-05 20:14:26.000000000 +0100
313 @@ -1 +1 @@
314 -old-contents
315 +new-contents
316 """)
317 self.build_tree_contents([
318 ("source/thefile", "old-contents\n"),
319 ("source/debian/patches/series", "01_foo.patch"),
320 ("source/debian/patches/01_foo.patch", patch)])
321 source.add(["thefile", "debian/patches", "debian/patches/series",
322 "debian/patches/01_foo.patch"])
323 source.commit("add patch")
324
325 self.build_tree_contents([("test.recipe", "# bzr-builder format 0.3 "
326 "deb-version 1\nsource\n")])
327 out, err = self.run_bzr(
328 "dailydeb -q test.recipe working", retcode=0)
329 self.assertFileEqual("3.0 (native)\n",
330 "working/test-1/debian/source/format")
331 self.assertFileEqual("new-contents\n",
332 "working/test-1/thefile")
333 self.failIfExists("working/test-1/debian/patches")
334
335 def test_cmd_dailydeb_force_native_apply_quilt_failure(self):
336 source = self.make_simple_quilt_package()
337 self.build_tree(["source/debian/patches/"])
338 patch = dedent(
339 """diff -ur a/thefile b/thefile
340 --- a/thefile 2010-12-05 20:14:22.000000000 +0100
341 +++ b/thefile 2010-12-05 20:14:26.000000000 +0100
342 @@ -1 +1 @@
343 -old-contents
344 +new-contents
345 """)
346 self.build_tree_contents([
347 ("source/thefile", "contents\n"),
348 ("source/debian/patches/series", "01_foo.patch"),
349 ("source/debian/patches/01_foo.patch", patch)])
350 source.add(["thefile", "debian/patches", "debian/patches/series",
351 "debian/patches/01_foo.patch"])
352 source.commit("add patch")
353
354 self.build_tree_contents([("test.recipe", "# bzr-builder format 0.3 "
355 "deb-version 1\nsource\n")])
356 out, err = self.run_bzr(
357 "dailydeb -q test.recipe working", retcode=3)
358 self.assertContainsRe(err, "bzr: ERROR: Failed to apply quilt patches")
359
360 def test_unknown_source_format(self):
361 source = self.make_simple_package()
362 self.build_tree(["source/debian/source/"])
363 self.build_tree_contents([
364 ("source/debian/source/format", "2.0\n")])
365 source.add(["debian/source", "debian/source/format"])
366 source.commit("set source format")
367
368 self.build_tree_contents([("test.recipe", "# bzr-builder format 0.3 "
369 "deb-version 1\nsource\n")])
370 out, err = self.run_bzr(
371 "dailydeb -q test.recipe working", retcode=3)
372 self.assertEquals(err, "bzr: ERROR: Unknown source format 2.0\n")
373

Subscribers

People subscribed via source and target branches