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
1=== modified file 'cmds.py'
2--- cmds.py 2010-08-25 19:27:04 +0000
3+++ cmds.py 2010-12-07 17:56:23 +0000
4@@ -251,7 +251,7 @@
5
6
7 def _run_command(command, basedir, msg, error_msg,
8- not_installed_msg=None):
9+ not_installed_msg=None, env=None):
10 """ Run a command in a subprocess.
11
12 :param command: list with command and parameters
13@@ -259,6 +259,7 @@
14 :param error_msg: message to display if something fails.
15 :param not_installed_msg: the message to display if the command
16 isn't available.
17+ :param env: Optional environment to use rather than os.environ.
18 """
19 trace.note(msg)
20 # Hide output if -q is in use.
21@@ -267,6 +268,8 @@
22 kwargs = {"stderr": subprocess.STDOUT, "stdout": subprocess.PIPE}
23 else:
24 kwargs = {}
25+ if env is not None:
26+ kwargs["env"] = env
27 try:
28 proc = subprocess.Popen(command, cwd=basedir,
29 stdin=subprocess.PIPE, **kwargs)
30@@ -293,6 +296,59 @@
31 not_installed_msg="debuild is not installed, please install "
32 "the devscripts package.")
33
34+def get_source_format(path):
35+ """Retrieve the source format name from a package.
36+
37+ :param path: Path to the package
38+ :return: String with package format
39+ """
40+ source_format_path = os.path.join(path, "debian", "source", "format")
41+ if not os.path.exists(source_format_path):
42+ return "1.0"
43+ f = open(source_format_path, 'r')
44+ try:
45+ return f.read().strip()
46+ finally:
47+ f.close()
48+
49+
50+def convert_3_0_quilt_to_native(path):
51+ """Convert a package in 3.0 (quilt) format to 3.0 (native).
52+
53+ This applies all patches in the package and updates the
54+ debian/source/format file.
55+
56+ :param path: Path to the package on disk
57+ """
58+ path = os.path.abspath(path)
59+ patches_dir = os.path.join(path, "debian", "patches")
60+ series_file = os.path.join(patches_dir, "series")
61+ if os.path.exists(series_file):
62+ _run_command(["quilt", "push", "-a", "-v"], path,
63+ "Applying quilt patches",
64+ "Failed to apply quilt patches",
65+ not_installed_msg="quilt is not installed, please install it.",
66+ env={"QUILT_SERIES": series_file, "QUILT_PATCHES": patches_dir})
67+ shutil.rmtree(os.path.join(path, "debian/patches"))
68+ f = open(os.path.join(path, "debian", "source", "format"), 'w')
69+ try:
70+ f.write("3.0 (native)\n")
71+ finally:
72+ f.close()
73+
74+
75+def force_native_format(working_tree_path):
76+ """Make sure a package is a format that supports native packages.
77+
78+ :param working_tree_path: Path to the package
79+ """
80+ current_format = get_source_format(working_tree_path)
81+ if current_format == "3.0 (quilt)":
82+ convert_3_0_quilt_to_native(working_tree_path)
83+ elif current_format not in ("1.0", "3.0 (native)"):
84+ raise errors.BzrCommandError("Unknown source format %s" %
85+ current_format)
86+
87
88 def sign_source_package(basedir, key_id):
89 command = ["/usr/bin/debsign", "-S", "-k%s" % key_id]
90@@ -402,7 +458,7 @@
91 "specified string to the end of the version used "
92 "in debian/changelog."),
93 Option("safe", help="Error if the recipe would cause"
94- " arbitrary code execution.")
95+ " arbitrary code execution."),
96 ]
97
98 takes_args = ["recipe_file", "working_basedir?"]
99@@ -451,6 +507,7 @@
100 add_changelog_entry(base_branch, working_directory,
101 distribution=distribution, package=package,
102 append_version=append_version)
103+ force_native_format(working_directory)
104 package_dir = calculate_package_dir(base_branch,
105 package_name, working_basedir)
106 # working_directory -> package_dir: after this debian stuff works.
107
108=== modified file 'tests/test_blackbox.py'
109--- tests/test_blackbox.py 2010-08-25 19:27:04 +0000
110+++ tests/test_blackbox.py 2010-12-07 17:56:23 +0000
111@@ -14,6 +14,7 @@
112 # with this program. If not, see <http://www.gnu.org/licenses/>.
113
114 import os
115+from textwrap import dedent
116
117 from bzrlib import workingtree
118 from bzrlib.tests import (
119@@ -284,3 +285,89 @@
120 retcode=3)
121 self.assertContainsRe(err, "The 'run' instruction is forbidden.$")
122
123+ def make_simple_quilt_package(self):
124+ source = self.make_simple_package()
125+ self.build_tree(["source/debian/source/"])
126+ self.build_tree_contents([
127+ ("source/debian/source/format", "3.0 (quilt)\n")])
128+ source.add(["debian/source", "debian/source/format"])
129+ source.commit("set source format")
130+ return source
131+
132+ def test_cmd_dailydeb_force_native(self):
133+ self.make_simple_quilt_package()
134+ self.build_tree_contents([("test.recipe", "# bzr-builder format 0.3 "
135+ "deb-version 1\nsource 2\n")])
136+ out, err = self.run_bzr(
137+ "dailydeb -q test.recipe working", retcode=0)
138+ self.assertFileEqual("3.0 (native)\n",
139+ "working/test-1/debian/source/format")
140+
141+ def test_cmd_dailydeb_force_native_apply_quilt(self):
142+ source = self.make_simple_quilt_package()
143+ self.build_tree(["source/debian/patches/"])
144+ patch = dedent(
145+ """diff -ur a/thefile b/thefile
146+ --- a/thefile 2010-12-05 20:14:22.000000000 +0100
147+ +++ b/thefile 2010-12-05 20:14:26.000000000 +0100
148+ @@ -1 +1 @@
149+ -old-contents
150+ +new-contents
151+ """)
152+ self.build_tree_contents([
153+ ("source/thefile", "old-contents\n"),
154+ ("source/debian/patches/series", "01_foo.patch"),
155+ ("source/debian/patches/01_foo.patch", patch)])
156+ source.add(["thefile", "debian/patches", "debian/patches/series",
157+ "debian/patches/01_foo.patch"])
158+ source.commit("add patch")
159+
160+ self.build_tree_contents([("test.recipe", "# bzr-builder format 0.3 "
161+ "deb-version 1\nsource\n")])
162+ out, err = self.run_bzr(
163+ "dailydeb -q test.recipe working", retcode=0)
164+ self.assertFileEqual("3.0 (native)\n",
165+ "working/test-1/debian/source/format")
166+ self.assertFileEqual("new-contents\n",
167+ "working/test-1/thefile")
168+ self.failIfExists("working/test-1/debian/patches")
169+
170+ def test_cmd_dailydeb_force_native_apply_quilt_failure(self):
171+ source = self.make_simple_quilt_package()
172+ self.build_tree(["source/debian/patches/"])
173+ patch = dedent(
174+ """diff -ur a/thefile b/thefile
175+ --- a/thefile 2010-12-05 20:14:22.000000000 +0100
176+ +++ b/thefile 2010-12-05 20:14:26.000000000 +0100
177+ @@ -1 +1 @@
178+ -old-contents
179+ +new-contents
180+ """)
181+ self.build_tree_contents([
182+ ("source/thefile", "contents\n"),
183+ ("source/debian/patches/series", "01_foo.patch"),
184+ ("source/debian/patches/01_foo.patch", patch)])
185+ source.add(["thefile", "debian/patches", "debian/patches/series",
186+ "debian/patches/01_foo.patch"])
187+ source.commit("add patch")
188+
189+ self.build_tree_contents([("test.recipe", "# bzr-builder format 0.3 "
190+ "deb-version 1\nsource\n")])
191+ out, err = self.run_bzr(
192+ "dailydeb -q test.recipe working", retcode=3)
193+ self.assertContainsRe(err, "bzr: ERROR: Failed to apply quilt patches")
194+
195+ def test_unknown_source_format(self):
196+ source = self.make_simple_package()
197+ self.build_tree(["source/debian/source/"])
198+ self.build_tree_contents([
199+ ("source/debian/source/format", "2.0\n")])
200+ source.add(["debian/source", "debian/source/format"])
201+ source.commit("set source format")
202+
203+ self.build_tree_contents([("test.recipe", "# bzr-builder format 0.3 "
204+ "deb-version 1\nsource\n")])
205+ out, err = self.run_bzr(
206+ "dailydeb -q test.recipe working", retcode=3)
207+ self.assertEquals(err, "bzr: ERROR: Unknown source format 2.0\n")
208+

Subscribers

People subscribed via source and target branches