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
=== modified file 'cmds.py'
--- cmds.py 2011-01-11 00:29:56 +0000
+++ cmds.py 2011-01-11 00:29:56 +0000
@@ -104,6 +104,7 @@
104 find_last_distribution,104 find_last_distribution,
105 find_previous_upload,105 find_previous_upload,
106 get_export_upstream_revision,106 get_export_upstream_revision,
107 guess_build_type,
107 lookup_distribution,108 lookup_distribution,
108 open_file,109 open_file,
109 open_file_via_transport,110 open_file_via_transport,
@@ -135,7 +136,6 @@
135 help="Select the upstream revision that will be exported.",136 help="Select the upstream revision that will be exported.",
136 type=str)137 type=str)
137138
138
139class cmd_builddeb(Command):139class cmd_builddeb(Command):
140 """Builds a Debian package from a branch.140 """Builds a Debian package from a branch.
141141
@@ -359,14 +359,8 @@
359 except NoPreviousUpload:359 except NoPreviousUpload:
360 prev_version = None360 prev_version = None
361 if build_type is None:361 if build_type is None:
362 if prev_version and not prev_version.debian_revision:362 build_type = guess_build_type(tree, changelog.version,
363 # If the package doesn't have a debian revision, assume it's native.363 contains_upstream_source)
364 build_type = BUILD_TYPE_NATIVE
365 elif not contains_upstream_source:
366 # Default to merge mode if there's only a debian/ directory
367 build_type = BUILD_TYPE_MERGE
368 else:
369 build_type = BUILD_TYPE_NORMAL
370364
371 note("Building package in %s mode" % {365 note("Building package in %s mode" % {
372 BUILD_TYPE_NATIVE: "native",366 BUILD_TYPE_NATIVE: "native",
373367
=== modified file 'debian/changelog'
--- debian/changelog 2010-09-10 02:53:47 +0000
+++ debian/changelog 2011-01-11 00:29:56 +0000
@@ -22,8 +22,10 @@
22 if we can't find the tarball.22 if we can't find the tarball.
23 * Determine Bazaar home directory using bzrlib to prevent test23 * Determine Bazaar home directory using bzrlib to prevent test
24 isolation issues. LP: #61412524 isolation issues. LP: #614125
25 * Automatically use debian/source/format if package is native. Closes:
26 #586617
2527
26 -- James Westby <james.westby@ubuntu.com> Wed, 18 Aug 2010 20:12:20 -040028 -- Jelmer Vernooij <jelmer@debian.org> Tue, 11 Jan 2011 00:42:21 +0100
2729
28bzr-builddeb (2.5) unstable; urgency=low30bzr-builddeb (2.5) unstable; urgency=low
2931
3032
=== modified file 'errors.py'
--- errors.py 2010-06-15 11:33:11 +0000
+++ errors.py 2011-01-11 00:29:56 +0000
@@ -203,3 +203,20 @@
203class UnableToFindPreviousUpload(BzrError):203class UnableToFindPreviousUpload(BzrError):
204204
205 _fmt = ("Unable to determine the previous upload for --package-merge.")205 _fmt = ("Unable to determine the previous upload for --package-merge.")
206
207
208class InconsistentSourceFormatError(BzrError):
209
210 _fmt = ("Inconsistency between source format and version: version is "
211 "%(version_bool)snative, format is %(format_bool)snative.")
212
213 def __init__(self, version_native, format_native):
214 if version_native:
215 version_bool = ""
216 else:
217 version_bool = "not "
218 if format_native:
219 format_bool = ""
220 else:
221 format_bool = "not "
222 BzrError.__init__(self, version_bool=version_bool, format_bool=format_bool)
206223
=== modified file 'tests/test_util.py'
--- tests/test_util.py 2010-07-29 18:41:30 +0000
+++ tests/test_util.py 2011-01-11 00:29:56 +0000
@@ -31,9 +31,15 @@
31 # Prior to 0.1.15 the debian module was called debian_bundle31 # Prior to 0.1.15 the debian module was called debian_bundle
32 from debian_bundle.changelog import Changelog, Version32 from debian_bundle.changelog import Changelog, Version
3333
34from bzrlib.plugins.builddeb.config import DebBuildConfig34from bzrlib.plugins.builddeb.config import (
35 DebBuildConfig,
36 BUILD_TYPE_MERGE,
37 BUILD_TYPE_NATIVE,
38 BUILD_TYPE_NORMAL,
39 )
35from bzrlib.plugins.builddeb.errors import (MissingChangelogError,40from bzrlib.plugins.builddeb.errors import (MissingChangelogError,
36 AddChangelogError,41 AddChangelogError,
42 InconsistentSourceFormatError,
37 NoPreviousUpload,43 NoPreviousUpload,
38 UnknownDistribution,44 UnknownDistribution,
39 )45 )
@@ -50,6 +56,8 @@
50 get_export_upstream_revision,56 get_export_upstream_revision,
51 get_commit_info_from_changelog,57 get_commit_info_from_changelog,
52 get_snapshot_revision,58 get_snapshot_revision,
59 get_source_format,
60 guess_build_type,
53 lookup_distribution,61 lookup_distribution,
54 move_file_if_different,62 move_file_if_different,
55 get_parent_dir,63 get_parent_dir,
@@ -772,3 +780,85 @@
772 self.assertRaises(NoPreviousUpload, _find_previous_upload, cl)780 self.assertRaises(NoPreviousUpload, _find_previous_upload, cl)
773 cl = self.make_changelog([("0.1-1", "unstable")])781 cl = self.make_changelog([("0.1-1", "unstable")])
774 self.assertRaises(NoPreviousUpload, _find_previous_upload, cl)782 self.assertRaises(NoPreviousUpload, _find_previous_upload, cl)
783
784
785class SourceFormatTests(TestCaseWithTransport):
786
787 def test_no_source_format_file(self):
788 tree = self.make_branch_and_tree('.')
789 self.assertEquals("1.0", get_source_format(tree))
790
791 def test_source_format_newline(self):
792 tree = self.make_branch_and_tree('.')
793 self.build_tree_contents([("debian/", ), ("debian/source/",),
794 ("debian/source/format", "3.0 (native)\n")])
795 tree.add(["debian", "debian/source", "debian/source/format"])
796 self.assertEquals("3.0 (native)", get_source_format(tree))
797
798 def test_source_format(self):
799 tree = self.make_branch_and_tree('.')
800 self.build_tree_contents([("debian/",), ("debian/source/",),
801 ("debian/source/format", "3.0 (quilt)")])
802 tree.add(["debian", "debian/source", "debian/source/format"])
803 self.assertEquals("3.0 (quilt)", get_source_format(tree))
804
805
806class GuessBuildTypeTests(TestCaseWithTransport):
807 """Tests for guess_build_type."""
808
809 def writeVersionFile(self, tree, format_string):
810 """Write a Debian source format file.
811
812 :param tree: Tree to write to.
813 :param format_string: Format string to write.
814 """
815 self.build_tree_contents([("debian/",), ("debian/source/",),
816 ("debian/source/format", format_string)])
817 tree.add(["debian", "debian/source", "debian/source/format"])
818
819 def test_normal_source_format(self):
820 # Normal source format -> NORMAL
821 tree = self.make_branch_and_tree('.')
822 self.writeVersionFile(tree, "3.0 (quilt)")
823 self.assertEquals(BUILD_TYPE_NORMAL, guess_build_type(tree, None, True))
824
825 def test_normal_source_format_merge(self):
826 # Normal source format without upstream source -> MERGE
827 tree = self.make_branch_and_tree('.')
828 self.writeVersionFile(tree, "3.0 (quilt)")
829 self.assertEquals(BUILD_TYPE_MERGE, guess_build_type(tree, None, False))
830
831 def test_native_source_format(self):
832 # Native source format -> NATIVE
833 tree = self.make_branch_and_tree('.')
834 self.writeVersionFile(tree, "3.0 (native)")
835 self.assertEquals(BUILD_TYPE_NATIVE, guess_build_type(tree, None, True))
836
837 def test_prev_version_native(self):
838 # Native package version -> NATIVE
839 tree = self.make_branch_and_tree('.')
840 self.assertEquals(BUILD_TYPE_NATIVE,
841 guess_build_type(tree, Version("1.0"), True))
842
843 def test_no_upstream_source(self):
844 # No upstream source code and a non-native package -> MERGE
845 tree = self.make_branch_and_tree('.')
846 self.assertEquals(BUILD_TYPE_MERGE,
847 guess_build_type(tree, Version("1.0-1"), False))
848
849 def test_default(self):
850 # Upstream source code and a non-native package -> NORMAL
851 tree = self.make_branch_and_tree('.')
852 self.assertEquals(BUILD_TYPE_NORMAL,
853 guess_build_type(tree, Version("1.0-1"), True))
854
855 def test_inconsistent(self):
856 # If version string and source format disagree on whether the package is native,
857 # raise an exception.
858 tree = self.make_branch_and_tree('.')
859 self.writeVersionFile(tree, "3.0 (native)")
860 e = self.assertRaises(InconsistentSourceFormatError, guess_build_type, tree,
861 Version("1.0-1"), True)
862 self.assertEquals(
863 "Inconsistency between source format and version: version is not native, "
864 "format is native.", str(e))
775865
=== modified file 'util.py'
--- util.py 2011-01-11 00:29:56 +0000
+++ util.py 2011-01-11 00:29:56 +0000
@@ -55,10 +55,16 @@
55 local_conf,55 local_conf,
56 global_conf,56 global_conf,
57 )57 )
58from bzrlib.plugins.builddeb.config import DebBuildConfig58from bzrlib.plugins.builddeb.config import (
59 DebBuildConfig,
60 BUILD_TYPE_MERGE,
61 BUILD_TYPE_NATIVE,
62 BUILD_TYPE_NORMAL,
63 )
59from bzrlib.plugins.builddeb.errors import (64from bzrlib.plugins.builddeb.errors import (
60 MissingChangelogError,65 MissingChangelogError,
61 AddChangelogError,66 AddChangelogError,
67 InconsistentSourceFormatError,
62 NoPreviousUpload,68 NoPreviousUpload,
63 UnableToFindPreviousUpload,69 UnableToFindPreviousUpload,
64 UnknownDistribution,70 UnknownDistribution,
@@ -612,3 +618,53 @@
612 present_files = set(root.children.keys())618 present_files = set(root.children.keys())
613 packaging_files = frozenset(["debian", ".bzr-builddeb"])619 packaging_files = frozenset(["debian", ".bzr-builddeb"])
614 return (len(present_files - packaging_files) > 0)620 return (len(present_files - packaging_files) > 0)
621
622
623def get_source_format(tree):
624 """Retrieve the source format name from a package.
625
626 :param path: Path to the package
627 :return: String with package format
628 """
629 if not tree.has_filename("debian/source/format"):
630 return "1.0"
631 return tree.get_file_text(tree.path2id("debian/source/format")).strip()
632
633
634NATIVE_SOURCE_FORMATS = ["3.0 (native)"]
635NORMAL_SOURCE_FORMATS = ["3.0 (quilt)"]
636
637
638def guess_build_type(tree, version, contains_upstream_source):
639 """Guess the build type based on the contents of a tree.
640
641 :param tree: A `Tree` object.
642 :param version: `Version` of the upload.
643 :param contains_upstream_source: Whether this branch contains the upstream source.
644 :return: A build_type value.
645 """
646 source_format = get_source_format(tree)
647 if source_format in NATIVE_SOURCE_FORMATS:
648 format_native = True
649 elif source_format in NORMAL_SOURCE_FORMATS:
650 format_native = False
651 else:
652 format_native = None
653
654 # If the package doesn't have a debian revision then it must be native.
655 if version is not None:
656 version_native = (not version.debian_revision)
657 else:
658 version_native = None
659
660 if type(version_native) is bool and type(format_native) is bool:
661 if version_native != format_native:
662 raise InconsistentSourceFormatError(version_native, format_native)
663
664 if version_native or format_native:
665 return BUILD_TYPE_NATIVE
666 if not contains_upstream_source:
667 # Default to merge mode if there's only a debian/ directory
668 return BUILD_TYPE_MERGE
669 else:
670 return BUILD_TYPE_NORMAL

Subscribers

People subscribed via source and target branches