Merge lp:~jelmer/bzr-builddeb/build-type-enum into lp:bzr-builddeb

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 489
Merge reported by: Jelmer Vernooij
Merged at revision: not available
Proposed branch: lp:~jelmer/bzr-builddeb/build-type-enum
Merge into: lp:bzr-builddeb
Diff against target: 291 lines (+85/-42)
5 files modified
__init__.py (+2/-1)
cmds.py (+54/-38)
config.py (+17/-0)
tests/test_config.py (+7/-1)
util.py (+5/-2)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/build-type-enum
Reviewer Review Type Date Requested Status
Bzr-builddeb-hackers Pending
Review via email: mp+45789@code.launchpad.net

Description of the change

This changes bzr-builddeb to use a "build_type" enum internally, rather than a tuple with three booleans ("split", "merge", "native").

This simplifies the code a bit, it makes the automatic detection of native packages better (looks at the debian revision if there was a previous upload for this distroseries) and should make it easier to fix bug 586617.

To post a comment you must log in.
Revision history for this message
Andrew Bennetts (spiv) wrote :

208 +BUILD_TYPE_NORMAL = 0
209 +BUILD_TYPE_NATIVE = 1
210 +BUILD_TYPE_MERGE = 2
211 +BUILD_TYPE_SPLIT = 3

In my experience it's nicer to use string constants for enums (e.g. 'NORMAL') rather than integers. This makes debugging much more pleasant.

489. By Jelmer Vernooij

Use string constants for enum, per spiv's suggestion.

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

On Wed, 2011-01-12 at 20:00 +0000, Andrew Bennetts wrote:
> In my experience it's nicer to use string constants for enums (e.g. 'NORMAL') rather than integers. This makes debugging much more pleasant.
Thanks, that's a useful suggestion. Fixed!

Cheers,

