Merge lp:~jelmer/bzr-builddeb/auto-native into lp:bzr-builddeb
- auto-native
- Merge into trunk
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 |
Related bugs: |
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/
Description of the change
Jelmer Vernooij (jelmer) wrote : | # |
Jelmer Vernooij (jelmer) wrote : | # |
Related to this I wonder if we can drop the --native and --merge flags, they no longer seem necessary now.
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
James Westby (james-w) wrote : | # |
Looks good.
Thanks,
James
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
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 | 104 | find_last_distribution, | 104 | find_last_distribution, |
6 | 105 | find_previous_upload, | 105 | find_previous_upload, |
7 | 106 | get_export_upstream_revision, | 106 | get_export_upstream_revision, |
8 | 107 | guess_build_type, | ||
9 | 107 | lookup_distribution, | 108 | lookup_distribution, |
10 | 108 | open_file, | 109 | open_file, |
11 | 109 | open_file_via_transport, | 110 | open_file_via_transport, |
12 | @@ -135,7 +136,6 @@ | |||
13 | 135 | help="Select the upstream revision that will be exported.", | 136 | help="Select the upstream revision that will be exported.", |
14 | 136 | type=str) | 137 | type=str) |
15 | 137 | 138 | ||
16 | 138 | |||
17 | 139 | class cmd_builddeb(Command): | 139 | class cmd_builddeb(Command): |
18 | 140 | """Builds a Debian package from a branch. | 140 | """Builds a Debian package from a branch. |
19 | 141 | 141 | ||
20 | @@ -359,14 +359,8 @@ | |||
21 | 359 | except NoPreviousUpload: | 359 | except NoPreviousUpload: |
22 | 360 | prev_version = None | 360 | prev_version = None |
23 | 361 | if build_type is None: | 361 | if build_type is None: |
32 | 362 | if prev_version and not prev_version.debian_revision: | 362 | build_type = guess_build_type(tree, changelog.version, |
33 | 363 | # If the package doesn't have a debian revision, assume it's native. | 363 | contains_upstream_source) |
26 | 364 | build_type = BUILD_TYPE_NATIVE | ||
27 | 365 | elif not contains_upstream_source: | ||
28 | 366 | # Default to merge mode if there's only a debian/ directory | ||
29 | 367 | build_type = BUILD_TYPE_MERGE | ||
30 | 368 | else: | ||
31 | 369 | build_type = BUILD_TYPE_NORMAL | ||
34 | 370 | 364 | ||
35 | 371 | note("Building package in %s mode" % { | 365 | note("Building package in %s mode" % { |
36 | 372 | BUILD_TYPE_NATIVE: "native", | 366 | BUILD_TYPE_NATIVE: "native", |
37 | 373 | 367 | ||
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 | 22 | if we can't find the tarball. | 22 | if we can't find the tarball. |
43 | 23 | * Determine Bazaar home directory using bzrlib to prevent test | 23 | * Determine Bazaar home directory using bzrlib to prevent test |
44 | 24 | isolation issues. LP: #614125 | 24 | isolation issues. LP: #614125 |
45 | 25 | * Automatically use debian/source/format if package is native. Closes: | ||
46 | 26 | #586617 | ||
47 | 25 | 27 | ||
49 | 26 | -- James Westby <james.westby@ubuntu.com> Wed, 18 Aug 2010 20:12:20 -0400 | 28 | -- Jelmer Vernooij <jelmer@debian.org> Tue, 11 Jan 2011 00:42:21 +0100 |
50 | 27 | 29 | ||
51 | 28 | bzr-builddeb (2.5) unstable; urgency=low | 30 | bzr-builddeb (2.5) unstable; urgency=low |
52 | 29 | 31 | ||
53 | 30 | 32 | ||
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 | 203 | class UnableToFindPreviousUpload(BzrError): | 203 | class UnableToFindPreviousUpload(BzrError): |
59 | 204 | 204 | ||
60 | 205 | _fmt = ("Unable to determine the previous upload for --package-merge.") | 205 | _fmt = ("Unable to determine the previous upload for --package-merge.") |
61 | 206 | |||
62 | 207 | |||
63 | 208 | class InconsistentSourceFormatError(BzrError): | ||
64 | 209 | |||
65 | 210 | _fmt = ("Inconsistency between source format and version: version is " | ||
66 | 211 | "%(version_bool)snative, format is %(format_bool)snative.") | ||
67 | 212 | |||
68 | 213 | def __init__(self, version_native, format_native): | ||
69 | 214 | if version_native: | ||
70 | 215 | version_bool = "" | ||
71 | 216 | else: | ||
72 | 217 | version_bool = "not " | ||
73 | 218 | if format_native: | ||
74 | 219 | format_bool = "" | ||
75 | 220 | else: | ||
76 | 221 | format_bool = "not " | ||
77 | 222 | BzrError.__init__(self, version_bool=version_bool, format_bool=format_bool) | ||
78 | 206 | 223 | ||
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 | 31 | # Prior to 0.1.15 the debian module was called debian_bundle | 31 | # Prior to 0.1.15 the debian module was called debian_bundle |
84 | 32 | from debian_bundle.changelog import Changelog, Version | 32 | from debian_bundle.changelog import Changelog, Version |
85 | 33 | 33 | ||
87 | 34 | from bzrlib.plugins.builddeb.config import DebBuildConfig | 34 | from bzrlib.plugins.builddeb.config import ( |
88 | 35 | DebBuildConfig, | ||
89 | 36 | BUILD_TYPE_MERGE, | ||
90 | 37 | BUILD_TYPE_NATIVE, | ||
91 | 38 | BUILD_TYPE_NORMAL, | ||
92 | 39 | ) | ||
93 | 35 | from bzrlib.plugins.builddeb.errors import (MissingChangelogError, | 40 | from bzrlib.plugins.builddeb.errors import (MissingChangelogError, |
94 | 36 | AddChangelogError, | 41 | AddChangelogError, |
95 | 42 | InconsistentSourceFormatError, | ||
96 | 37 | NoPreviousUpload, | 43 | NoPreviousUpload, |
97 | 38 | UnknownDistribution, | 44 | UnknownDistribution, |
98 | 39 | ) | 45 | ) |
99 | @@ -50,6 +56,8 @@ | |||
100 | 50 | get_export_upstream_revision, | 56 | get_export_upstream_revision, |
101 | 51 | get_commit_info_from_changelog, | 57 | get_commit_info_from_changelog, |
102 | 52 | get_snapshot_revision, | 58 | get_snapshot_revision, |
103 | 59 | get_source_format, | ||
104 | 60 | guess_build_type, | ||
105 | 53 | lookup_distribution, | 61 | lookup_distribution, |
106 | 54 | move_file_if_different, | 62 | move_file_if_different, |
107 | 55 | get_parent_dir, | 63 | get_parent_dir, |
108 | @@ -772,3 +780,85 @@ | |||
109 | 772 | self.assertRaises(NoPreviousUpload, _find_previous_upload, cl) | 780 | self.assertRaises(NoPreviousUpload, _find_previous_upload, cl) |
110 | 773 | cl = self.make_changelog([("0.1-1", "unstable")]) | 781 | cl = self.make_changelog([("0.1-1", "unstable")]) |
111 | 774 | self.assertRaises(NoPreviousUpload, _find_previous_upload, cl) | 782 | self.assertRaises(NoPreviousUpload, _find_previous_upload, cl) |
112 | 783 | |||
113 | 784 | |||
114 | 785 | class SourceFormatTests(TestCaseWithTransport): | ||
115 | 786 | |||
116 | 787 | def test_no_source_format_file(self): | ||
117 | 788 | tree = self.make_branch_and_tree('.') | ||
118 | 789 | self.assertEquals("1.0", get_source_format(tree)) | ||
119 | 790 | |||
120 | 791 | def test_source_format_newline(self): | ||
121 | 792 | tree = self.make_branch_and_tree('.') | ||
122 | 793 | self.build_tree_contents([("debian/", ), ("debian/source/",), | ||
123 | 794 | ("debian/source/format", "3.0 (native)\n")]) | ||
124 | 795 | tree.add(["debian", "debian/source", "debian/source/format"]) | ||
125 | 796 | self.assertEquals("3.0 (native)", get_source_format(tree)) | ||
126 | 797 | |||
127 | 798 | def test_source_format(self): | ||
128 | 799 | tree = self.make_branch_and_tree('.') | ||
129 | 800 | self.build_tree_contents([("debian/",), ("debian/source/",), | ||
130 | 801 | ("debian/source/format", "3.0 (quilt)")]) | ||
131 | 802 | tree.add(["debian", "debian/source", "debian/source/format"]) | ||
132 | 803 | self.assertEquals("3.0 (quilt)", get_source_format(tree)) | ||
133 | 804 | |||
134 | 805 | |||
135 | 806 | class GuessBuildTypeTests(TestCaseWithTransport): | ||
136 | 807 | """Tests for guess_build_type.""" | ||
137 | 808 | |||
138 | 809 | def writeVersionFile(self, tree, format_string): | ||
139 | 810 | """Write a Debian source format file. | ||
140 | 811 | |||
141 | 812 | :param tree: Tree to write to. | ||
142 | 813 | :param format_string: Format string to write. | ||
143 | 814 | """ | ||
144 | 815 | self.build_tree_contents([("debian/",), ("debian/source/",), | ||
145 | 816 | ("debian/source/format", format_string)]) | ||
146 | 817 | tree.add(["debian", "debian/source", "debian/source/format"]) | ||
147 | 818 | |||
148 | 819 | def test_normal_source_format(self): | ||
149 | 820 | # Normal source format -> NORMAL | ||
150 | 821 | tree = self.make_branch_and_tree('.') | ||
151 | 822 | self.writeVersionFile(tree, "3.0 (quilt)") | ||
152 | 823 | self.assertEquals(BUILD_TYPE_NORMAL, guess_build_type(tree, None, True)) | ||
153 | 824 | |||
154 | 825 | def test_normal_source_format_merge(self): | ||
155 | 826 | # Normal source format without upstream source -> MERGE | ||
156 | 827 | tree = self.make_branch_and_tree('.') | ||
157 | 828 | self.writeVersionFile(tree, "3.0 (quilt)") | ||
158 | 829 | self.assertEquals(BUILD_TYPE_MERGE, guess_build_type(tree, None, False)) | ||
159 | 830 | |||
160 | 831 | def test_native_source_format(self): | ||
161 | 832 | # Native source format -> NATIVE | ||
162 | 833 | tree = self.make_branch_and_tree('.') | ||
163 | 834 | self.writeVersionFile(tree, "3.0 (native)") | ||
164 | 835 | self.assertEquals(BUILD_TYPE_NATIVE, guess_build_type(tree, None, True)) | ||
165 | 836 | |||
166 | 837 | def test_prev_version_native(self): | ||
167 | 838 | # Native package version -> NATIVE | ||
168 | 839 | tree = self.make_branch_and_tree('.') | ||
169 | 840 | self.assertEquals(BUILD_TYPE_NATIVE, | ||
170 | 841 | guess_build_type(tree, Version("1.0"), True)) | ||
171 | 842 | |||
172 | 843 | def test_no_upstream_source(self): | ||
173 | 844 | # No upstream source code and a non-native package -> MERGE | ||
174 | 845 | tree = self.make_branch_and_tree('.') | ||
175 | 846 | self.assertEquals(BUILD_TYPE_MERGE, | ||
176 | 847 | guess_build_type(tree, Version("1.0-1"), False)) | ||
177 | 848 | |||
178 | 849 | def test_default(self): | ||
179 | 850 | # Upstream source code and a non-native package -> NORMAL | ||
180 | 851 | tree = self.make_branch_and_tree('.') | ||
181 | 852 | self.assertEquals(BUILD_TYPE_NORMAL, | ||
182 | 853 | guess_build_type(tree, Version("1.0-1"), True)) | ||
183 | 854 | |||
184 | 855 | def test_inconsistent(self): | ||
185 | 856 | # If version string and source format disagree on whether the package is native, | ||
186 | 857 | # raise an exception. | ||
187 | 858 | tree = self.make_branch_and_tree('.') | ||
188 | 859 | self.writeVersionFile(tree, "3.0 (native)") | ||
189 | 860 | e = self.assertRaises(InconsistentSourceFormatError, guess_build_type, tree, | ||
190 | 861 | Version("1.0-1"), True) | ||
191 | 862 | self.assertEquals( | ||
192 | 863 | "Inconsistency between source format and version: version is not native, " | ||
193 | 864 | "format is native.", str(e)) | ||
194 | 775 | 865 | ||
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 | 55 | local_conf, | 55 | local_conf, |
200 | 56 | global_conf, | 56 | global_conf, |
201 | 57 | ) | 57 | ) |
203 | 58 | from bzrlib.plugins.builddeb.config import DebBuildConfig | 58 | from bzrlib.plugins.builddeb.config import ( |
204 | 59 | DebBuildConfig, | ||
205 | 60 | BUILD_TYPE_MERGE, | ||
206 | 61 | BUILD_TYPE_NATIVE, | ||
207 | 62 | BUILD_TYPE_NORMAL, | ||
208 | 63 | ) | ||
209 | 59 | from bzrlib.plugins.builddeb.errors import ( | 64 | from bzrlib.plugins.builddeb.errors import ( |
210 | 60 | MissingChangelogError, | 65 | MissingChangelogError, |
211 | 61 | AddChangelogError, | 66 | AddChangelogError, |
212 | 67 | InconsistentSourceFormatError, | ||
213 | 62 | NoPreviousUpload, | 68 | NoPreviousUpload, |
214 | 63 | UnableToFindPreviousUpload, | 69 | UnableToFindPreviousUpload, |
215 | 64 | UnknownDistribution, | 70 | UnknownDistribution, |
216 | @@ -612,3 +618,53 @@ | |||
217 | 612 | present_files = set(root.children.keys()) | 618 | present_files = set(root.children.keys()) |
218 | 613 | packaging_files = frozenset(["debian", ".bzr-builddeb"]) | 619 | packaging_files = frozenset(["debian", ".bzr-builddeb"]) |
219 | 614 | return (len(present_files - packaging_files) > 0) | 620 | return (len(present_files - packaging_files) > 0) |
220 | 621 | |||
221 | 622 | |||
222 | 623 | def get_source_format(tree): | ||
223 | 624 | """Retrieve the source format name from a package. | ||
224 | 625 | |||
225 | 626 | :param path: Path to the package | ||
226 | 627 | :return: String with package format | ||
227 | 628 | """ | ||
228 | 629 | if not tree.has_filename("debian/source/format"): | ||
229 | 630 | return "1.0" | ||
230 | 631 | return tree.get_file_text(tree.path2id("debian/source/format")).strip() | ||
231 | 632 | |||
232 | 633 | |||
233 | 634 | NATIVE_SOURCE_FORMATS = ["3.0 (native)"] | ||
234 | 635 | NORMAL_SOURCE_FORMATS = ["3.0 (quilt)"] | ||
235 | 636 | |||
236 | 637 | |||
237 | 638 | def guess_build_type(tree, version, contains_upstream_source): | ||
238 | 639 | """Guess the build type based on the contents of a tree. | ||
239 | 640 | |||
240 | 641 | :param tree: A `Tree` object. | ||
241 | 642 | :param version: `Version` of the upload. | ||
242 | 643 | :param contains_upstream_source: Whether this branch contains the upstream source. | ||
243 | 644 | :return: A build_type value. | ||
244 | 645 | """ | ||
245 | 646 | source_format = get_source_format(tree) | ||
246 | 647 | if source_format in NATIVE_SOURCE_FORMATS: | ||
247 | 648 | format_native = True | ||
248 | 649 | elif source_format in NORMAL_SOURCE_FORMATS: | ||
249 | 650 | format_native = False | ||
250 | 651 | else: | ||
251 | 652 | format_native = None | ||
252 | 653 | |||
253 | 654 | # If the package doesn't have a debian revision then it must be native. | ||
254 | 655 | if version is not None: | ||
255 | 656 | version_native = (not version.debian_revision) | ||
256 | 657 | else: | ||
257 | 658 | version_native = None | ||
258 | 659 | |||
259 | 660 | if type(version_native) is bool and type(format_native) is bool: | ||
260 | 661 | if version_native != format_native: | ||
261 | 662 | raise InconsistentSourceFormatError(version_native, format_native) | ||
262 | 663 | |||
263 | 664 | if version_native or format_native: | ||
264 | 665 | return BUILD_TYPE_NATIVE | ||
265 | 666 | if not contains_upstream_source: | ||
266 | 667 | # Default to merge mode if there's only a debian/ directory | ||
267 | 668 | return BUILD_TYPE_MERGE | ||
268 | 669 | else: | ||
269 | 670 | return BUILD_TYPE_NORMAL |
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.