Merge lp:~jelmer/bzr-builddeb/lazy-1 into lp:~bzr-builddeb-hackers/bzr-builddeb/trunk-old
- lazy-1
- Merge into trunk-old
Proposed by
Jelmer Vernooij
Status: | Merged |
---|---|
Merge reported by: | James Westby |
Merged at revision: | not available |
Proposed branch: | lp:~jelmer/bzr-builddeb/lazy-1 |
Merge into: | lp:~bzr-builddeb-hackers/bzr-builddeb/trunk-old |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~jelmer/bzr-builddeb/lazy-1 |
Related bugs: |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote : | # |
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 2008-12-02 16:42:32 +0000 | |||
3 | +++ __init__.py 2009-02-12 14:45:56 +0000 | |||
4 | @@ -24,84 +24,24 @@ | |||
5 | 24 | """bzr-builddeb - manage packages in a Bazaar branch.""" | 24 | """bzr-builddeb - manage packages in a Bazaar branch.""" |
6 | 25 | 25 | ||
7 | 26 | import os | 26 | import os |
19 | 27 | import shutil | 27 | |
20 | 28 | import subprocess | 28 | from bzrlib.commands import plugin_cmds |
10 | 29 | import tempfile | ||
11 | 30 | import urlparse | ||
12 | 31 | |||
13 | 32 | from debian_bundle.changelog import Version | ||
14 | 33 | |||
15 | 34 | from bzrlib import bzrdir | ||
16 | 35 | from bzrlib.branch import Branch | ||
17 | 36 | from bzrlib.commands import Command, register_command | ||
18 | 37 | from bzrlib.config import ConfigObj | ||
21 | 38 | from bzrlib.directory_service import directories | 29 | from bzrlib.directory_service import directories |
22 | 39 | from bzrlib.errors import (BzrCommandError, | ||
23 | 40 | NoSuchFile, | ||
24 | 41 | NoWorkingTree, | ||
25 | 42 | NotBranchError, | ||
26 | 43 | FileExists, | ||
27 | 44 | AlreadyBranchError, | ||
28 | 45 | ) | ||
29 | 46 | from bzrlib.option import Option | ||
30 | 47 | from bzrlib.trace import info, warning | ||
31 | 48 | from bzrlib.transport import get_transport | ||
32 | 49 | from bzrlib import urlutils | ||
33 | 50 | from bzrlib.workingtree import WorkingTree | ||
34 | 51 | 30 | ||
35 | 52 | from bzrlib.plugins.builddeb.builder import (DebBuild, | ||
36 | 53 | DebMergeBuild, | ||
37 | 54 | DebNativeBuild, | ||
38 | 55 | DebSplitBuild, | ||
39 | 56 | DebMergeExportUpstreamBuild, | ||
40 | 57 | DebExportUpstreamBuild, | ||
41 | 58 | ) | ||
42 | 59 | from bzrlib.plugins.builddeb.config import DebBuildConfig | ||
43 | 60 | from bzrlib.plugins.builddeb.errors import (StopBuild, | ||
44 | 61 | ) | ||
45 | 62 | from bzrlib.plugins.builddeb.hooks import run_hook | ||
46 | 63 | from bzrlib.plugins.builddeb.import_dsc import ( | ||
47 | 64 | DistributionBranch, | ||
48 | 65 | DistributionBranchSet, | ||
49 | 66 | DscCache, | ||
50 | 67 | DscComp, | ||
51 | 68 | ) | ||
52 | 69 | from bzrlib.plugins.builddeb.properties import BuildProperties | ||
53 | 70 | from bzrlib.plugins.builddeb import revspec | ||
54 | 71 | from bzrlib.plugins.builddeb.util import (find_changelog, | ||
55 | 72 | lookup_distribution, | ||
56 | 73 | suite_to_distribution, | ||
57 | 74 | tarball_name, | ||
58 | 75 | ) | ||
59 | 76 | from bzrlib.plugins.builddeb.version import version_info | 31 | from bzrlib.plugins.builddeb.version import version_info |
60 | 77 | 32 | ||
61 | 33 | commands = { | ||
62 | 34 | "test_builddeb": [], | ||
63 | 35 | "builddeb": ["bd"], | ||
64 | 36 | "merge_upstream": ["mu"], | ||
65 | 37 | "import_dsc": [], | ||
66 | 38 | "bd_do": [], | ||
67 | 39 | "mark_uploaded": [] | ||
68 | 40 | } | ||
69 | 78 | 41 | ||
96 | 79 | dont_purge_opt = Option('dont-purge', | 42 | for command, aliases in commands.iteritems(): |
97 | 80 | help="Don't purge the build directory after building") | 43 | plugin_cmds.register_lazy('cmd_' + command, aliases, |
98 | 81 | result_opt = Option('result-dir', | 44 | "bzrlib.plugins.builddeb.cmds") |
73 | 82 | help="Directory in which to place the resulting package files", type=str) | ||
74 | 83 | builder_opt = Option('builder', | ||
75 | 84 | help="Command to build the package", type=str) | ||
76 | 85 | merge_opt = Option('merge', | ||
77 | 86 | help='Merge the debian part of the source in to the upstream tarball') | ||
78 | 87 | build_dir_opt = Option('build-dir', | ||
79 | 88 | help="The dir to use for building", type=str) | ||
80 | 89 | orig_dir_opt = Option('orig-dir', | ||
81 | 90 | help="Directory containing the .orig.tar.gz files. For use when only" | ||
82 | 91 | +"debian/ is versioned", type=str) | ||
83 | 92 | native_opt = Option('native', | ||
84 | 93 | help="Build a native package") | ||
85 | 94 | split_opt = Option('split', | ||
86 | 95 | help="Automatically create an .orig.tar.gz from a full source branch") | ||
87 | 96 | export_upstream_opt = Option('export-upstream', | ||
88 | 97 | help="Create the .orig.tar.gz from a bzr branch before building", | ||
89 | 98 | type=unicode) | ||
90 | 99 | export_upstream_revision_opt = Option('export-upstream-revision', | ||
91 | 100 | help="Select the upstream revision that will be exported", | ||
92 | 101 | type=str) | ||
93 | 102 | no_user_conf_opt = Option('no-user-config', | ||
94 | 103 | help="Stop builddeb from reading the user's config file. Used mainly " | ||
95 | 104 | "for tests") | ||
99 | 105 | 45 | ||
100 | 106 | builddeb_dir = '.bzr-builddeb' | 46 | builddeb_dir = '.bzr-builddeb' |
101 | 107 | default_conf = os.path.join(builddeb_dir, 'default.conf') | 47 | default_conf = os.path.join(builddeb_dir, 'default.conf') |
102 | @@ -113,680 +53,17 @@ | |||
103 | 113 | default_result_dir = '..' | 53 | default_result_dir = '..' |
104 | 114 | 54 | ||
105 | 115 | 55 | ||
780 | 116 | def debuild_config(tree, working_tree, no_user_config): | 56 | directories.register_lazy("deb:", 'bzrlib.plugins.builddeb.directory', |
781 | 117 | """Obtain the Debuild configuration object. | 57 | 'VcsDirectory', |
782 | 118 | 58 | "Directory that uses Debian Vcs-* control fields to look up branches") | |
783 | 119 | :param tree: A Tree object, can be a WorkingTree or RevisionTree. | 59 | |
784 | 120 | :param working_tree: Whether the tree is a working tree. | 60 | try: |
785 | 121 | :param no_user_config: Whether to skip the user configuration | 61 | from bzrlib.revisionspec import revspec_registry |
786 | 122 | """ | 62 | revspec_registry.register_lazy("package:", "bzrlib.plugins.builddeb.revspec", "RevisionSpec_package") |
787 | 123 | config_files = [] | 63 | except ImportError: |
788 | 124 | user_config = None | 64 | from bzrlib.revisionspec import SPEC_TYPES |
789 | 125 | if (working_tree and | 65 | from bzrlib.plugins.builddeb.revspec import RevisionSpec_package |
790 | 126 | tree.has_filename(local_conf) and tree.path2id(local_conf) is None): | 66 | SPEC_TYPES.append(RevisionSpec_package) |
117 | 127 | config_files.append((tree.get_file_byname(local_conf), True)) | ||
118 | 128 | if not no_user_config: | ||
119 | 129 | config_files.append((global_conf, True)) | ||
120 | 130 | user_config = global_conf | ||
121 | 131 | if tree.path2id(default_conf): | ||
122 | 132 | config_files.append((tree.get_file(tree.path2id(default_conf)), False)) | ||
123 | 133 | config = DebBuildConfig(config_files) | ||
124 | 134 | config.set_user_config(user_config) | ||
125 | 135 | return config | ||
126 | 136 | |||
127 | 137 | |||
128 | 138 | class cmd_builddeb(Command): | ||
129 | 139 | """Builds a Debian package from a branch. | ||
130 | 140 | |||
131 | 141 | If BRANCH is specified it is assumed that the branch you wish to build is | ||
132 | 142 | located there. If it is not specified then the current directory is used. | ||
133 | 143 | |||
134 | 144 | By default the if a working tree is found it is used to build and otherwise | ||
135 | 145 | the last committed revision was used. To force building the last committed | ||
136 | 146 | revision use --revision -1. You can specify any other revision using the | ||
137 | 147 | --revision option. | ||
138 | 148 | |||
139 | 149 | If you only wish to export the package, and not build it (especially useful | ||
140 | 150 | for merge mode), use --export-only. | ||
141 | 151 | |||
142 | 152 | To leave the build directory when the build is completed use --dont-purge. | ||
143 | 153 | |||
144 | 154 | Specify the command to use when building using the --builder option, | ||
145 | 155 | |||
146 | 156 | You can also specify directories to use for different things. --build-dir | ||
147 | 157 | is the directory to build the packages beneath, which defaults to | ||
148 | 158 | '../build-area'. '--orig-dir' specifies the directory that contains the | ||
149 | 159 | .orig.tar.gz files , which defaults to '..'. '--result-dir' specifies where | ||
150 | 160 | the resulting package files should be placed, which defaults to '..'. | ||
151 | 161 | --result-dir will have problems if you use a build command that places | ||
152 | 162 | the results in a different directory. | ||
153 | 163 | |||
154 | 164 | The --reuse option will be useful if you are in merge mode, and the upstream | ||
155 | 165 | tarball is very large. It attempts to reuse a build directory from an earlier | ||
156 | 166 | build. It will fail if one doesn't exist, but you can create one by using | ||
157 | 167 | --export-only. | ||
158 | 168 | |||
159 | 169 | --quick allows you to define a quick-builder in your configuration files, | ||
160 | 170 | which will be used when this option is passed. It defaults to 'fakeroot | ||
161 | 171 | debian/rules binary'. It is overriden if --builder is passed. Using this | ||
162 | 172 | and --reuse allows for fast rebuilds. | ||
163 | 173 | |||
164 | 174 | --source allows you to build a source package without having to | ||
165 | 175 | specify a builder to do so with --builder. It uses the source-builder | ||
166 | 176 | option from your configuration files, and defaults to 'dpkg-buildpackage | ||
167 | 177 | -rfakeroot -uc -us -S'. It is overriden if either --builder or --quick are | ||
168 | 178 | used. | ||
169 | 179 | |||
170 | 180 | """ | ||
171 | 181 | working_tree_opt = Option('working-tree', help="This option has no effect", | ||
172 | 182 | short_name='w') | ||
173 | 183 | export_only_opt = Option('export-only', help="Export only, don't build", | ||
174 | 184 | short_name='e') | ||
175 | 185 | use_existing_opt = Option('use-existing', | ||
176 | 186 | help="Use an existing build directory") | ||
177 | 187 | ignore_changes_opt = Option('ignore-changes', | ||
178 | 188 | help="This option has no effect") | ||
179 | 189 | ignore_unknowns_opt = Option('ignore-unknowns', | ||
180 | 190 | help="Ignore any unknown files, but still fail if there are any changes" | ||
181 | 191 | +", the default is to fail if there are unknowns as well.") | ||
182 | 192 | quick_opt = Option('quick', help="Quickly build the package, uses " | ||
183 | 193 | +"quick-builder, which defaults to \"fakeroot " | ||
184 | 194 | +"debian/rules binary\"") | ||
185 | 195 | reuse_opt = Option('reuse', help="Try to avoid expoting too much on each " | ||
186 | 196 | +"build. Only works in merge mode; it saves unpacking " | ||
187 | 197 | +"the upstream tarball each time. Implies --dont-purge " | ||
188 | 198 | +"and --use-existing") | ||
189 | 199 | source_opt = Option('source', help="Build a source package, uses " | ||
190 | 200 | +"source-builder, which defaults to \"dpkg-buildpackage " | ||
191 | 201 | +"-rfakeroot -uc -us -S\"", short_name='S') | ||
192 | 202 | result_compat_opt = Option('result', help="Present only for compatibility " | ||
193 | 203 | "with bzr-builddeb <= 2.0. Use --result-dir instead.") | ||
194 | 204 | takes_args = ['branch?'] | ||
195 | 205 | aliases = ['bd'] | ||
196 | 206 | takes_options = [working_tree_opt, export_only_opt, | ||
197 | 207 | dont_purge_opt, use_existing_opt, result_opt, builder_opt, merge_opt, | ||
198 | 208 | build_dir_opt, orig_dir_opt, ignore_changes_opt, ignore_unknowns_opt, | ||
199 | 209 | quick_opt, reuse_opt, native_opt, split_opt, export_upstream_opt, | ||
200 | 210 | export_upstream_revision_opt, source_opt, 'revision', | ||
201 | 211 | no_user_conf_opt, result_compat_opt] | ||
202 | 212 | |||
203 | 213 | def run(self, branch=None, verbose=False, working_tree=False, | ||
204 | 214 | export_only=False, dont_purge=False, use_existing=False, | ||
205 | 215 | result_dir=None, builder=None, merge=False, build_dir=None, | ||
206 | 216 | orig_dir=None, ignore_changes=False, ignore_unknowns=False, | ||
207 | 217 | quick=False, reuse=False, native=False, split=False, | ||
208 | 218 | export_upstream=None, export_upstream_revision=None, | ||
209 | 219 | source=False, revision=None, no_user_config=False, result=None): | ||
210 | 220 | |||
211 | 221 | if branch is None: | ||
212 | 222 | branch = "." | ||
213 | 223 | |||
214 | 224 | # Find out if we were passed a local or remote branch | ||
215 | 225 | is_local = urlparse.urlsplit(branch)[0] in ('', 'file') | ||
216 | 226 | if is_local: | ||
217 | 227 | os.chdir(branch) | ||
218 | 228 | |||
219 | 229 | try: | ||
220 | 230 | tree, _ = WorkingTree.open_containing(branch) | ||
221 | 231 | branch = tree.branch | ||
222 | 232 | except NoWorkingTree: | ||
223 | 233 | tree = None | ||
224 | 234 | branch, _ = Branch.open_containing(branch) | ||
225 | 235 | |||
226 | 236 | if revision is None and tree is not None: | ||
227 | 237 | info("Building using working tree") | ||
228 | 238 | working_tree = True | ||
229 | 239 | else: | ||
230 | 240 | if revision is None: | ||
231 | 241 | revid = branch.last_revision() | ||
232 | 242 | elif len(revision) == 1: | ||
233 | 243 | revid = revision[0].in_history(branch).rev_id | ||
234 | 244 | else: | ||
235 | 245 | raise BzrCommandError('bzr builddeb --revision takes exactly one ' | ||
236 | 246 | 'revision specifier.') | ||
237 | 247 | info("Building branch from revision %s", revid) | ||
238 | 248 | tree = branch.repository.revision_tree(revid) | ||
239 | 249 | working_tree = False | ||
240 | 250 | |||
241 | 251 | tree.lock_read() | ||
242 | 252 | try: | ||
243 | 253 | config = debuild_config(tree, working_tree, no_user_config) | ||
244 | 254 | |||
245 | 255 | if reuse: | ||
246 | 256 | info("Reusing existing build dir") | ||
247 | 257 | dont_purge = True | ||
248 | 258 | use_existing = True | ||
249 | 259 | |||
250 | 260 | if not merge: | ||
251 | 261 | merge = config.merge | ||
252 | 262 | |||
253 | 263 | if merge: | ||
254 | 264 | info("Running in merge mode") | ||
255 | 265 | else: | ||
256 | 266 | if not native: | ||
257 | 267 | native = config.native | ||
258 | 268 | if native: | ||
259 | 269 | info("Running in native mode") | ||
260 | 270 | else: | ||
261 | 271 | if not split: | ||
262 | 272 | split = config.split | ||
263 | 273 | if split: | ||
264 | 274 | info("Running in split mode") | ||
265 | 275 | |||
266 | 276 | if builder is None: | ||
267 | 277 | if quick: | ||
268 | 278 | builder = config.quick_builder | ||
269 | 279 | if builder is None: | ||
270 | 280 | builder = "fakeroot debian/rules binary" | ||
271 | 281 | else: | ||
272 | 282 | if source: | ||
273 | 283 | builder = config.source_builder | ||
274 | 284 | if builder is None: | ||
275 | 285 | builder = "dpkg-buildpackage -rfakeroot -uc -us -S" | ||
276 | 286 | else: | ||
277 | 287 | builder = config.builder | ||
278 | 288 | if builder is None: | ||
279 | 289 | builder = "dpkg-buildpackage -uc -us -rfakeroot" | ||
280 | 290 | |||
281 | 291 | (changelog, larstiq) = find_changelog(tree, merge) | ||
282 | 292 | |||
283 | 293 | config.set_version(changelog.version) | ||
284 | 294 | |||
285 | 295 | if export_upstream is None: | ||
286 | 296 | export_upstream = config.export_upstream | ||
287 | 297 | |||
288 | 298 | if export_upstream_revision is None: | ||
289 | 299 | export_upstream_revision = config.export_upstream_revision | ||
290 | 300 | |||
291 | 301 | if result_dir is None: | ||
292 | 302 | result_dir = result | ||
293 | 303 | |||
294 | 304 | if result_dir is None: | ||
295 | 305 | if is_local: | ||
296 | 306 | result_dir = config.result_dir | ||
297 | 307 | else: | ||
298 | 308 | result_dir = config.user_result_dir | ||
299 | 309 | if result_dir is not None: | ||
300 | 310 | result_dir = os.path.realpath(result_dir) | ||
301 | 311 | |||
302 | 312 | if build_dir is None: | ||
303 | 313 | if is_local: | ||
304 | 314 | build_dir = config.build_dir or default_build_dir | ||
305 | 315 | else: | ||
306 | 316 | build_dir = config.user_build_dir or 'build-area' | ||
307 | 317 | |||
308 | 318 | if orig_dir is None: | ||
309 | 319 | if is_local: | ||
310 | 320 | orig_dir = config.orig_dir or default_orig_dir | ||
311 | 321 | else: | ||
312 | 322 | orig_dir = config.user_orig_dir or 'build-area' | ||
313 | 323 | |||
314 | 324 | properties = BuildProperties(changelog, build_dir, orig_dir, larstiq) | ||
315 | 325 | |||
316 | 326 | if merge: | ||
317 | 327 | if export_upstream is None: | ||
318 | 328 | build = DebMergeBuild(properties, tree, _is_working_tree=working_tree) | ||
319 | 329 | else: | ||
320 | 330 | prepull_upstream = config.prepull_upstream | ||
321 | 331 | stop_on_no_change = config.prepull_upstream_stop | ||
322 | 332 | build = DebMergeExportUpstreamBuild(properties, tree, export_upstream, | ||
323 | 333 | export_upstream_revision, | ||
324 | 334 | prepull_upstream, | ||
325 | 335 | stop_on_no_change, | ||
326 | 336 | _is_working_tree=working_tree) | ||
327 | 337 | elif native: | ||
328 | 338 | build = DebNativeBuild(properties, tree, _is_working_tree=working_tree) | ||
329 | 339 | elif split: | ||
330 | 340 | build = DebSplitBuild(properties, tree, _is_working_tree=working_tree) | ||
331 | 341 | else: | ||
332 | 342 | if export_upstream is None: | ||
333 | 343 | build = DebBuild(properties, tree, _is_working_tree=working_tree) | ||
334 | 344 | else: | ||
335 | 345 | prepull_upstream = config.prepull_upstream | ||
336 | 346 | stop_on_no_change = config.prepull_upstream_stop | ||
337 | 347 | build = DebExportUpstreamBuild(properties, tree, export_upstream, | ||
338 | 348 | export_upstream_revision, | ||
339 | 349 | prepull_upstream, | ||
340 | 350 | stop_on_no_change, | ||
341 | 351 | _is_working_tree=working_tree) | ||
342 | 352 | |||
343 | 353 | build.prepare(use_existing) | ||
344 | 354 | |||
345 | 355 | run_hook(tree, 'pre-export', config) | ||
346 | 356 | |||
347 | 357 | try: | ||
348 | 358 | build.export(use_existing) | ||
349 | 359 | except StopBuild, e: | ||
350 | 360 | warning('Stopping the build: %s.', e.reason) | ||
351 | 361 | return | ||
352 | 362 | |||
353 | 363 | if not export_only: | ||
354 | 364 | run_hook(tree, 'pre-build', config, wd=properties.source_dir()) | ||
355 | 365 | build.build(builder) | ||
356 | 366 | run_hook(tree, 'post-build', config, wd=properties.source_dir()) | ||
357 | 367 | if not dont_purge: | ||
358 | 368 | build.clean() | ||
359 | 369 | arch = None | ||
360 | 370 | if source: | ||
361 | 371 | arch = "source" | ||
362 | 372 | if result_dir is not None: | ||
363 | 373 | build.move_result(result_dir, arch=arch) | ||
364 | 374 | else: | ||
365 | 375 | build.move_result(default_result_dir, allow_missing=True, arch=arch) | ||
366 | 376 | finally: | ||
367 | 377 | tree.unlock() | ||
368 | 378 | |||
369 | 379 | |||
370 | 380 | register_command(cmd_builddeb) | ||
371 | 381 | |||
372 | 382 | |||
373 | 383 | class cmd_merge_upstream(Command): | ||
374 | 384 | """Merges a new upstream version into the current branch. | ||
375 | 385 | |||
376 | 386 | Takes a new upstream version and merges it in to your branch, so that your | ||
377 | 387 | packaging changes are applied to the new version. | ||
378 | 388 | |||
379 | 389 | You must supply the source to import from, and the version number of the | ||
380 | 390 | new release. The source can be a .tar.gz, .tar, .tar.bz2, .tgz or .zip | ||
381 | 391 | archive, or a directory. The source may also be a remote file. | ||
382 | 392 | |||
383 | 393 | You must supply the version number of the new upstream release | ||
384 | 394 | using --version, and the target distribution using --distribution. | ||
385 | 395 | The target distribtution is the distribution that you aim to upload to, | ||
386 | 396 | one of "debian" or "ubuntu". You can also specify the target used in | ||
387 | 397 | the changelog, e.g. "unstable", and it will be resolved automatically. | ||
388 | 398 | |||
389 | 399 | If there is no debian changelog in the branch to retrieve the package | ||
390 | 400 | name from then you must pass the --package option. If this version | ||
391 | 401 | will change the name of the source package then you can use this option | ||
392 | 402 | to set the new name. | ||
393 | 403 | """ | ||
394 | 404 | takes_args = ['location?'] | ||
395 | 405 | aliases = ['mu'] | ||
396 | 406 | |||
397 | 407 | package_opt = Option('package', help="The name of the source package.", | ||
398 | 408 | type=str) | ||
399 | 409 | version_opt = Option('version', help="The version number of this release.", | ||
400 | 410 | type=str) | ||
401 | 411 | distribution_opt = Option('distribution', help="The distribution that " | ||
402 | 412 | "this release is targetted at", type=str) | ||
403 | 413 | directory_opt = Option('directory', help='Working tree into which to merge.', | ||
404 | 414 | short_name='d', type=unicode) | ||
405 | 415 | |||
406 | 416 | takes_options = [package_opt, no_user_conf_opt, version_opt, | ||
407 | 417 | distribution_opt, directory_opt, 'revision'] | ||
408 | 418 | |||
409 | 419 | def run(self, location=None, version=None, distribution=None, package=None, | ||
410 | 420 | no_user_config=None, directory=".", revision=None): | ||
411 | 421 | from bzrlib.plugins.builddeb.errors import MissingChangelogError | ||
412 | 422 | from bzrlib.plugins.builddeb.repack_tarball import repack_tarball | ||
413 | 423 | from bzrlib.plugins.builddeb.merge_upstream import merge_upstream_branch | ||
414 | 424 | tree, _ = WorkingTree.open_containing(directory) | ||
415 | 425 | tree.lock_write() | ||
416 | 426 | try: | ||
417 | 427 | # Check for uncommitted changes. | ||
418 | 428 | if tree.changes_from(tree.basis_tree()).has_changed(): | ||
419 | 429 | raise BzrCommandError("There are uncommitted changes in the " | ||
420 | 430 | "working tree. You must commit before using this " | ||
421 | 431 | "command.") | ||
422 | 432 | config = debuild_config(tree, tree, no_user_config) | ||
423 | 433 | if config.merge: | ||
424 | 434 | raise BzrCommandError("Merge upstream in merge mode is not " | ||
425 | 435 | "yet supported.") | ||
426 | 436 | if config.native: | ||
427 | 437 | raise BzrCommandError("Merge upstream in native mode is not " | ||
428 | 438 | "yet supported.") | ||
429 | 439 | if config.export_upstream and location is None: | ||
430 | 440 | location = config.export_upstream | ||
431 | 441 | if config.split: | ||
432 | 442 | raise BzrCommandError("Split mode is not yet supported.") | ||
433 | 443 | |||
434 | 444 | if location is None: | ||
435 | 445 | raise BzrCommandError("No location specified to merge") | ||
436 | 446 | try: | ||
437 | 447 | changelog = find_changelog(tree, False)[0] | ||
438 | 448 | current_version = changelog.version | ||
439 | 449 | if package is None: | ||
440 | 450 | package = changelog.package | ||
441 | 451 | except MissingChangelogError: | ||
442 | 452 | current_version = None | ||
443 | 453 | |||
444 | 454 | if package is None: | ||
445 | 455 | raise BzrCommandError("You did not specify --package, and " | ||
446 | 456 | "there is no changelog from which to determine the " | ||
447 | 457 | "package name, which is needed to know the name to " | ||
448 | 458 | "give the .orig.tar.gz. Please specify --package.") | ||
449 | 459 | |||
450 | 460 | try: | ||
451 | 461 | upstream_branch = Branch.open(location) | ||
452 | 462 | except NotBranchError: | ||
453 | 463 | upstream_branch = None | ||
454 | 464 | |||
455 | 465 | if upstream_branch is None: | ||
456 | 466 | if version is None: | ||
457 | 467 | raise BzrCommandError("You must specify the version number using " | ||
458 | 468 | "--version.") | ||
459 | 469 | version = Version(version) | ||
460 | 470 | if distribution is None: | ||
461 | 471 | raise BzrCommandError("You must specify the target distribution " | ||
462 | 472 | "using --distribution.") | ||
463 | 473 | if revision is not None: | ||
464 | 474 | raise BzrCommandError("--revision is not allowed when merging a tarball") | ||
465 | 475 | |||
466 | 476 | orig_dir = config.orig_dir or default_orig_dir | ||
467 | 477 | orig_dir = os.path.join(tree.basedir, orig_dir) | ||
468 | 478 | dest_name = tarball_name(package, version.upstream_version) | ||
469 | 479 | try: | ||
470 | 480 | repack_tarball(location, dest_name, target_dir=orig_dir) | ||
471 | 481 | except FileExists: | ||
472 | 482 | raise BzrCommandError("The target file %s already exists, and is either " | ||
473 | 483 | "different to the new upstream tarball, or they " | ||
474 | 484 | "are of different formats. Either delete the target " | ||
475 | 485 | "file, or use it as the argument to import.") | ||
476 | 486 | tarball_filename = os.path.join(orig_dir, dest_name) | ||
477 | 487 | distribution = distribution.lower() | ||
478 | 488 | distribution_name = lookup_distribution(distribution) | ||
479 | 489 | if distribution_name is None: | ||
480 | 490 | raise BzrCommandError("Unknown target distribution: %s" \ | ||
481 | 491 | % distribution) | ||
482 | 492 | db = DistributionBranch(distribution_name, tree.branch, None, | ||
483 | 493 | tree=tree) | ||
484 | 494 | dbs = DistributionBranchSet() | ||
485 | 495 | dbs.add_branch(db) | ||
486 | 496 | conflicts = db.merge_upstream(tarball_filename, version, | ||
487 | 497 | current_version) | ||
488 | 498 | else: | ||
489 | 499 | if revision is not None: | ||
490 | 500 | if len(revision) > 1: | ||
491 | 501 | raise BzrCommandError("merge-upstream takes only a single --revision") | ||
492 | 502 | upstream_revspec = revision[0] | ||
493 | 503 | else: | ||
494 | 504 | upstream_revspec = None | ||
495 | 505 | version = merge_upstream_branch(tree, upstream_branch, package, | ||
496 | 506 | upstream_revspec, version) | ||
497 | 507 | info("Using version string %s for upstream branch." % (version)) | ||
498 | 508 | finally: | ||
499 | 509 | tree.unlock() | ||
500 | 510 | |||
501 | 511 | if "~bzr" in str(version) or "+bzr" in str(version): | ||
502 | 512 | entry_description = "New upstream snapshot." | ||
503 | 513 | else: | ||
504 | 514 | entry_description = "New upstream release." | ||
505 | 515 | |||
506 | 516 | info("The new upstream version has been imported. You should " | ||
507 | 517 | "now update the changelog (try dch -v %s-1 \"%s\"), resolve any " | ||
508 | 518 | "conflicts, and then commit." % (str(version), entry_description)) | ||
509 | 519 | |||
510 | 520 | |||
511 | 521 | register_command(cmd_merge_upstream) | ||
512 | 522 | |||
513 | 523 | |||
514 | 524 | class cmd_import_dsc(Command): | ||
515 | 525 | """Import a series of source packages. | ||
516 | 526 | |||
517 | 527 | Provide a number of source packages (.dsc files), and they will | ||
518 | 528 | be imported to create a branch with history that reflects those | ||
519 | 529 | packages. | ||
520 | 530 | |||
521 | 531 | The first argument is the distribution that these source packages | ||
522 | 532 | were uploaded to, one of "debian" or "ubuntu". It can also | ||
523 | 533 | be the target distribution from the changelog, e.g. "unstable", | ||
524 | 534 | which will be resolved to the correct distribution. | ||
525 | 535 | |||
526 | 536 | You can also specify a file (possibly remote) that contains a | ||
527 | 537 | list of source packages (.dsc files) to import using the --file | ||
528 | 538 | option. Each line is taken to be a URI or path to import. The | ||
529 | 539 | sources specified in the file are used in addition to those | ||
530 | 540 | specified on the command line. | ||
531 | 541 | |||
532 | 542 | If you have an existing branch containing packaging and you want to | ||
533 | 543 | import a .dsc from an upload done from outside the version control | ||
534 | 544 | system you can use this command. | ||
535 | 545 | """ | ||
536 | 546 | |||
537 | 547 | takes_args = ['files*'] | ||
538 | 548 | |||
539 | 549 | filename_opt = Option('file', help="File containing URIs of source " | ||
540 | 550 | "packages to import.", type=str, argname="filename", | ||
541 | 551 | short_name='F') | ||
542 | 552 | distribution_opt = Option('distribution', help="The distribution that " | ||
543 | 553 | "these packages were uploaded to.", type=str) | ||
544 | 554 | |||
545 | 555 | takes_options = [filename_opt, distribution_opt] | ||
546 | 556 | |||
547 | 557 | def import_many(self, db, files_list, orig_target): | ||
548 | 558 | cache = DscCache() | ||
549 | 559 | files_list.sort(cmp=DscComp(cache).cmp) | ||
550 | 560 | if not os.path.exists(orig_target): | ||
551 | 561 | os.makedirs(orig_target) | ||
552 | 562 | for dscname in files_list: | ||
553 | 563 | dsc = cache.get_dsc(dscname) | ||
554 | 564 | def get_dsc_part(from_transport, filename): | ||
555 | 565 | from_f = from_transport.get(filename) | ||
556 | 566 | contents = from_f.read() | ||
557 | 567 | to_f = open(os.path.join(orig_target, filename), 'wb') | ||
558 | 568 | try: | ||
559 | 569 | to_f.write(contents) | ||
560 | 570 | finally: | ||
561 | 571 | to_f.close() | ||
562 | 572 | base, filename = urlutils.split(dscname) | ||
563 | 573 | from_transport = cache.get_transport(dscname) | ||
564 | 574 | get_dsc_part(from_transport, filename) | ||
565 | 575 | for file_details in dsc['files']: | ||
566 | 576 | name = file_details['name'] | ||
567 | 577 | get_dsc_part(from_transport, name) | ||
568 | 578 | db.import_package(os.path.join(orig_target, filename)) | ||
569 | 579 | |||
570 | 580 | def run(self, files_list, distribution=None, filename=None): | ||
571 | 581 | from bzrlib.plugins.builddeb.errors import MissingChangelogError | ||
572 | 582 | if distribution is None: | ||
573 | 583 | raise BzrCommandError("You must specify the distribution " | ||
574 | 584 | "these packages were uploaded to using --distribution.") | ||
575 | 585 | distribution = distribution.lower() | ||
576 | 586 | distribution_name = lookup_distribution(distribution) | ||
577 | 587 | if distribution_name is None: | ||
578 | 588 | raise BzrCommandError("Unknown target distribution: %s" \ | ||
579 | 589 | % distribution) | ||
580 | 590 | try: | ||
581 | 591 | tree = WorkingTree.open_containing('.')[0] | ||
582 | 592 | except NotBranchError: | ||
583 | 593 | raise BzrCommandError("There is no tree to import the packages in to") | ||
584 | 594 | tree.lock_write() | ||
585 | 595 | try: | ||
586 | 596 | if tree.changes_from(tree.basis_tree()).has_changed(): | ||
587 | 597 | raise BzrCommandError("There are uncommitted changes in the " | ||
588 | 598 | "working tree. You must commit before using this " | ||
589 | 599 | "command") | ||
590 | 600 | if files_list is None: | ||
591 | 601 | files_list = [] | ||
592 | 602 | if filename is not None: | ||
593 | 603 | if isinstance(filename, unicode): | ||
594 | 604 | filename = filename.encode('utf-8') | ||
595 | 605 | base_dir, path = urlutils.split(filename) | ||
596 | 606 | sources_file = get_transport(base_dir).get(path) | ||
597 | 607 | for line in sources_file: | ||
598 | 608 | line.strip() | ||
599 | 609 | files_list.append(line) | ||
600 | 610 | if len(files_list) < 1: | ||
601 | 611 | raise BzrCommandError("You must give the location of at least one " | ||
602 | 612 | "source package to install, or use the " | ||
603 | 613 | "--file option.") | ||
604 | 614 | config = debuild_config(tree, tree, False) | ||
605 | 615 | orig_dir = config.orig_dir or default_orig_dir | ||
606 | 616 | orig_target = os.path.join(tree.basedir, default_orig_dir) | ||
607 | 617 | db = DistributionBranch(distribution_name, tree.branch, | ||
608 | 618 | None, tree=tree) | ||
609 | 619 | dbs = DistributionBranchSet() | ||
610 | 620 | dbs.add_branch(db) | ||
611 | 621 | try: | ||
612 | 622 | (changelog, larstiq) = find_changelog(tree, False) | ||
613 | 623 | last_version = changelog.version | ||
614 | 624 | except MissingChangelogError: | ||
615 | 625 | last_version = None | ||
616 | 626 | tempdir = tempfile.mkdtemp(dir=os.path.join(tree.basedir, | ||
617 | 627 | '..')) | ||
618 | 628 | try: | ||
619 | 629 | if last_version is not None: | ||
620 | 630 | upstream_tip = db._revid_of_upstream_version_from_branch( | ||
621 | 631 | last_version) | ||
622 | 632 | db._extract_upstream_tree(upstream_tip, tempdir) | ||
623 | 633 | else: | ||
624 | 634 | db._create_empty_upstream_tree(tempdir) | ||
625 | 635 | self.import_many(db, files_list, orig_target) | ||
626 | 636 | finally: | ||
627 | 637 | shutil.rmtree(tempdir) | ||
628 | 638 | finally: | ||
629 | 639 | tree.unlock() | ||
630 | 640 | |||
631 | 641 | register_command(cmd_import_dsc) | ||
632 | 642 | |||
633 | 643 | |||
634 | 644 | class cmd_bd_do(Command): | ||
635 | 645 | """Run a command in an exported package, copying the result back. | ||
636 | 646 | |||
637 | 647 | For a merge mode package the full source is not available, making some | ||
638 | 648 | operations difficult. This command allows you to run any command in an | ||
639 | 649 | exported source directory, copying the resulting debian/ directory back | ||
640 | 650 | to your branch if the command is successful. | ||
641 | 651 | |||
642 | 652 | For instance: | ||
643 | 653 | |||
644 | 654 | bzr bd-do | ||
645 | 655 | |||
646 | 656 | will run a shell in the unpacked source. Any changes you make in the | ||
647 | 657 | ``debian/`` directory (and only those made in that directory) will be copied | ||
648 | 658 | back to the branch. If you exit with a non-zero exit code (e.g. "exit 1"), | ||
649 | 659 | then the changes will not be copied back. | ||
650 | 660 | |||
651 | 661 | You can also specify single commands to be run, e.g. | ||
652 | 662 | |||
653 | 663 | bzr bd-do "dpatch-edit-patch 01-fix-build" | ||
654 | 664 | |||
655 | 665 | Note that only the first argument is used as the command, and so the above | ||
656 | 666 | example had to be quoted. | ||
657 | 667 | """ | ||
658 | 668 | |||
659 | 669 | takes_args = ['command?'] | ||
660 | 670 | |||
661 | 671 | def run(self, command=None): | ||
662 | 672 | t = WorkingTree.open_containing('.')[0] | ||
663 | 673 | config = debuild_config(t, t, False) | ||
664 | 674 | |||
665 | 675 | if not config.merge: | ||
666 | 676 | raise BzrCommandError("This command only works for merge mode " | ||
667 | 677 | "packages. See /usr/share/doc/bzr-builddeb" | ||
668 | 678 | "/user_manual/merge.html for more information.") | ||
669 | 679 | |||
670 | 680 | give_instruction = False | ||
671 | 681 | if command is None: | ||
672 | 682 | try: | ||
673 | 683 | command = os.environ['SHELL'] | ||
674 | 684 | except KeyError: | ||
675 | 685 | command = "/bin/sh" | ||
676 | 686 | give_instruction = True | ||
677 | 687 | (changelog, larstiq) = find_changelog(t, True) | ||
678 | 688 | build_dir = config.build_dir | ||
679 | 689 | if build_dir is None: | ||
680 | 690 | build_dir = default_build_dir | ||
681 | 691 | orig_dir = config.orig_dir | ||
682 | 692 | if orig_dir is None: | ||
683 | 693 | orig_dir = default_orig_dir | ||
684 | 694 | properties = BuildProperties(changelog, build_dir, orig_dir, larstiq) | ||
685 | 695 | export_upstream = config.export_upstream | ||
686 | 696 | export_upstream_revision = config.export_upstream_revision | ||
687 | 697 | |||
688 | 698 | if export_upstream is None: | ||
689 | 699 | build = DebMergeBuild(properties, t, _is_working_tree=True) | ||
690 | 700 | else: | ||
691 | 701 | prepull_upstream = config.prepull_upstream | ||
692 | 702 | stop_on_no_change = config.prepull_upstream_stop | ||
693 | 703 | build = DebMergeExportUpstreamBuild(properties, t, export_upstream, | ||
694 | 704 | export_upstream_revision, | ||
695 | 705 | prepull_upstream, | ||
696 | 706 | stop_on_no_change, | ||
697 | 707 | _is_working_tree=True) | ||
698 | 708 | |||
699 | 709 | build.prepare() | ||
700 | 710 | try: | ||
701 | 711 | build.export() | ||
702 | 712 | except StopBuild, e: | ||
703 | 713 | warning('Stopping the build: %s.', e.reason) | ||
704 | 714 | info('Running "%s" in the exported directory.' % (command)) | ||
705 | 715 | if give_instruction: | ||
706 | 716 | info('If you want to cancel your changes then exit with a non-zero ' | ||
707 | 717 | 'exit code, e.g. run "exit 1".') | ||
708 | 718 | proc = subprocess.Popen(command, shell=True, | ||
709 | 719 | cwd=properties.source_dir()) | ||
710 | 720 | proc.wait() | ||
711 | 721 | if proc.returncode != 0: | ||
712 | 722 | raise BzrCommandError('Not updating the working tree as the command ' | ||
713 | 723 | 'failed.') | ||
714 | 724 | info("Copying debian/ back") | ||
715 | 725 | if larstiq: | ||
716 | 726 | destination = '.' | ||
717 | 727 | else: | ||
718 | 728 | destination = 'debian/' | ||
719 | 729 | source_debian = os.path.join(properties.source_dir(), 'debian') | ||
720 | 730 | for filename in os.listdir(source_debian): | ||
721 | 731 | proc = subprocess.Popen('cp -apf "%s" "%s"' % ( | ||
722 | 732 | os.path.join(source_debian, filename), destination), | ||
723 | 733 | shell=True) | ||
724 | 734 | proc.wait() | ||
725 | 735 | if proc.returncode != 0: | ||
726 | 736 | raise BzrCommandError('Copying back debian/ failed') | ||
727 | 737 | build.clean() | ||
728 | 738 | info('If any files were added or removed you should run "bzr add" or ' | ||
729 | 739 | '"bzr rm" as appropriate.') | ||
730 | 740 | |||
731 | 741 | |||
732 | 742 | register_command(cmd_bd_do) | ||
733 | 743 | |||
734 | 744 | |||
735 | 745 | class cmd_mark_uploaded(Command): | ||
736 | 746 | """Mark that this branch has been uploaded, prior to pushing it. | ||
737 | 747 | |||
738 | 748 | When a package has been uploaded we want to mark the revision | ||
739 | 749 | that it was uploaded in. This command automates doing that | ||
740 | 750 | by marking the current tip revision with the version indicated | ||
741 | 751 | in debian/changelog. | ||
742 | 752 | """ | ||
743 | 753 | force = Option('force', help="Mark the upload even if it is already " | ||
744 | 754 | "marked.") | ||
745 | 755 | |||
746 | 756 | takes_options = [merge_opt, no_user_conf_opt, force] | ||
747 | 757 | |||
748 | 758 | def run(self, merge=False, no_user_config=False, force=None): | ||
749 | 759 | t = WorkingTree.open_containing('.')[0] | ||
750 | 760 | t.lock_write() | ||
751 | 761 | try: | ||
752 | 762 | if t.changes_from(t.basis_tree()).has_changed(): | ||
753 | 763 | raise BzrCommandError("There are uncommitted changes in the " | ||
754 | 764 | "working tree. You must commit before using this " | ||
755 | 765 | "command") | ||
756 | 766 | config = debuild_config(t, t, no_user_config) | ||
757 | 767 | if not merge: | ||
758 | 768 | merge = config.merge | ||
759 | 769 | (changelog, larstiq) = find_changelog(t, merge) | ||
760 | 770 | distributions = changelog.distributions.strip() | ||
761 | 771 | target_dist = distributions.split()[0] | ||
762 | 772 | distribution_name = suite_to_distribution(target_dist) | ||
763 | 773 | if distribution_name is None: | ||
764 | 774 | raise BzrCommandError("Unknown target distribution: %s" \ | ||
765 | 775 | % target_dist) | ||
766 | 776 | db = DistributionBranch(distribution_name, t.branch, None) | ||
767 | 777 | dbs = DistributionBranchSet() | ||
768 | 778 | dbs.add_branch(db) | ||
769 | 779 | if db.has_version(changelog.version): | ||
770 | 780 | if not force: | ||
771 | 781 | raise BzrCommandError("This version has already been " | ||
772 | 782 | "marked uploaded. Use --force to force marking " | ||
773 | 783 | "this new version.") | ||
774 | 784 | db.tag_version(changelog.version) | ||
775 | 785 | finally: | ||
776 | 786 | t.unlock() | ||
777 | 787 | |||
778 | 788 | |||
779 | 789 | register_command(cmd_mark_uploaded) | ||
791 | 790 | 67 | ||
792 | 791 | 68 | ||
793 | 792 | def test_suite(): | 69 | def test_suite(): |
794 | @@ -797,30 +74,9 @@ | |||
795 | 797 | return result | 74 | return result |
796 | 798 | 75 | ||
797 | 799 | 76 | ||
798 | 800 | class cmd_test_builddeb(Command): | ||
799 | 801 | """Run the builddeb test suite""" | ||
800 | 802 | |||
801 | 803 | hidden = True | ||
802 | 804 | |||
803 | 805 | def run(self): | ||
804 | 806 | from bzrlib.tests import selftest | ||
805 | 807 | passed = selftest(test_suite_factory=test_suite) | ||
806 | 808 | # invert for shell exit code rules | ||
807 | 809 | return not passed | ||
808 | 810 | |||
809 | 811 | |||
810 | 812 | register_command(cmd_test_builddeb) | ||
811 | 813 | |||
812 | 814 | directories.register_lazy("deb:", 'bzrlib.plugins.builddeb.directory', | ||
813 | 815 | 'VcsDirectory', | ||
814 | 816 | "Directory that uses Debian Vcs-* control fields to look up branches") | ||
815 | 817 | |||
816 | 818 | if __name__ == '__main__': | 77 | if __name__ == '__main__': |
817 | 819 | print ("This is a Bazaar plugin. Copy this directory to ~/.bazaar/plugins " | 78 | print ("This is a Bazaar plugin. Copy this directory to ~/.bazaar/plugins " |
818 | 820 | "to use it.\n") | 79 | "to use it.\n") |
819 | 821 | import unittest | 80 | import unittest |
820 | 822 | runner = unittest.TextTestRunner() | 81 | runner = unittest.TextTestRunner() |
821 | 823 | runner.run(test_suite()) | 82 | runner.run(test_suite()) |
822 | 824 | else: | ||
823 | 825 | import sys | ||
824 | 826 | sys.path.append(os.path.dirname(os.path.abspath(__file__))) | ||
825 | 827 | 83 | ||
826 | === added file 'cmds.py' | |||
827 | --- cmds.py 1970-01-01 00:00:00 +0000 | |||
828 | +++ cmds.py 2009-02-12 14:45:56 +0000 | |||
829 | @@ -0,0 +1,788 @@ | |||
830 | 1 | # __init__.py -- The plugin for bzr | ||
831 | 2 | # Copyright (C) 2005 Jamie Wilkinson <jaq@debian.org> | ||
832 | 3 | # 2006, 2007 James Westby <jw+debian@jameswestby.net> | ||
833 | 4 | # 2007 Reinhard Tartler <siretart@tauware.de> | ||
834 | 5 | # 2008 Canonical Ltd. | ||
835 | 6 | # | ||
836 | 7 | # This file is part of bzr-builddeb. | ||
837 | 8 | # | ||
838 | 9 | # bzr-builddeb is free software; you can redistribute it and/or modify | ||
839 | 10 | # it under the terms of the GNU General Public License as published by | ||
840 | 11 | # the Free Software Foundation; either version 2 of the License, or | ||
841 | 12 | # (at your option) any later version. | ||
842 | 13 | # | ||
843 | 14 | # bzr-builddeb is distributed in the hope that it will be useful, | ||
844 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
845 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
846 | 17 | # GNU General Public License for more details. | ||
847 | 18 | # | ||
848 | 19 | # You should have received a copy of the GNU General Public License | ||
849 | 20 | # along with bzr-builddeb; if not, write to the Free Software | ||
850 | 21 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
851 | 22 | # | ||
852 | 23 | import os | ||
853 | 24 | import shutil | ||
854 | 25 | import subprocess | ||
855 | 26 | import tempfile | ||
856 | 27 | import urlparse | ||
857 | 28 | |||
858 | 29 | from debian_bundle.changelog import Version | ||
859 | 30 | |||
860 | 31 | from bzrlib import ( | ||
861 | 32 | bzrdir, | ||
862 | 33 | urlutils, | ||
863 | 34 | ) | ||
864 | 35 | from bzrlib.branch import Branch | ||
865 | 36 | from bzrlib.commands import Command | ||
866 | 37 | from bzrlib.errors import (BzrCommandError, | ||
867 | 38 | NoWorkingTree, | ||
868 | 39 | NotBranchError, | ||
869 | 40 | FileExists, | ||
870 | 41 | ) | ||
871 | 42 | from bzrlib.option import Option | ||
872 | 43 | from bzrlib.trace import info, warning | ||
873 | 44 | from bzrlib.transport import get_transport | ||
874 | 45 | from bzrlib.workingtree import WorkingTree | ||
875 | 46 | |||
876 | 47 | from bzrlib.plugins.builddeb import ( | ||
877 | 48 | default_build_dir, | ||
878 | 49 | default_orig_dir, | ||
879 | 50 | default_result_dir, | ||
880 | 51 | default_conf, | ||
881 | 52 | local_conf, | ||
882 | 53 | global_conf, | ||
883 | 54 | test_suite, | ||
884 | 55 | ) | ||
885 | 56 | from bzrlib.plugins.builddeb.builder import ( | ||
886 | 57 | DebBuild, | ||
887 | 58 | DebMergeBuild, | ||
888 | 59 | DebNativeBuild, | ||
889 | 60 | DebSplitBuild, | ||
890 | 61 | DebMergeExportUpstreamBuild, | ||
891 | 62 | DebExportUpstreamBuild, | ||
892 | 63 | ) | ||
893 | 64 | from bzrlib.plugins.builddeb.config import DebBuildConfig | ||
894 | 65 | from bzrlib.plugins.builddeb.errors import (StopBuild, | ||
895 | 66 | ) | ||
896 | 67 | from bzrlib.plugins.builddeb.hooks import run_hook | ||
897 | 68 | from bzrlib.plugins.builddeb.import_dsc import ( | ||
898 | 69 | DistributionBranch, | ||
899 | 70 | DistributionBranchSet, | ||
900 | 71 | DscCache, | ||
901 | 72 | DscComp, | ||
902 | 73 | ) | ||
903 | 74 | from bzrlib.plugins.builddeb.properties import BuildProperties | ||
904 | 75 | from bzrlib.plugins.builddeb.util import (find_changelog, | ||
905 | 76 | lookup_distribution, | ||
906 | 77 | suite_to_distribution, | ||
907 | 78 | tarball_name, | ||
908 | 79 | ) | ||
909 | 80 | |||
910 | 81 | dont_purge_opt = Option('dont-purge', | ||
911 | 82 | help="Don't purge the build directory after building") | ||
912 | 83 | result_opt = Option('result-dir', | ||
913 | 84 | help="Directory in which to place the resulting package files", type=str) | ||
914 | 85 | builder_opt = Option('builder', | ||
915 | 86 | help="Command to build the package", type=str) | ||
916 | 87 | merge_opt = Option('merge', | ||
917 | 88 | help='Merge the debian part of the source in to the upstream tarball') | ||
918 | 89 | build_dir_opt = Option('build-dir', | ||
919 | 90 | help="The dir to use for building", type=str) | ||
920 | 91 | orig_dir_opt = Option('orig-dir', | ||
921 | 92 | help="Directory containing the .orig.tar.gz files. For use when only" | ||
922 | 93 | +"debian/ is versioned", type=str) | ||
923 | 94 | native_opt = Option('native', | ||
924 | 95 | help="Build a native package") | ||
925 | 96 | split_opt = Option('split', | ||
926 | 97 | help="Automatically create an .orig.tar.gz from a full source branch") | ||
927 | 98 | export_upstream_opt = Option('export-upstream', | ||
928 | 99 | help="Create the .orig.tar.gz from a bzr branch before building", | ||
929 | 100 | type=unicode) | ||
930 | 101 | export_upstream_revision_opt = Option('export-upstream-revision', | ||
931 | 102 | help="Select the upstream revision that will be exported", | ||
932 | 103 | type=str) | ||
933 | 104 | no_user_conf_opt = Option('no-user-config', | ||
934 | 105 | help="Stop builddeb from reading the user's config file. Used mainly " | ||
935 | 106 | "for tests") | ||
936 | 107 | |||
937 | 108 | |||
938 | 109 | def debuild_config(tree, working_tree, no_user_config): | ||
939 | 110 | """Obtain the Debuild configuration object. | ||
940 | 111 | |||
941 | 112 | :param tree: A Tree object, can be a WorkingTree or RevisionTree. | ||
942 | 113 | :param working_tree: Whether the tree is a working tree. | ||
943 | 114 | :param no_user_config: Whether to skip the user configuration | ||
944 | 115 | """ | ||
945 | 116 | config_files = [] | ||
946 | 117 | user_config = None | ||
947 | 118 | if (working_tree and | ||
948 | 119 | tree.has_filename(local_conf) and tree.path2id(local_conf) is None): | ||
949 | 120 | config_files.append((tree.get_file_byname(local_conf), True)) | ||
950 | 121 | if not no_user_config: | ||
951 | 122 | config_files.append((global_conf, True)) | ||
952 | 123 | user_config = global_conf | ||
953 | 124 | if tree.path2id(default_conf): | ||
954 | 125 | config_files.append((tree.get_file(tree.path2id(default_conf)), False)) | ||
955 | 126 | config = DebBuildConfig(config_files) | ||
956 | 127 | config.set_user_config(user_config) | ||
957 | 128 | return config | ||
958 | 129 | |||
959 | 130 | |||
960 | 131 | class cmd_builddeb(Command): | ||
961 | 132 | """Builds a Debian package from a branch. | ||
962 | 133 | |||
963 | 134 | If BRANCH is specified it is assumed that the branch you wish to build is | ||
964 | 135 | located there. If it is not specified then the current directory is used. | ||
965 | 136 | |||
966 | 137 | By default the if a working tree is found it is used to build and otherwise | ||
967 | 138 | the last committed revision was used. To force building the last committed | ||
968 | 139 | revision use --revision -1. You can specify any other revision using the | ||
969 | 140 | --revision option. | ||
970 | 141 | |||
971 | 142 | If you only wish to export the package, and not build it (especially useful | ||
972 | 143 | for merge mode), use --export-only. | ||
973 | 144 | |||
974 | 145 | To leave the build directory when the build is completed use --dont-purge. | ||
975 | 146 | |||
976 | 147 | Specify the command to use when building using the --builder option, | ||
977 | 148 | |||
978 | 149 | You can also specify directories to use for different things. --build-dir | ||
979 | 150 | is the directory to build the packages beneath, which defaults to | ||
980 | 151 | '../build-area'. '--orig-dir' specifies the directory that contains the | ||
981 | 152 | .orig.tar.gz files , which defaults to '..'. '--result-dir' specifies where | ||
982 | 153 | the resulting package files should be placed, which defaults to '..'. | ||
983 | 154 | --result-dir will have problems if you use a build command that places | ||
984 | 155 | the results in a different directory. | ||
985 | 156 | |||
986 | 157 | The --reuse option will be useful if you are in merge mode, and the upstream | ||
987 | 158 | tarball is very large. It attempts to reuse a build directory from an earlier | ||
988 | 159 | build. It will fail if one doesn't exist, but you can create one by using | ||
989 | 160 | --export-only. | ||
990 | 161 | |||
991 | 162 | --quick allows you to define a quick-builder in your configuration files, | ||
992 | 163 | which will be used when this option is passed. It defaults to 'fakeroot | ||
993 | 164 | debian/rules binary'. It is overriden if --builder is passed. Using this | ||
994 | 165 | and --reuse allows for fast rebuilds. | ||
995 | 166 | |||
996 | 167 | --source allows you to build a source package without having to | ||
997 | 168 | specify a builder to do so with --builder. It uses the source-builder | ||
998 | 169 | option from your configuration files, and defaults to 'dpkg-buildpackage | ||
999 | 170 | -rfakeroot -uc -us -S'. It is overriden if either --builder or --quick are | ||
1000 | 171 | used. | ||
1001 | 172 | |||
1002 | 173 | """ | ||
1003 | 174 | working_tree_opt = Option('working-tree', help="This option has no effect", | ||
1004 | 175 | short_name='w') | ||
1005 | 176 | export_only_opt = Option('export-only', help="Export only, don't build", | ||
1006 | 177 | short_name='e') | ||
1007 | 178 | use_existing_opt = Option('use-existing', | ||
1008 | 179 | help="Use an existing build directory") | ||
1009 | 180 | ignore_changes_opt = Option('ignore-changes', | ||
1010 | 181 | help="This option has no effect") | ||
1011 | 182 | ignore_unknowns_opt = Option('ignore-unknowns', | ||
1012 | 183 | help="Ignore any unknown files, but still fail if there are any changes" | ||
1013 | 184 | +", the default is to fail if there are unknowns as well.") | ||
1014 | 185 | quick_opt = Option('quick', help="Quickly build the package, uses " | ||
1015 | 186 | +"quick-builder, which defaults to \"fakeroot " | ||
1016 | 187 | +"debian/rules binary\"") | ||
1017 | 188 | reuse_opt = Option('reuse', help="Try to avoid expoting too much on each " | ||
1018 | 189 | +"build. Only works in merge mode; it saves unpacking " | ||
1019 | 190 | +"the upstream tarball each time. Implies --dont-purge " | ||
1020 | 191 | +"and --use-existing") | ||
1021 | 192 | source_opt = Option('source', help="Build a source package, uses " | ||
1022 | 193 | +"source-builder, which defaults to \"dpkg-buildpackage " | ||
1023 | 194 | +"-rfakeroot -uc -us -S\"", short_name='S') | ||
1024 | 195 | result_compat_opt = Option('result', help="Present only for compatibility " | ||
1025 | 196 | "with bzr-builddeb <= 2.0. Use --result-dir instead.") | ||
1026 | 197 | takes_args = ['branch?'] | ||
1027 | 198 | aliases = ['bd'] | ||
1028 | 199 | takes_options = [working_tree_opt, export_only_opt, | ||
1029 | 200 | dont_purge_opt, use_existing_opt, result_opt, builder_opt, merge_opt, | ||
1030 | 201 | build_dir_opt, orig_dir_opt, ignore_changes_opt, ignore_unknowns_opt, | ||
1031 | 202 | quick_opt, reuse_opt, native_opt, split_opt, export_upstream_opt, | ||
1032 | 203 | export_upstream_revision_opt, source_opt, 'revision', | ||
1033 | 204 | no_user_conf_opt, result_compat_opt] | ||
1034 | 205 | |||
1035 | 206 | def run(self, branch=None, verbose=False, working_tree=False, | ||
1036 | 207 | export_only=False, dont_purge=False, use_existing=False, | ||
1037 | 208 | result_dir=None, builder=None, merge=False, build_dir=None, | ||
1038 | 209 | orig_dir=None, ignore_changes=False, ignore_unknowns=False, | ||
1039 | 210 | quick=False, reuse=False, native=False, split=False, | ||
1040 | 211 | export_upstream=None, export_upstream_revision=None, | ||
1041 | 212 | source=False, revision=None, no_user_config=False, result=None): | ||
1042 | 213 | |||
1043 | 214 | if branch is None: | ||
1044 | 215 | branch = "." | ||
1045 | 216 | |||
1046 | 217 | # Find out if we were passed a local or remote branch | ||
1047 | 218 | is_local = urlparse.urlsplit(branch)[0] in ('', 'file') | ||
1048 | 219 | if is_local: | ||
1049 | 220 | os.chdir(branch) | ||
1050 | 221 | |||
1051 | 222 | try: | ||
1052 | 223 | tree, _ = WorkingTree.open_containing(branch) | ||
1053 | 224 | branch = tree.branch | ||
1054 | 225 | except NoWorkingTree: | ||
1055 | 226 | tree = None | ||
1056 | 227 | branch, _ = Branch.open_containing(branch) | ||
1057 | 228 | |||
1058 | 229 | if revision is None and tree is not None: | ||
1059 | 230 | info("Building using working tree") | ||
1060 | 231 | working_tree = True | ||
1061 | 232 | else: | ||
1062 | 233 | if revision is None: | ||
1063 | 234 | revid = branch.last_revision() | ||
1064 | 235 | elif len(revision) == 1: | ||
1065 | 236 | revid = revision[0].in_history(branch).rev_id | ||
1066 | 237 | else: | ||
1067 | 238 | raise BzrCommandError('bzr builddeb --revision takes exactly one ' | ||
1068 | 239 | 'revision specifier.') | ||
1069 | 240 | info("Building branch from revision %s", revid) | ||
1070 | 241 | tree = branch.repository.revision_tree(revid) | ||
1071 | 242 | working_tree = False | ||
1072 | 243 | |||
1073 | 244 | tree.lock_read() | ||
1074 | 245 | try: | ||
1075 | 246 | config = debuild_config(tree, working_tree, no_user_config) | ||
1076 | 247 | |||
1077 | 248 | if reuse: | ||
1078 | 249 | info("Reusing existing build dir") | ||
1079 | 250 | dont_purge = True | ||
1080 | 251 | use_existing = True | ||
1081 | 252 | |||
1082 | 253 | if not merge: | ||
1083 | 254 | merge = config.merge | ||
1084 | 255 | |||
1085 | 256 | if merge: | ||
1086 | 257 | info("Running in merge mode") | ||
1087 | 258 | else: | ||
1088 | 259 | if not native: | ||
1089 | 260 | native = config.native | ||
1090 | 261 | if native: | ||
1091 | 262 | info("Running in native mode") | ||
1092 | 263 | else: | ||
1093 | 264 | if not split: | ||
1094 | 265 | split = config.split | ||
1095 | 266 | if split: | ||
1096 | 267 | info("Running in split mode") | ||
1097 | 268 | |||
1098 | 269 | if builder is None: | ||
1099 | 270 | if quick: | ||
1100 | 271 | builder = config.quick_builder | ||
1101 | 272 | if builder is None: | ||
1102 | 273 | builder = "fakeroot debian/rules binary" | ||
1103 | 274 | else: | ||
1104 | 275 | if source: | ||
1105 | 276 | builder = config.source_builder | ||
1106 | 277 | if builder is None: | ||
1107 | 278 | builder = "dpkg-buildpackage -rfakeroot -uc -us -S" | ||
1108 | 279 | else: | ||
1109 | 280 | builder = config.builder | ||
1110 | 281 | if builder is None: | ||
1111 | 282 | builder = "dpkg-buildpackage -uc -us -rfakeroot" | ||
1112 | 283 | |||
1113 | 284 | (changelog, larstiq) = find_changelog(tree, merge) | ||
1114 | 285 | |||
1115 | 286 | config.set_version(changelog.version) | ||
1116 | 287 | |||
1117 | 288 | if export_upstream is None: | ||
1118 | 289 | export_upstream = config.export_upstream | ||
1119 | 290 | |||
1120 | 291 | if export_upstream_revision is None: | ||
1121 | 292 | export_upstream_revision = config.export_upstream_revision | ||
1122 | 293 | |||
1123 | 294 | if result_dir is None: | ||
1124 | 295 | result_dir = result | ||
1125 | 296 | |||
1126 | 297 | if result_dir is None: | ||
1127 | 298 | if is_local: | ||
1128 | 299 | result_dir = config.result_dir | ||
1129 | 300 | else: | ||
1130 | 301 | result_dir = config.user_result_dir | ||
1131 | 302 | if result_dir is not None: | ||
1132 | 303 | result_dir = os.path.realpath(result_dir) | ||
1133 | 304 | |||
1134 | 305 | if build_dir is None: | ||
1135 | 306 | if is_local: | ||
1136 | 307 | build_dir = config.build_dir or default_build_dir | ||
1137 | 308 | else: | ||
1138 | 309 | build_dir = config.user_build_dir or 'build-area' | ||
1139 | 310 | |||
1140 | 311 | if orig_dir is None: | ||
1141 | 312 | if is_local: | ||
1142 | 313 | orig_dir = config.orig_dir or default_orig_dir | ||
1143 | 314 | else: | ||
1144 | 315 | orig_dir = config.user_orig_dir or 'build-area' | ||
1145 | 316 | |||
1146 | 317 | properties = BuildProperties(changelog, build_dir, orig_dir, larstiq) | ||
1147 | 318 | |||
1148 | 319 | if merge: | ||
1149 | 320 | if export_upstream is None: | ||
1150 | 321 | build = DebMergeBuild(properties, tree, _is_working_tree=working_tree) | ||
1151 | 322 | else: | ||
1152 | 323 | prepull_upstream = config.prepull_upstream | ||
1153 | 324 | stop_on_no_change = config.prepull_upstream_stop | ||
1154 | 325 | build = DebMergeExportUpstreamBuild(properties, tree, export_upstream, | ||
1155 | 326 | export_upstream_revision, | ||
1156 | 327 | prepull_upstream, | ||
1157 | 328 | stop_on_no_change, | ||
1158 | 329 | _is_working_tree=working_tree) | ||
1159 | 330 | elif native: | ||
1160 | 331 | build = DebNativeBuild(properties, tree, _is_working_tree=working_tree) | ||
1161 | 332 | elif split: | ||
1162 | 333 | build = DebSplitBuild(properties, tree, _is_working_tree=working_tree) | ||
1163 | 334 | else: | ||
1164 | 335 | if export_upstream is None: | ||
1165 | 336 | build = DebBuild(properties, tree, _is_working_tree=working_tree) | ||
1166 | 337 | else: | ||
1167 | 338 | prepull_upstream = config.prepull_upstream | ||
1168 | 339 | stop_on_no_change = config.prepull_upstream_stop | ||
1169 | 340 | build = DebExportUpstreamBuild(properties, tree, export_upstream, | ||
1170 | 341 | export_upstream_revision, | ||
1171 | 342 | prepull_upstream, | ||
1172 | 343 | stop_on_no_change, | ||
1173 | 344 | _is_working_tree=working_tree) | ||
1174 | 345 | |||
1175 | 346 | build.prepare(use_existing) | ||
1176 | 347 | |||
1177 | 348 | run_hook(tree, 'pre-export', config) | ||
1178 | 349 | |||
1179 | 350 | try: | ||
1180 | 351 | build.export(use_existing) | ||
1181 | 352 | except StopBuild, e: | ||
1182 | 353 | warning('Stopping the build: %s.', e.reason) | ||
1183 | 354 | return | ||
1184 | 355 | |||
1185 | 356 | if not export_only: | ||
1186 | 357 | run_hook(tree, 'pre-build', config, wd=properties.source_dir()) | ||
1187 | 358 | build.build(builder) | ||
1188 | 359 | run_hook(tree, 'post-build', config, wd=properties.source_dir()) | ||
1189 | 360 | if not dont_purge: | ||
1190 | 361 | build.clean() | ||
1191 | 362 | arch = None | ||
1192 | 363 | if source: | ||
1193 | 364 | arch = "source" | ||
1194 | 365 | if result_dir is not None: | ||
1195 | 366 | build.move_result(result_dir, arch=arch) | ||
1196 | 367 | else: | ||
1197 | 368 | build.move_result(default_result_dir, allow_missing=True, arch=arch) | ||
1198 | 369 | finally: | ||
1199 | 370 | tree.unlock() | ||
1200 | 371 | |||
1201 | 372 | |||
1202 | 373 | |||
1203 | 374 | |||
1204 | 375 | class cmd_merge_upstream(Command): | ||
1205 | 376 | """Merges a new upstream version into the current branch. | ||
1206 | 377 | |||
1207 | 378 | Takes a new upstream version and merges it in to your branch, so that your | ||
1208 | 379 | packaging changes are applied to the new version. | ||
1209 | 380 | |||
1210 | 381 | You must supply the source to import from, and the version number of the | ||
1211 | 382 | new release. The source can be a .tar.gz, .tar, .tar.bz2, .tgz or .zip | ||
1212 | 383 | archive, or a directory. The source may also be a remote file. | ||
1213 | 384 | |||
1214 | 385 | You must supply the version number of the new upstream release | ||
1215 | 386 | using --version, and the target distribution using --distribution. | ||
1216 | 387 | The target distribtution is the distribution that you aim to upload to, | ||
1217 | 388 | one of "debian" or "ubuntu". You can also specify the target used in | ||
1218 | 389 | the changelog, e.g. "unstable", and it will be resolved automatically. | ||
1219 | 390 | |||
1220 | 391 | If there is no debian changelog in the branch to retrieve the package | ||
1221 | 392 | name from then you must pass the --package option. If this version | ||
1222 | 393 | will change the name of the source package then you can use this option | ||
1223 | 394 | to set the new name. | ||
1224 | 395 | """ | ||
1225 | 396 | takes_args = ['location?'] | ||
1226 | 397 | aliases = ['mu'] | ||
1227 | 398 | |||
1228 | 399 | package_opt = Option('package', help="The name of the source package.", | ||
1229 | 400 | type=str) | ||
1230 | 401 | version_opt = Option('version', help="The version number of this release.", | ||
1231 | 402 | type=str) | ||
1232 | 403 | distribution_opt = Option('distribution', help="The distribution that " | ||
1233 | 404 | "this release is targetted at", type=str) | ||
1234 | 405 | directory_opt = Option('directory', help='Working tree into which to merge.', | ||
1235 | 406 | short_name='d', type=unicode) | ||
1236 | 407 | |||
1237 | 408 | takes_options = [package_opt, no_user_conf_opt, version_opt, | ||
1238 | 409 | distribution_opt, directory_opt, 'revision'] | ||
1239 | 410 | |||
1240 | 411 | def run(self, location=None, version=None, distribution=None, package=None, | ||
1241 | 412 | no_user_config=None, directory=".", revision=None): | ||
1242 | 413 | from bzrlib.plugins.builddeb.errors import MissingChangelogError | ||
1243 | 414 | from bzrlib.plugins.builddeb.repack_tarball import repack_tarball | ||
1244 | 415 | from bzrlib.plugins.builddeb.merge_upstream import merge_upstream_branch | ||
1245 | 416 | tree, _ = WorkingTree.open_containing(directory) | ||
1246 | 417 | tree.lock_write() | ||
1247 | 418 | try: | ||
1248 | 419 | # Check for uncommitted changes. | ||
1249 | 420 | if tree.changes_from(tree.basis_tree()).has_changed(): | ||
1250 | 421 | raise BzrCommandError("There are uncommitted changes in the " | ||
1251 | 422 | "working tree. You must commit before using this " | ||
1252 | 423 | "command.") | ||
1253 | 424 | config = debuild_config(tree, tree, no_user_config) | ||
1254 | 425 | if config.merge: | ||
1255 | 426 | raise BzrCommandError("Merge upstream in merge mode is not " | ||
1256 | 427 | "yet supported.") | ||
1257 | 428 | if config.native: | ||
1258 | 429 | raise BzrCommandError("Merge upstream in native mode is not " | ||
1259 | 430 | "yet supported.") | ||
1260 | 431 | if config.export_upstream and location is None: | ||
1261 | 432 | location = config.export_upstream | ||
1262 | 433 | if config.split: | ||
1263 | 434 | raise BzrCommandError("Split mode is not yet supported.") | ||
1264 | 435 | |||
1265 | 436 | if location is None: | ||
1266 | 437 | raise BzrCommandError("No location specified to merge") | ||
1267 | 438 | try: | ||
1268 | 439 | changelog = find_changelog(tree, False)[0] | ||
1269 | 440 | current_version = changelog.version | ||
1270 | 441 | if package is None: | ||
1271 | 442 | package = changelog.package | ||
1272 | 443 | except MissingChangelogError: | ||
1273 | 444 | current_version = None | ||
1274 | 445 | |||
1275 | 446 | if package is None: | ||
1276 | 447 | raise BzrCommandError("You did not specify --package, and " | ||
1277 | 448 | "there is no changelog from which to determine the " | ||
1278 | 449 | "package name, which is needed to know the name to " | ||
1279 | 450 | "give the .orig.tar.gz. Please specify --package.") | ||
1280 | 451 | |||
1281 | 452 | try: | ||
1282 | 453 | upstream_branch = Branch.open(location) | ||
1283 | 454 | except NotBranchError: | ||
1284 | 455 | upstream_branch = None | ||
1285 | 456 | |||
1286 | 457 | if upstream_branch is None: | ||
1287 | 458 | if version is None: | ||
1288 | 459 | raise BzrCommandError("You must specify the version number using " | ||
1289 | 460 | "--version.") | ||
1290 | 461 | version = Version(version) | ||
1291 | 462 | if distribution is None: | ||
1292 | 463 | raise BzrCommandError("You must specify the target distribution " | ||
1293 | 464 | "using --distribution.") | ||
1294 | 465 | if revision is not None: | ||
1295 | 466 | raise BzrCommandError("--revision is not allowed when merging a tarball") | ||
1296 | 467 | |||
1297 | 468 | orig_dir = config.orig_dir or default_orig_dir | ||
1298 | 469 | orig_dir = os.path.join(tree.basedir, orig_dir) | ||
1299 | 470 | dest_name = tarball_name(package, version.upstream_version) | ||
1300 | 471 | try: | ||
1301 | 472 | repack_tarball(location, dest_name, target_dir=orig_dir) | ||
1302 | 473 | except FileExists: | ||
1303 | 474 | raise BzrCommandError("The target file %s already exists, and is either " | ||
1304 | 475 | "different to the new upstream tarball, or they " | ||
1305 | 476 | "are of different formats. Either delete the target " | ||
1306 | 477 | "file, or use it as the argument to import.") | ||
1307 | 478 | tarball_filename = os.path.join(orig_dir, dest_name) | ||
1308 | 479 | distribution = distribution.lower() | ||
1309 | 480 | distribution_name = lookup_distribution(distribution) | ||
1310 | 481 | if distribution_name is None: | ||
1311 | 482 | raise BzrCommandError("Unknown target distribution: %s" \ | ||
1312 | 483 | % distribution) | ||
1313 | 484 | db = DistributionBranch(distribution_name, tree.branch, None, | ||
1314 | 485 | tree=tree) | ||
1315 | 486 | dbs = DistributionBranchSet() | ||
1316 | 487 | dbs.add_branch(db) | ||
1317 | 488 | conflicts = db.merge_upstream(tarball_filename, version, | ||
1318 | 489 | current_version) | ||
1319 | 490 | else: | ||
1320 | 491 | if revision is not None: | ||
1321 | 492 | if len(revision) > 1: | ||
1322 | 493 | raise BzrCommandError("merge-upstream takes only a single --revision") | ||
1323 | 494 | upstream_revspec = revision[0] | ||
1324 | 495 | else: | ||
1325 | 496 | upstream_revspec = None | ||
1326 | 497 | version = merge_upstream_branch(tree, upstream_branch, package, | ||
1327 | 498 | upstream_revspec, version) | ||
1328 | 499 | info("Using version string %s for upstream branch." % (version)) | ||
1329 | 500 | finally: | ||
1330 | 501 | tree.unlock() | ||
1331 | 502 | |||
1332 | 503 | if "~bzr" in str(version) or "+bzr" in str(version): | ||
1333 | 504 | entry_description = "New upstream snapshot." | ||
1334 | 505 | else: | ||
1335 | 506 | entry_description = "New upstream release." | ||
1336 | 507 | |||
1337 | 508 | info("The new upstream version has been imported. You should " | ||
1338 | 509 | "now update the changelog (try dch -v %s-1 \"%s\"), resolve any " | ||
1339 | 510 | "conflicts, and then commit." % (str(version), entry_description)) | ||
1340 | 511 | |||
1341 | 512 | |||
1342 | 513 | |||
1343 | 514 | |||
1344 | 515 | class cmd_import_dsc(Command): | ||
1345 | 516 | """Import a series of source packages. | ||
1346 | 517 | |||
1347 | 518 | Provide a number of source packages (.dsc files), and they will | ||
1348 | 519 | be imported to create a branch with history that reflects those | ||
1349 | 520 | packages. | ||
1350 | 521 | |||
1351 | 522 | The first argument is the distribution that these source packages | ||
1352 | 523 | were uploaded to, one of "debian" or "ubuntu". It can also | ||
1353 | 524 | be the target distribution from the changelog, e.g. "unstable", | ||
1354 | 525 | which will be resolved to the correct distribution. | ||
1355 | 526 | |||
1356 | 527 | You can also specify a file (possibly remote) that contains a | ||
1357 | 528 | list of source packages (.dsc files) to import using the --file | ||
1358 | 529 | option. Each line is taken to be a URI or path to import. The | ||
1359 | 530 | sources specified in the file are used in addition to those | ||
1360 | 531 | specified on the command line. | ||
1361 | 532 | |||
1362 | 533 | If you have an existing branch containing packaging and you want to | ||
1363 | 534 | import a .dsc from an upload done from outside the version control | ||
1364 | 535 | system you can use this command. | ||
1365 | 536 | """ | ||
1366 | 537 | |||
1367 | 538 | takes_args = ['files*'] | ||
1368 | 539 | |||
1369 | 540 | filename_opt = Option('file', help="File containing URIs of source " | ||
1370 | 541 | "packages to import.", type=str, argname="filename", | ||
1371 | 542 | short_name='F') | ||
1372 | 543 | distribution_opt = Option('distribution', help="The distribution that " | ||
1373 | 544 | "these packages were uploaded to.", type=str) | ||
1374 | 545 | |||
1375 | 546 | takes_options = [filename_opt, distribution_opt] | ||
1376 | 547 | |||
1377 | 548 | def import_many(self, db, files_list, orig_target): | ||
1378 | 549 | cache = DscCache() | ||
1379 | 550 | files_list.sort(cmp=DscComp(cache).cmp) | ||
1380 | 551 | if not os.path.exists(orig_target): | ||
1381 | 552 | os.makedirs(orig_target) | ||
1382 | 553 | for dscname in files_list: | ||
1383 | 554 | dsc = cache.get_dsc(dscname) | ||
1384 | 555 | def get_dsc_part(from_transport, filename): | ||
1385 | 556 | from_f = from_transport.get(filename) | ||
1386 | 557 | contents = from_f.read() | ||
1387 | 558 | to_f = open(os.path.join(orig_target, filename), 'wb') | ||
1388 | 559 | try: | ||
1389 | 560 | to_f.write(contents) | ||
1390 | 561 | finally: | ||
1391 | 562 | to_f.close() | ||
1392 | 563 | base, filename = urlutils.split(dscname) | ||
1393 | 564 | from_transport = cache.get_transport(dscname) | ||
1394 | 565 | get_dsc_part(from_transport, filename) | ||
1395 | 566 | for file_details in dsc['files']: | ||
1396 | 567 | name = file_details['name'] | ||
1397 | 568 | get_dsc_part(from_transport, name) | ||
1398 | 569 | db.import_package(os.path.join(orig_target, filename)) | ||
1399 | 570 | |||
1400 | 571 | def run(self, files_list, distribution=None, filename=None): | ||
1401 | 572 | from bzrlib.plugins.builddeb.errors import MissingChangelogError | ||
1402 | 573 | if distribution is None: | ||
1403 | 574 | raise BzrCommandError("You must specify the distribution " | ||
1404 | 575 | "these packages were uploaded to using --distribution.") | ||
1405 | 576 | distribution = distribution.lower() | ||
1406 | 577 | distribution_name = lookup_distribution(distribution) | ||
1407 | 578 | if distribution_name is None: | ||
1408 | 579 | raise BzrCommandError("Unknown target distribution: %s" \ | ||
1409 | 580 | % distribution) | ||
1410 | 581 | try: | ||
1411 | 582 | tree = WorkingTree.open_containing('.')[0] | ||
1412 | 583 | except NotBranchError: | ||
1413 | 584 | raise BzrCommandError("There is no tree to import the packages in to") | ||
1414 | 585 | tree.lock_write() | ||
1415 | 586 | try: | ||
1416 | 587 | if tree.changes_from(tree.basis_tree()).has_changed(): | ||
1417 | 588 | raise BzrCommandError("There are uncommitted changes in the " | ||
1418 | 589 | "working tree. You must commit before using this " | ||
1419 | 590 | "command") | ||
1420 | 591 | if files_list is None: | ||
1421 | 592 | files_list = [] | ||
1422 | 593 | if filename is not None: | ||
1423 | 594 | if isinstance(filename, unicode): | ||
1424 | 595 | filename = filename.encode('utf-8') | ||
1425 | 596 | base_dir, path = urlutils.split(filename) | ||
1426 | 597 | sources_file = get_transport(base_dir).get(path) | ||
1427 | 598 | for line in sources_file: | ||
1428 | 599 | line.strip() | ||
1429 | 600 | files_list.append(line) | ||
1430 | 601 | if len(files_list) < 1: | ||
1431 | 602 | raise BzrCommandError("You must give the location of at least one " | ||
1432 | 603 | "source package to install, or use the " | ||
1433 | 604 | "--file option.") | ||
1434 | 605 | config = debuild_config(tree, tree, False) | ||
1435 | 606 | orig_dir = config.orig_dir or default_orig_dir | ||
1436 | 607 | orig_target = os.path.join(tree.basedir, default_orig_dir) | ||
1437 | 608 | db = DistributionBranch(distribution_name, tree.branch, | ||
1438 | 609 | None, tree=tree) | ||
1439 | 610 | dbs = DistributionBranchSet() | ||
1440 | 611 | dbs.add_branch(db) | ||
1441 | 612 | try: | ||
1442 | 613 | (changelog, larstiq) = find_changelog(tree, False) | ||
1443 | 614 | last_version = changelog.version | ||
1444 | 615 | except MissingChangelogError: | ||
1445 | 616 | last_version = None | ||
1446 | 617 | tempdir = tempfile.mkdtemp(dir=os.path.join(tree.basedir, | ||
1447 | 618 | '..')) | ||
1448 | 619 | try: | ||
1449 | 620 | if last_version is not None: | ||
1450 | 621 | upstream_tip = db._revid_of_upstream_version_from_branch( | ||
1451 | 622 | last_version) | ||
1452 | 623 | db._extract_upstream_tree(upstream_tip, tempdir) | ||
1453 | 624 | else: | ||
1454 | 625 | db._create_empty_upstream_tree(tempdir) | ||
1455 | 626 | self.import_many(db, files_list, orig_target) | ||
1456 | 627 | finally: | ||
1457 | 628 | shutil.rmtree(tempdir) | ||
1458 | 629 | finally: | ||
1459 | 630 | tree.unlock() | ||
1460 | 631 | |||
1461 | 632 | |||
1462 | 633 | |||
1463 | 634 | class cmd_bd_do(Command): | ||
1464 | 635 | """Run a command in an exported package, copying the result back. | ||
1465 | 636 | |||
1466 | 637 | For a merge mode package the full source is not available, making some | ||
1467 | 638 | operations difficult. This command allows you to run any command in an | ||
1468 | 639 | exported source directory, copying the resulting debian/ directory back | ||
1469 | 640 | to your branch if the command is successful. | ||
1470 | 641 | |||
1471 | 642 | For instance: | ||
1472 | 643 | |||
1473 | 644 | bzr bd-do | ||
1474 | 645 | |||
1475 | 646 | will run a shell in the unpacked source. Any changes you make in the | ||
1476 | 647 | ``debian/`` directory (and only those made in that directory) will be copied | ||
1477 | 648 | back to the branch. If you exit with a non-zero exit code (e.g. "exit 1"), | ||
1478 | 649 | then the changes will not be copied back. | ||
1479 | 650 | |||
1480 | 651 | You can also specify single commands to be run, e.g. | ||
1481 | 652 | |||
1482 | 653 | bzr bd-do "dpatch-edit-patch 01-fix-build" | ||
1483 | 654 | |||
1484 | 655 | Note that only the first argument is used as the command, and so the above | ||
1485 | 656 | example had to be quoted. | ||
1486 | 657 | """ | ||
1487 | 658 | |||
1488 | 659 | takes_args = ['command?'] | ||
1489 | 660 | |||
1490 | 661 | def run(self, command=None): | ||
1491 | 662 | t = WorkingTree.open_containing('.')[0] | ||
1492 | 663 | config = debuild_config(t, t, False) | ||
1493 | 664 | |||
1494 | 665 | if not config.merge: | ||
1495 | 666 | raise BzrCommandError("This command only works for merge mode " | ||
1496 | 667 | "packages. See /usr/share/doc/bzr-builddeb" | ||
1497 | 668 | "/user_manual/merge.html for more information.") | ||
1498 | 669 | |||
1499 | 670 | give_instruction = False | ||
1500 | 671 | if command is None: | ||
1501 | 672 | try: | ||
1502 | 673 | command = os.environ['SHELL'] | ||
1503 | 674 | except KeyError: | ||
1504 | 675 | command = "/bin/sh" | ||
1505 | 676 | give_instruction = True | ||
1506 | 677 | (changelog, larstiq) = find_changelog(t, True) | ||
1507 | 678 | build_dir = config.build_dir | ||
1508 | 679 | if build_dir is None: | ||
1509 | 680 | build_dir = default_build_dir | ||
1510 | 681 | orig_dir = config.orig_dir | ||
1511 | 682 | if orig_dir is None: | ||
1512 | 683 | orig_dir = default_orig_dir | ||
1513 | 684 | properties = BuildProperties(changelog, build_dir, orig_dir, larstiq) | ||
1514 | 685 | export_upstream = config.export_upstream | ||
1515 | 686 | export_upstream_revision = config.export_upstream_revision | ||
1516 | 687 | |||
1517 | 688 | if export_upstream is None: | ||
1518 | 689 | build = DebMergeBuild(properties, t, _is_working_tree=True) | ||
1519 | 690 | else: | ||
1520 | 691 | prepull_upstream = config.prepull_upstream | ||
1521 | 692 | stop_on_no_change = config.prepull_upstream_stop | ||
1522 | 693 | build = DebMergeExportUpstreamBuild(properties, t, export_upstream, | ||
1523 | 694 | export_upstream_revision, | ||
1524 | 695 | prepull_upstream, | ||
1525 | 696 | stop_on_no_change, | ||
1526 | 697 | _is_working_tree=True) | ||
1527 | 698 | |||
1528 | 699 | build.prepare() | ||
1529 | 700 | try: | ||
1530 | 701 | build.export() | ||
1531 | 702 | except StopBuild, e: | ||
1532 | 703 | warning('Stopping the build: %s.', e.reason) | ||
1533 | 704 | info('Running "%s" in the exported directory.' % (command)) | ||
1534 | 705 | if give_instruction: | ||
1535 | 706 | info('If you want to cancel your changes then exit with a non-zero ' | ||
1536 | 707 | 'exit code, e.g. run "exit 1".') | ||
1537 | 708 | proc = subprocess.Popen(command, shell=True, | ||
1538 | 709 | cwd=properties.source_dir()) | ||
1539 | 710 | proc.wait() | ||
1540 | 711 | if proc.returncode != 0: | ||
1541 | 712 | raise BzrCommandError('Not updating the working tree as the command ' | ||
1542 | 713 | 'failed.') | ||
1543 | 714 | info("Copying debian/ back") | ||
1544 | 715 | if larstiq: | ||
1545 | 716 | destination = '.' | ||
1546 | 717 | else: | ||
1547 | 718 | destination = 'debian/' | ||
1548 | 719 | source_debian = os.path.join(properties.source_dir(), 'debian') | ||
1549 | 720 | for filename in os.listdir(source_debian): | ||
1550 | 721 | proc = subprocess.Popen('cp -apf "%s" "%s"' % ( | ||
1551 | 722 | os.path.join(source_debian, filename), destination), | ||
1552 | 723 | shell=True) | ||
1553 | 724 | proc.wait() | ||
1554 | 725 | if proc.returncode != 0: | ||
1555 | 726 | raise BzrCommandError('Copying back debian/ failed') | ||
1556 | 727 | build.clean() | ||
1557 | 728 | info('If any files were added or removed you should run "bzr add" or ' | ||
1558 | 729 | '"bzr rm" as appropriate.') | ||
1559 | 730 | |||
1560 | 731 | |||
1561 | 732 | |||
1562 | 733 | |||
1563 | 734 | class cmd_mark_uploaded(Command): | ||
1564 | 735 | """Mark that this branch has been uploaded, prior to pushing it. | ||
1565 | 736 | |||
1566 | 737 | When a package has been uploaded we want to mark the revision | ||
1567 | 738 | that it was uploaded in. This command automates doing that | ||
1568 | 739 | by marking the current tip revision with the version indicated | ||
1569 | 740 | in debian/changelog. | ||
1570 | 741 | """ | ||
1571 | 742 | force = Option('force', help="Mark the upload even if it is already " | ||
1572 | 743 | "marked.") | ||
1573 | 744 | |||
1574 | 745 | takes_options = [merge_opt, no_user_conf_opt, force] | ||
1575 | 746 | |||
1576 | 747 | def run(self, merge=False, no_user_config=False, force=None): | ||
1577 | 748 | t = WorkingTree.open_containing('.')[0] | ||
1578 | 749 | t.lock_write() | ||
1579 | 750 | try: | ||
1580 | 751 | if t.changes_from(t.basis_tree()).has_changed(): | ||
1581 | 752 | raise BzrCommandError("There are uncommitted changes in the " | ||
1582 | 753 | "working tree. You must commit before using this " | ||
1583 | 754 | "command") | ||
1584 | 755 | config = debuild_config(t, t, no_user_config) | ||
1585 | 756 | if not merge: | ||
1586 | 757 | merge = config.merge | ||
1587 | 758 | (changelog, larstiq) = find_changelog(t, merge) | ||
1588 | 759 | distributions = changelog.distributions.strip() | ||
1589 | 760 | target_dist = distributions.split()[0] | ||
1590 | 761 | distribution_name = suite_to_distribution(target_dist) | ||
1591 | 762 | if distribution_name is None: | ||
1592 | 763 | raise BzrCommandError("Unknown target distribution: %s" \ | ||
1593 | 764 | % target_dist) | ||
1594 | 765 | db = DistributionBranch(distribution_name, t.branch, None) | ||
1595 | 766 | dbs = DistributionBranchSet() | ||
1596 | 767 | dbs.add_branch(db) | ||
1597 | 768 | if db.has_version(changelog.version): | ||
1598 | 769 | if not force: | ||
1599 | 770 | raise BzrCommandError("This version has already been " | ||
1600 | 771 | "marked uploaded. Use --force to force marking " | ||
1601 | 772 | "this new version.") | ||
1602 | 773 | db.tag_version(changelog.version) | ||
1603 | 774 | finally: | ||
1604 | 775 | t.unlock() | ||
1605 | 776 | |||
1606 | 777 | |||
1607 | 778 | class cmd_test_builddeb(Command): | ||
1608 | 779 | """Run the builddeb test suite""" | ||
1609 | 780 | |||
1610 | 781 | hidden = True | ||
1611 | 782 | |||
1612 | 783 | def run(self): | ||
1613 | 784 | from bzrlib.tests import selftest | ||
1614 | 785 | passed = selftest(test_suite_factory=test_suite) | ||
1615 | 786 | # invert for shell exit code rules | ||
1616 | 787 | return not passed | ||
1617 | 788 | |||
1618 | 0 | 789 | ||
1619 | === modified file 'revspec.py' | |||
1620 | --- revspec.py 2008-11-27 15:30:30 +0000 | |||
1621 | +++ revspec.py 2009-01-29 23:47:05 +0000 | |||
1622 | @@ -19,7 +19,7 @@ | |||
1623 | 19 | # | 19 | # |
1624 | 20 | 20 | ||
1625 | 21 | from bzrlib.errors import NoSuchTag | 21 | from bzrlib.errors import NoSuchTag |
1627 | 22 | from bzrlib.revisionspec import RevisionSpec, RevisionInfo, SPEC_TYPES | 22 | from bzrlib.revisionspec import RevisionSpec, RevisionInfo |
1628 | 23 | 23 | ||
1629 | 24 | from bzrlib.plugins.builddeb.errors import ( | 24 | from bzrlib.plugins.builddeb.errors import ( |
1630 | 25 | AmbiguousPackageSpecification, | 25 | AmbiguousPackageSpecification, |
1631 | @@ -84,5 +84,4 @@ | |||
1632 | 84 | return RevisionInfo.from_revision_id(branch, | 84 | return RevisionInfo.from_revision_id(branch, |
1633 | 85 | revision_id, revs) | 85 | revision_id, revs) |
1634 | 86 | 86 | ||
1635 | 87 | SPEC_TYPES.append(RevisionSpec_package) | ||
1636 | 88 | 87 | ||
1637 | 89 | 88 | ||
1638 | === modified file 'tests/__init__.py' | |||
1639 | --- tests/__init__.py 2008-09-03 12:07:07 +0000 | |||
1640 | +++ tests/__init__.py 2009-02-12 14:45:56 +0000 | |||
1641 | @@ -134,7 +134,7 @@ | |||
1642 | 134 | 'config' | 134 | 'config' |
1643 | 135 | ] | 135 | ] |
1644 | 136 | for mod in doctest_mod_names: | 136 | for mod in doctest_mod_names: |
1646 | 137 | suite.addTest(doctest.DocTestSuite(mod)) | 137 | suite.addTest(doctest.DocTestSuite("bzrlib.plugins.builddeb." + mod)) |
1647 | 138 | 138 | ||
1648 | 139 | adapt_modules(['%s.test_repack_tarball' % __name__], | 139 | adapt_modules(['%s.test_repack_tarball' % __name__], |
1649 | 140 | RepackTarballAdaptor(), loader, suite) | 140 | RepackTarballAdaptor(), loader, suite) |
1650 | 141 | 141 | ||
1651 | === modified file 'tests/test_repack_tarball_extra.py' | |||
1652 | --- tests/test_repack_tarball_extra.py 2008-12-02 16:25:25 +0000 | |||
1653 | +++ tests/test_repack_tarball_extra.py 2009-02-12 14:45:56 +0000 | |||
1654 | @@ -22,7 +22,7 @@ | |||
1655 | 22 | import shutil | 22 | import shutil |
1656 | 23 | import tarfile | 23 | import tarfile |
1657 | 24 | 24 | ||
1659 | 25 | from repack_tarball import repack_tarball | 25 | from bzrlib.plugins.builddeb.repack_tarball import repack_tarball |
1660 | 26 | 26 | ||
1661 | 27 | from bzrlib.errors import BzrCommandError, FileExists | 27 | from bzrlib.errors import BzrCommandError, FileExists |
1662 | 28 | from bzrlib.tests import TestCaseInTempDir | 28 | from bzrlib.tests import TestCaseInTempDir |
The attached patch improves the import overhead of bzr-builddeb by:
* lazily registering all commands (moved to cmds.py) plugins. builddeb"
* using absolute imports everywhere, and no longer updating sys.path to
include "bzrlib.
It seems intrusive, but mainly just moves code from __init__.py to cmds.py.
In practice, this means having bzr-builddeb enabled will only load the
__init__.py file if you're not using it.