Merge lp:~jelmer/bzr-builddeb/auto-native into lp:bzr-builddeb

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: 492
Proposed branch: lp:~jelmer/bzr-builddeb/auto-native
Merge into: lp:bzr-builddeb
Prerequisite: lp:~jelmer/bzr-builddeb/build-type-enum
Diff against target: 269 lines (+171/-12)
5 files modified
cmds.py (+3/-9)
debian/changelog (+3/-1)
errors.py (+17/-0)
tests/test_util.py (+91/-1)
util.py (+57/-1)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/auto-native
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+45799@code.launchpad.net

Commit message

Recognize that a branch is native or normal based on debian/source/format.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

This branch makes bzr-builddeb recognize that a package is native or not by looking at the debian/source/format file.

It will also report inconsistencies between debian/source/format and the version in the changelog file, if both are present.

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

Related to this I wonder if we can drop the --native and --merge flags, they no longer seem necessary now.

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

On Tue, 11 Jan 2011 00:36:09 -0000, Jelmer Vernooij <email address hidden> wrote:
> Related to this I wonder if we can drop the --native and --merge flags, they no longer seem necessary now.

For --native there will still be a bunch of 1.0 native packages that
this won't get.

Having said that, I would like to get rid of them anyway, as there are
some people that don't create the configuration files, and only use the
flags, meaning that other people find problems when they try and build
the packages.

I think that we should probably have a deprecation period though.

Thanks,

James

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

Looks good.

Thanks,

James

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

Hi,

Thanks for the review :-)

On Thu, 2011-01-13 at 17:58 +0000, James Westby wrote:
> On Tue, 11 Jan 2011 00:36:09 -0000, Jelmer Vernooij <email address hidden> wrote:
> > Related to this I wonder if we can drop the --native and --merge flags, they no longer seem necessary now.
> For --native there will still be a bunch of 1.0 native packages that
> this won't get.
The version is also used as an indication of whether the package is
native or not, and should work for 1.0 packages too.

> Having said that, I would like to get rid of them anyway, as there are
> some people that don't create the configuration files, and only use the
> flags, meaning that other people find problems when they try and build
> the packages.
>
> I think that we should probably have a deprecation period though.
Yeah, that makes sense.

Cheers,