Jelmer

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '__init__.py'
2--- __init__.py 2011-01-10 22:44:18 +0000
3+++ __init__.py 2011-01-12 21:33:12 +0000
4@@ -135,6 +135,7 @@
5
6
7 def debian_tag_name(branch, revid):
8+ from bzrlib.plugins.builddeb.config import BUILD_TYPE_MERGE
9 from bzrlib.plugins.builddeb.errors import MissingChangelogError
10 from bzrlib.plugins.builddeb.import_dsc import (DistributionBranch,
11 DistributionBranchSet)
12@@ -142,7 +143,7 @@
13 t = branch.repository.revision_tree(revid)
14 config = debuild_config(t, False)
15 try:
16- (changelog, larstiq) = find_changelog(t, config.merge)
17+ (changelog, larstiq) = find_changelog(t, config.build_type == BUILD_TYPE_MERGE)
18 except MissingChangelogError:
19 # Not a debian package
20 return None
21
22=== modified file 'cmds.py'
23--- cmds.py 2010-11-17 16:53:31 +0000
24+++ cmds.py 2011-01-12 21:33:12 +0000
25@@ -61,7 +61,16 @@
26 from bzrlib.plugins.builddeb.builder import (
27 DebBuild,
28 )
29-from bzrlib.plugins.builddeb.errors import BuildFailedError
30+from bzrlib.plugins.builddeb.config import (
31+ BUILD_TYPE_MERGE,
32+ BUILD_TYPE_NATIVE,
33+ BUILD_TYPE_NORMAL,
34+ BUILD_TYPE_SPLIT,
35+ )
36+from bzrlib.plugins.builddeb.errors import (
37+ BuildFailedError,
38+ NoPreviousUpload,
39+ )
40 from bzrlib.plugins.builddeb.hooks import run_hook
41 from bzrlib.plugins.builddeb.import_dsc import (
42 DistributionBranch,
43@@ -222,25 +231,14 @@
44 working_tree = False
45 return tree, working_tree
46
47- def _build_type(self, config, merge, native, split):
48- if not merge:
49- merge = config.merge
50+ def _build_type(self, merge, native, split):
51 if merge:
52- note("Running in merge mode")
53- native = False
54- split = False
55- else:
56- if not native:
57- native = config.native
58- if native:
59- note("Running in native mode")
60- split = False
61- else:
62- if not split:
63- split = config.split
64- if split:
65- note("Running in split mode")
66- return merge, native, split
67+ return BUILD_TYPE_MERGE
68+ if native:
69+ return BUILD_TYPE_NATIVE
70+ if split:
71+ return BUILD_TYPE_SPLIT
72+ return None
73
74 def _get_build_command(self, config, builder, quick, build_options):
75 if builder is None:
76@@ -327,10 +325,10 @@
77 def run(self, branch_or_build_options_list=None, verbose=False,
78 working_tree=False,
79 export_only=False, dont_purge=False, use_existing=False,
80- result_dir=None, builder=None, merge=False, build_dir=None,
81+ result_dir=None, builder=None, merge=None, build_dir=None,
82 export_upstream=None, export_upstream_revision=None,
83 orig_dir=None, split=None,
84- quick=False, reuse=False, native=False,
85+ quick=False, reuse=False, native=None,
86 source=False, revision=None, result=None, package_merge=None):
87 if result is not None:
88 warning("--result is deprected, use --result-dir instead")
89@@ -351,14 +349,32 @@
90 note("Reusing existing build dir")
91 dont_purge = True
92 use_existing = True
93- merge, native, split = self._build_type(config, merge, native, split)
94- if (not merge and not native and not split and
95- not tree_contains_upstream_source(tree)):
96- # Default to merge mode if there's only a debian/ directory
97- merge = True
98- (changelog, larstiq) = find_changelog(tree, merge)
99+ build_type = self._build_type(merge, native, split)
100+ if build_type is None:
101+ build_type = config.build_type
102+ contains_upstream_source = tree_contains_upstream_source(tree)
103+ (changelog, larstiq) = find_changelog(tree, not contains_upstream_source)
104+ try:
105+ prev_version = find_previous_upload(tree, not contains_upstream_source)
106+ except NoPreviousUpload:
107+ prev_version = None
108+ if build_type is None:
109+ if prev_version and not prev_version.debian_revision:
110+ # If the package doesn't have a debian revision, assume it's native.
111+ build_type = BUILD_TYPE_NATIVE
112+ elif not contains_upstream_source:
113+ # Default to merge mode if there's only a debian/ directory
114+ build_type = BUILD_TYPE_MERGE
115+ else:
116+ build_type = BUILD_TYPE_NORMAL
117+
118+ note("Building package in %s mode" % {
119+ BUILD_TYPE_NATIVE: "native",
120+ BUILD_TYPE_MERGE: "merge",
121+ BUILD_TYPE_SPLIT: "split",
122+ BUILD_TYPE_NORMAL: "normal"}[build_type])
123+
124 if package_merge:
125- prev_version = find_previous_upload(tree, merge)
126 build_options.append("-v%s" % str(prev_version))
127 if (prev_version.upstream_version
128 != changelog.version.upstream_version
129@@ -370,7 +386,7 @@
130 is_local, result_dir or result, build_dir, orig_dir)
131
132 upstream_sources = [
133- PristineTarSource(tree, branch),
134+ PristineTarSource(tree, branch),
135 AptSource(),
136 ]
137 if merge:
138@@ -689,10 +705,10 @@
139 "working tree. You must commit before using this "
140 "command.")
141 config = debuild_config(tree, tree)
142- if config.merge:
143+ if config.build_type == BUILD_TYPE_MERGE:
144 raise BzrCommandError("Merge upstream in merge mode is not "
145 "yet supported.")
146- if config.native:
147+ if config.build_type == BUILD_TYPE_NATIVE:
148 raise BzrCommandError("Merge upstream in native mode is not "
149 "yet supported.")
150
151@@ -803,7 +819,7 @@
152 "source package to install, or use the "
153 "--file option.")
154 config = debuild_config(tree, tree)
155- if config.merge:
156+ if config.build_type == BUILD_TYPE_MERGE:
157 raise BzrCommandError("import-dsc in merge mode is not "
158 "yet supported.")
159 orig_dir = config.orig_dir or default_orig_dir
160@@ -959,8 +975,7 @@
161 def run(self, command_list=None):
162 t = WorkingTree.open_containing('.')[0]
163 config = debuild_config(t, t)
164-
165- if not config.merge:
166+ if config.build_type != BUILD_TYPE_MERGE:
167 raise BzrCommandError("This command only works for merge mode "
168 "packages. See /usr/share/doc/bzr-builddeb"
169 "/user_manual/merge.html for more information.")
170@@ -1040,7 +1055,7 @@
171
172 takes_options = [merge_opt, force]
173
174- def run(self, merge=False, force=None):
175+ def run(self, merge=None, force=None):
176 t = WorkingTree.open_containing('.')[0]
177 t.lock_write()
178 try:
179@@ -1049,8 +1064,8 @@
180 "working tree. You must commit before using this "
181 "command")
182 config = debuild_config(t, t)
183- if not merge:
184- merge = config.merge
185+ if merge is None:
186+ merge = (config.build_type == BUILD_TYPE_MERGE)
187 (changelog, larstiq) = find_changelog(t, merge)
188 if changelog.distributions == 'UNRELEASED':
189 if not force:
190@@ -1104,7 +1119,8 @@
191 this_config = debuild_config(tree, tree)
192 that_config = debuild_config(source_branch.basis_tree(),
193 source_branch.basis_tree())
194- if not (this_config.native or that_config.native):
195+ if not (this_config.build_type == BUILD_TYPE_NATIVE or
196+ that_config.build_type == BUILD_TYPE_NATIVE):
197 fix_ancestry_as_needed(tree, source_branch)
198
199 # Merge source packaging branch in to the target packaging branch.
200
201=== modified file 'config.py'
202--- config.py 2010-02-10 13:59:07 +0000
203+++ config.py 2011-01-12 21:33:12 +0000
204@@ -26,6 +26,12 @@
205 from configobj import ParseError
206
207
208+BUILD_TYPE_NORMAL = "normal"
209+BUILD_TYPE_NATIVE = "native"
210+BUILD_TYPE_MERGE = "merge"
211+BUILD_TYPE_SPLIT = "split"
212+
213+
214 class SvnBuildPackageMappedConfig(object):
215 """Config object that provides a bzr-builddeb configuration
216 based on a svn-buildpackage configuration.
217@@ -257,6 +263,17 @@
218
219 merge = _bool_property('merge', "Run in merge mode")
220
221+ @property
222+ def build_type(self):
223+ if self.merge:
224+ return BUILD_TYPE_MERGE
225+ elif self.native:
226+ return BUILD_TYPE_NATIVE
227+ elif self.split:
228+ return BUILD_TYPE_SPLIT
229+ else:
230+ return BUILD_TYPE_NORMAL
231+
232 quick_builder = _opt_property('quick-builder',
233 "A quick command to build with", True)
234
235
236=== modified file 'tests/test_config.py'
237--- tests/test_config.py 2009-03-04 13:25:53 +0000
238+++ tests/test_config.py 2011-01-12 21:33:12 +0000
239@@ -21,7 +21,11 @@
240 from bzrlib.branch import Branch
241 from bzrlib.tests import TestCaseWithTransport
242
243-from bzrlib.plugins.builddeb.config import DebBuildConfig
244+from bzrlib.plugins.builddeb.config import (
245+ BUILD_TYPE_MERGE,
246+ BUILD_TYPE_NORMAL,
247+ DebBuildConfig,
248+ )
249
250
251 class DebBuildConfigTests(TestCaseWithTransport):
252@@ -75,6 +79,7 @@
253
254 def test_no_entry(self):
255 self.assertEqual(self.config.merge, False)
256+ self.assertEqual(self.config.build_type, BUILD_TYPE_NORMAL)
257
258 def test_parse_error(self):
259 f = open('invalid.conf', 'wb')
260@@ -107,6 +112,7 @@
261
262 cfg = DebBuildConfig([], tree=Branch.open(repos_url).basis_tree())
263 self.assertEquals(True, cfg.merge)
264+ self.assertEquals(BUILD_TYPE_MERGE, cfg.build_type)
265 self.assertEquals("someorigdir", cfg.orig_dir)
266
267 def test_from_svn_layout_file(self):
268
269=== modified file 'util.py'
270--- util.py 2010-10-30 15:17:44 +0000
271+++ util.py 2011-01-12 21:33:12 +0000
272@@ -140,7 +140,7 @@
273 try:
274 if not t.has_filename(changelog_file):
275 if merge:
276- #Assume LarstiQ's layout (.bzr in debian/)
277+ # Assume LarstiQ's layout (.bzr in debian/)
278 changelog_file = 'changelog'
279 larstiq = True
280 if not t.has_filename(changelog_file):
281@@ -606,6 +606,9 @@
282 :return: Boolean indicating whether or not the tree contains the upstream
283 source
284 """
285- present_files = set(tree.inventory.root.children.keys())
286+ root = tree.inventory.root
287+ if root is None:
288+ return False # Empty tree
289+ present_files = set(root.children.keys())
290 packaging_files = frozenset(["debian", ".bzr-builddeb"])
291 return (len(present_files - packaging_files) > 0)

Subscribers

People subscribed via source and target branches