Jelmer

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 2011-01-11 00:29:56 +0000
3+++ cmds.py 2011-01-11 00:29:56 +0000
4@@ -104,6 +104,7 @@
5 find_last_distribution,
6 find_previous_upload,
7 get_export_upstream_revision,
8+ guess_build_type,
9 lookup_distribution,
10 open_file,
11 open_file_via_transport,
12@@ -135,7 +136,6 @@
13 help="Select the upstream revision that will be exported.",
14 type=str)
15
16-
17 class cmd_builddeb(Command):
18 """Builds a Debian package from a branch.
19
20@@ -359,14 +359,8 @@
21 except NoPreviousUpload:
22 prev_version = None
23 if build_type is None:
24- if prev_version and not prev_version.debian_revision:
25- # If the package doesn't have a debian revision, assume it's native.
26- build_type = BUILD_TYPE_NATIVE
27- elif not contains_upstream_source:
28- # Default to merge mode if there's only a debian/ directory
29- build_type = BUILD_TYPE_MERGE
30- else:
31- build_type = BUILD_TYPE_NORMAL
32+ build_type = guess_build_type(tree, changelog.version,
33+ contains_upstream_source)
34
35 note("Building package in %s mode" % {
36 BUILD_TYPE_NATIVE: "native",
37
38=== modified file 'debian/changelog'
39--- debian/changelog 2010-09-10 02:53:47 +0000
40+++ debian/changelog 2011-01-11 00:29:56 +0000
41@@ -22,8 +22,10 @@
42 if we can't find the tarball.
43 * Determine Bazaar home directory using bzrlib to prevent test
44 isolation issues. LP: #614125
45+ * Automatically use debian/source/format if package is native. Closes:
46+ #586617
47
48- -- James Westby <james.westby@ubuntu.com> Wed, 18 Aug 2010 20:12:20 -0400
49+ -- Jelmer Vernooij <jelmer@debian.org> Tue, 11 Jan 2011 00:42:21 +0100
50
51 bzr-builddeb (2.5) unstable; urgency=low
52
53
54=== modified file 'errors.py'
55--- errors.py 2010-06-15 11:33:11 +0000
56+++ errors.py 2011-01-11 00:29:56 +0000
57@@ -203,3 +203,20 @@
58 class UnableToFindPreviousUpload(BzrError):
59
60 _fmt = ("Unable to determine the previous upload for --package-merge.")
61+
62+
63+class InconsistentSourceFormatError(BzrError):
64+
65+ _fmt = ("Inconsistency between source format and version: version is "
66+ "%(version_bool)snative, format is %(format_bool)snative.")
67+
68+ def __init__(self, version_native, format_native):
69+ if version_native:
70+ version_bool = ""
71+ else:
72+ version_bool = "not "
73+ if format_native:
74+ format_bool = ""
75+ else:
76+ format_bool = "not "
77+ BzrError.__init__(self, version_bool=version_bool, format_bool=format_bool)
78
79=== modified file 'tests/test_util.py'
80--- tests/test_util.py 2010-07-29 18:41:30 +0000
81+++ tests/test_util.py 2011-01-11 00:29:56 +0000
82@@ -31,9 +31,15 @@
83 # Prior to 0.1.15 the debian module was called debian_bundle
84 from debian_bundle.changelog import Changelog, Version
85
86-from bzrlib.plugins.builddeb.config import DebBuildConfig
87+from bzrlib.plugins.builddeb.config import (
88+ DebBuildConfig,
89+ BUILD_TYPE_MERGE,
90+ BUILD_TYPE_NATIVE,
91+ BUILD_TYPE_NORMAL,
92+ )
93 from bzrlib.plugins.builddeb.errors import (MissingChangelogError,
94 AddChangelogError,
95+ InconsistentSourceFormatError,
96 NoPreviousUpload,
97 UnknownDistribution,
98 )
99@@ -50,6 +56,8 @@
100 get_export_upstream_revision,
101 get_commit_info_from_changelog,
102 get_snapshot_revision,
103+ get_source_format,
104+ guess_build_type,
105 lookup_distribution,
106 move_file_if_different,
107 get_parent_dir,
108@@ -772,3 +780,85 @@
109 self.assertRaises(NoPreviousUpload, _find_previous_upload, cl)
110 cl = self.make_changelog([("0.1-1", "unstable")])
111 self.assertRaises(NoPreviousUpload, _find_previous_upload, cl)
112+
113+
114+class SourceFormatTests(TestCaseWithTransport):
115+
116+ def test_no_source_format_file(self):
117+ tree = self.make_branch_and_tree('.')
118+ self.assertEquals("1.0", get_source_format(tree))
119+
120+ def test_source_format_newline(self):
121+ tree = self.make_branch_and_tree('.')
122+ self.build_tree_contents([("debian/", ), ("debian/source/",),
123+ ("debian/source/format", "3.0 (native)\n")])
124+ tree.add(["debian", "debian/source", "debian/source/format"])
125+ self.assertEquals("3.0 (native)", get_source_format(tree))
126+
127+ def test_source_format(self):
128+ tree = self.make_branch_and_tree('.')
129+ self.build_tree_contents([("debian/",), ("debian/source/",),
130+ ("debian/source/format", "3.0 (quilt)")])
131+ tree.add(["debian", "debian/source", "debian/source/format"])
132+ self.assertEquals("3.0 (quilt)", get_source_format(tree))
133+
134+
135+class GuessBuildTypeTests(TestCaseWithTransport):
136+ """Tests for guess_build_type."""
137+
138+ def writeVersionFile(self, tree, format_string):
139+ """Write a Debian source format file.
140+
141+ :param tree: Tree to write to.
142+ :param format_string: Format string to write.
143+ """
144+ self.build_tree_contents([("debian/",), ("debian/source/",),
145+ ("debian/source/format", format_string)])
146+ tree.add(["debian", "debian/source", "debian/source/format"])
147+
148+ def test_normal_source_format(self):
149+ # Normal source format -> NORMAL
150+ tree = self.make_branch_and_tree('.')
151+ self.writeVersionFile(tree, "3.0 (quilt)")
152+ self.assertEquals(BUILD_TYPE_NORMAL, guess_build_type(tree, None, True))
153+
154+ def test_normal_source_format_merge(self):
155+ # Normal source format without upstream source -> MERGE
156+ tree = self.make_branch_and_tree('.')
157+ self.writeVersionFile(tree, "3.0 (quilt)")
158+ self.assertEquals(BUILD_TYPE_MERGE, guess_build_type(tree, None, False))
159+
160+ def test_native_source_format(self):
161+ # Native source format -> NATIVE
162+ tree = self.make_branch_and_tree('.')
163+ self.writeVersionFile(tree, "3.0 (native)")
164+ self.assertEquals(BUILD_TYPE_NATIVE, guess_build_type(tree, None, True))
165+
166+ def test_prev_version_native(self):
167+ # Native package version -> NATIVE
168+ tree = self.make_branch_and_tree('.')
169+ self.assertEquals(BUILD_TYPE_NATIVE,
170+ guess_build_type(tree, Version("1.0"), True))
171+
172+ def test_no_upstream_source(self):
173+ # No upstream source code and a non-native package -> MERGE
174+ tree = self.make_branch_and_tree('.')
175+ self.assertEquals(BUILD_TYPE_MERGE,
176+ guess_build_type(tree, Version("1.0-1"), False))
177+
178+ def test_default(self):
179+ # Upstream source code and a non-native package -> NORMAL
180+ tree = self.make_branch_and_tree('.')
181+ self.assertEquals(BUILD_TYPE_NORMAL,
182+ guess_build_type(tree, Version("1.0-1"), True))
183+
184+ def test_inconsistent(self):
185+ # If version string and source format disagree on whether the package is native,
186+ # raise an exception.
187+ tree = self.make_branch_and_tree('.')
188+ self.writeVersionFile(tree, "3.0 (native)")
189+ e = self.assertRaises(InconsistentSourceFormatError, guess_build_type, tree,
190+ Version("1.0-1"), True)
191+ self.assertEquals(
192+ "Inconsistency between source format and version: version is not native, "
193+ "format is native.", str(e))
194
195=== modified file 'util.py'
196--- util.py 2011-01-11 00:29:56 +0000
197+++ util.py 2011-01-11 00:29:56 +0000
198@@ -55,10 +55,16 @@
199 local_conf,
200 global_conf,
201 )
202-from bzrlib.plugins.builddeb.config import DebBuildConfig
203+from bzrlib.plugins.builddeb.config import (
204+ DebBuildConfig,
205+ BUILD_TYPE_MERGE,
206+ BUILD_TYPE_NATIVE,
207+ BUILD_TYPE_NORMAL,
208+ )
209 from bzrlib.plugins.builddeb.errors import (
210 MissingChangelogError,
211 AddChangelogError,
212+ InconsistentSourceFormatError,
213 NoPreviousUpload,
214 UnableToFindPreviousUpload,
215 UnknownDistribution,
216@@ -612,3 +618,53 @@
217 present_files = set(root.children.keys())
218 packaging_files = frozenset(["debian", ".bzr-builddeb"])
219 return (len(present_files - packaging_files) > 0)
220+
221+
222+def get_source_format(tree):
223+ """Retrieve the source format name from a package.
224+
225+ :param path: Path to the package
226+ :return: String with package format
227+ """
228+ if not tree.has_filename("debian/source/format"):
229+ return "1.0"
230+ return tree.get_file_text(tree.path2id("debian/source/format")).strip()
231+
232+
233+NATIVE_SOURCE_FORMATS = ["3.0 (native)"]
234+NORMAL_SOURCE_FORMATS = ["3.0 (quilt)"]
235+
236+
237+def guess_build_type(tree, version, contains_upstream_source):
238+ """Guess the build type based on the contents of a tree.
239+
240+ :param tree: A `Tree` object.
241+ :param version: `Version` of the upload.
242+ :param contains_upstream_source: Whether this branch contains the upstream source.
243+ :return: A build_type value.
244+ """
245+ source_format = get_source_format(tree)
246+ if source_format in NATIVE_SOURCE_FORMATS:
247+ format_native = True
248+ elif source_format in NORMAL_SOURCE_FORMATS:
249+ format_native = False
250+ else:
251+ format_native = None
252+
253+ # If the package doesn't have a debian revision then it must be native.
254+ if version is not None:
255+ version_native = (not version.debian_revision)
256+ else:
257+ version_native = None
258+
259+ if type(version_native) is bool and type(format_native) is bool:
260+ if version_native != format_native:
261+ raise InconsistentSourceFormatError(version_native, format_native)
262+
263+ if version_native or format_native:
264+ return BUILD_TYPE_NATIVE
265+ if not contains_upstream_source:
266+ # Default to merge mode if there's only a debian/ directory
267+ return BUILD_TYPE_MERGE
268+ else:
269+ return BUILD_TYPE_NORMAL

Subscribers

People subscribed via source and target branches