dpkg-source.pl 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. #!/usr/bin/perl
  2. #
  3. # dpkg-source
  4. #
  5. # Copyright © 1996 Ian Jackson <ijackson@chiark.greenend.org.uk>
  6. # Copyright © 1997 Klee Dienes <klee@debian.org>
  7. # Copyright © 1999-2003 Wichert Akkerman <wakkerma@debian.org>
  8. # Copyright © 1999 Ben Collins <bcollins@debian.org>
  9. # Copyright © 2000-2003 Adam Heath <doogie@debian.org>
  10. # Copyright © 2005 Brendan O'Dea <bod@debian.org>
  11. # Copyright © 2006-2008 Frank Lichtenheld <djpig@debian.org>
  12. # Copyright © 2006-2009,2012 Guillem Jover <guillem@debian.org>
  13. # Copyright © 2008-2011 Raphaël Hertzog <hertzog@debian.org>
  14. #
  15. # This program is free software; you can redistribute it and/or modify
  16. # it under the terms of the GNU General Public License as published by
  17. # the Free Software Foundation; either version 2 of the License, or
  18. # (at your option) any later version.
  19. #
  20. # This program is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. # GNU General Public License for more details.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  27. use strict;
  28. use warnings;
  29. use Cwd;
  30. use File::Basename;
  31. use File::Spec;
  32. use Dpkg ();
  33. use Dpkg::Gettext;
  34. use Dpkg::ErrorHandling;
  35. use Dpkg::Util qw(:list);
  36. use Dpkg::Arch qw(debarch_eq debarch_is debarch_is_wildcard debarch_is_illegal);
  37. use Dpkg::Deps;
  38. use Dpkg::Compression;
  39. use Dpkg::Conf;
  40. use Dpkg::Control::Info;
  41. use Dpkg::Control::Tests;
  42. use Dpkg::Control::Fields;
  43. use Dpkg::Index;
  44. use Dpkg::Substvars;
  45. use Dpkg::Version;
  46. use Dpkg::Vars;
  47. use Dpkg::Changelog::Parse;
  48. use Dpkg::Source::Package qw(get_default_diff_ignore_regex
  49. set_default_diff_ignore_regex
  50. get_default_tar_ignore_pattern);
  51. use Dpkg::Vendor qw(run_vendor_hook);
  52. textdomain('dpkg-dev');
  53. my $controlfile;
  54. my $changelogfile;
  55. my $changelogformat;
  56. my $build_format;
  57. my %options = (
  58. # Ignore files
  59. tar_ignore => [],
  60. diff_ignore_regex => '',
  61. # Misc options
  62. copy_orig_tarballs => 1,
  63. no_check => 0,
  64. require_valid_signature => 0,
  65. require_strong_checksums => 0,
  66. );
  67. # Fields to remove/override
  68. my %remove;
  69. my %override;
  70. my $substvars = Dpkg::Substvars->new();
  71. my $tar_ignore_default_pattern_done;
  72. my $diff_ignore_regex = get_default_diff_ignore_regex();
  73. my @options;
  74. my @cmdline_options;
  75. while (@ARGV && $ARGV[0] =~ m/^-/) {
  76. my $arg = shift @ARGV;
  77. if ($arg eq '-b' or $arg eq '--build') {
  78. setopmode('build');
  79. } elsif ($arg eq '-x' or $arg eq '--extract') {
  80. setopmode('extract');
  81. } elsif ($arg eq '--before-build') {
  82. setopmode('before-build');
  83. } elsif ($arg eq '--after-build') {
  84. setopmode('after-build');
  85. } elsif ($arg eq '--commit') {
  86. setopmode('commit');
  87. } elsif ($arg eq '--print-format') {
  88. setopmode('print-format');
  89. report_options(info_fh => \*STDERR); # Avoid clutter on STDOUT
  90. } else {
  91. push @options, $arg;
  92. }
  93. }
  94. my $dir;
  95. if (defined($options{opmode}) &&
  96. $options{opmode} =~ /^(build|print-format|(before|after)-build|commit)$/) {
  97. if (not scalar(@ARGV)) {
  98. usageerr(g_('--%s needs a directory'), $options{opmode})
  99. unless $1 eq 'commit';
  100. $dir = '.';
  101. } else {
  102. $dir = File::Spec->catdir(shift(@ARGV));
  103. }
  104. stat($dir) or syserr(g_('cannot stat directory %s'), $dir);
  105. if (not -d $dir) {
  106. error(g_('directory argument %s is not a directory'), $dir);
  107. }
  108. if ($dir eq '.') {
  109. # . is never correct, adjust automatically
  110. $dir = basename(cwd());
  111. chdir '..' or syserr(g_("unable to chdir to '%s'"), '..');
  112. }
  113. # --format options are not allowed, they would take precedence
  114. # over real command line options, debian/source/format should be used
  115. # instead
  116. # --unapply-patches is only allowed in local-options as it's a matter
  117. # of personal taste and the default should be to keep patches applied
  118. my $forbidden_opts_re = {
  119. 'options' => qr/^--(?:format=|unapply-patches$|abort-on-upstream-changes$)/,
  120. 'local-options' => qr/^--format=/,
  121. };
  122. foreach my $filename ('local-options', 'options') {
  123. my $conf = Dpkg::Conf->new();
  124. my $optfile = File::Spec->catfile($dir, 'debian', 'source', $filename);
  125. next unless -f $optfile;
  126. $conf->load($optfile);
  127. $conf->filter(remove => sub { $_[0] =~ $forbidden_opts_re->{$filename} });
  128. if (@$conf) {
  129. info(g_('using options from %s: %s'), $optfile, join(' ', @$conf))
  130. unless $options{opmode} eq 'print-format';
  131. unshift @options, @$conf;
  132. }
  133. }
  134. }
  135. while (@options) {
  136. $_ = shift(@options);
  137. if (m/^--format=(.*)$/) {
  138. $build_format //= $1;
  139. } elsif (m/^-(?:Z|-compression=)(.*)$/) {
  140. my $compression = $1;
  141. $options{compression} = $compression;
  142. usageerr(g_('%s is not a supported compression'), $compression)
  143. unless compression_is_supported($compression);
  144. compression_set_default($compression);
  145. } elsif (m/^-(?:z|-compression-level=)(.*)$/) {
  146. my $comp_level = $1;
  147. $options{comp_level} = $comp_level;
  148. usageerr(g_('%s is not a compression level'), $comp_level)
  149. unless compression_is_valid_level($comp_level);
  150. compression_set_default_level($comp_level);
  151. } elsif (m/^-c(.*)$/) {
  152. $controlfile = $1;
  153. } elsif (m/^-l(.*)$/) {
  154. $changelogfile = $1;
  155. } elsif (m/^-F([0-9a-z]+)$/) {
  156. $changelogformat = $1;
  157. } elsif (m/^-D([^\=:]+)[=:](.*)$/s) {
  158. $override{$1} = $2;
  159. } elsif (m/^-U([^\=:]+)$/) {
  160. $remove{$1} = 1;
  161. } elsif (m/^-(?:i|-diff-ignore(?:$|=))(.*)$/) {
  162. $options{diff_ignore_regex} = $1 ? $1 : $diff_ignore_regex;
  163. } elsif (m/^--extend-diff-ignore=(.+)$/) {
  164. $diff_ignore_regex .= "|$1";
  165. if ($options{diff_ignore_regex}) {
  166. $options{diff_ignore_regex} .= "|$1";
  167. }
  168. set_default_diff_ignore_regex($diff_ignore_regex);
  169. } elsif (m/^-(?:I|-tar-ignore=)(.+)$/) {
  170. push @{$options{tar_ignore}}, $1;
  171. } elsif (m/^-(?:I|-tar-ignore)$/) {
  172. unless ($tar_ignore_default_pattern_done) {
  173. push @{$options{tar_ignore}}, get_default_tar_ignore_pattern();
  174. # Prevent adding multiple times
  175. $tar_ignore_default_pattern_done = 1;
  176. }
  177. } elsif (m/^--no-copy$/) {
  178. $options{copy_orig_tarballs} = 0;
  179. } elsif (m/^--no-check$/) {
  180. $options{no_check} = 1;
  181. } elsif (m/^--require-valid-signature$/) {
  182. $options{require_valid_signature} = 1;
  183. } elsif (m/^--require-strong-checksums$/) {
  184. $options{require_strong_checksums} = 1;
  185. } elsif (m/^-V(\w[-:0-9A-Za-z]*)[=:](.*)$/s) {
  186. $substvars->set($1, $2);
  187. } elsif (m/^-T(.*)$/) {
  188. $substvars->load($1) if -e $1;
  189. } elsif (m/^-(?:\?|-help)$/) {
  190. usage();
  191. exit(0);
  192. } elsif (m/^--version$/) {
  193. version();
  194. exit(0);
  195. } elsif (m/^-[EW]$/) {
  196. # Deprecated option
  197. warning(g_('-E and -W are deprecated, they are without effect'));
  198. } elsif (m/^-q$/) {
  199. report_options(quiet_warnings => 1);
  200. $options{quiet} = 1;
  201. } elsif (m/^--$/) {
  202. last;
  203. } else {
  204. push @cmdline_options, $_;
  205. }
  206. }
  207. unless (defined($options{opmode})) {
  208. usageerr(g_('need an action option'));
  209. }
  210. if ($options{opmode} =~ /^(build|print-format|(before|after)-build|commit)$/) {
  211. $options{ARGV} = \@ARGV;
  212. $changelogfile ||= "$dir/debian/changelog";
  213. $controlfile ||= "$dir/debian/control";
  214. my %ch_options = (file => $changelogfile);
  215. $ch_options{changelogformat} = $changelogformat if $changelogformat;
  216. my $changelog = changelog_parse(%ch_options);
  217. my $control = Dpkg::Control::Info->new($controlfile);
  218. my $srcpkg = Dpkg::Source::Package->new(options => \%options);
  219. my $fields = $srcpkg->{fields};
  220. my @sourcearch;
  221. my %archadded;
  222. my @binarypackages;
  223. # Scan control info of source package
  224. my $src_fields = $control->get_source();
  225. error(g_("%s doesn't contain any information about the source package"),
  226. $controlfile) unless defined $src_fields;
  227. my $src_sect = $src_fields->{'Section'} || 'unknown';
  228. my $src_prio = $src_fields->{'Priority'} || 'unknown';
  229. foreach (keys %{$src_fields}) {
  230. my $v = $src_fields->{$_};
  231. if (m/^Source$/i) {
  232. set_source_package($v);
  233. $fields->{$_} = $v;
  234. } elsif (m/^Uploaders$/i) {
  235. ($fields->{$_} = $v) =~ s/\s*[\r\n]\s*/ /g; # Merge in a single-line
  236. } elsif (m/^Build-(?:Depends|Conflicts)(?:-Arch|-Indep)?$/i) {
  237. my $dep;
  238. my $type = field_get_dep_type($_);
  239. $dep = deps_parse($v, build_dep => 1, union => $type eq 'union');
  240. error(g_('error occurred while parsing %s'), $_) unless defined $dep;
  241. my $facts = Dpkg::Deps::KnownFacts->new();
  242. $dep->simplify_deps($facts);
  243. $dep->sort() if $type eq 'union';
  244. $fields->{$_} = $dep->output();
  245. } else {
  246. field_transfer_single($src_fields, $fields);
  247. }
  248. }
  249. # Scan control info of binary packages
  250. my @pkglist;
  251. foreach my $pkg ($control->get_packages()) {
  252. my $p = $pkg->{'Package'};
  253. my $sect = $pkg->{'Section'} || $src_sect;
  254. my $prio = $pkg->{'Priority'} || $src_prio;
  255. my $type = $pkg->{'Package-Type'} ||
  256. $pkg->get_custom_field('Package-Type') || 'deb';
  257. my $arch = $pkg->{'Architecture'};
  258. my $profile = $pkg->{'Build-Profiles'};
  259. my $pkg_summary = sprintf('%s %s %s %s', $p, $type, $sect, $prio);
  260. $pkg_summary .= ' arch=' . join ',', split /\s+/, $arch;
  261. if (defined $profile) {
  262. # If the string does not contain brackets then it is using the
  263. # old syntax. Emit a fatal error.
  264. if ($profile !~ m/^\s*<.*>\s*$/) {
  265. error(g_('binary package stanza %s is using an obsolete ' .
  266. 'Build-Profiles field syntax'), $p);
  267. }
  268. # Instead of splitting twice and then joining twice, we just do
  269. # simple string replacements:
  270. # Remove the enclosing <>
  271. $profile =~ s/^\s*<(.*)>\s*$/$1/;
  272. # Join lists with a plus (OR)
  273. $profile =~ s/>\s+</+/g;
  274. # Join their elements with a comma (AND)
  275. $profile =~ s/\s+/,/g;
  276. $pkg_summary .= " profile=$profile";
  277. }
  278. if (defined $pkg->{'Essential'} and $pkg->{'Essential'} eq 'yes') {
  279. $pkg_summary .= ' essential=yes';
  280. }
  281. push @pkglist, $pkg_summary;
  282. push @binarypackages, $p;
  283. foreach (keys %{$pkg}) {
  284. my $v = $pkg->{$_};
  285. if (m/^Architecture$/) {
  286. # Gather all binary architectures in one set. 'any' and 'all'
  287. # are special-cased as they need to be the only ones in the
  288. # current stanza if present.
  289. if (debarch_eq($v, 'any') || debarch_eq($v, 'all')) {
  290. push(@sourcearch, $v) unless $archadded{$v}++;
  291. } else {
  292. for my $a (split(/\s+/, $v)) {
  293. error(g_("'%s' is not a legal architecture string"), $a)
  294. if debarch_is_illegal($a);
  295. error(g_('architecture %s only allowed on its ' .
  296. "own (list for package %s is '%s')"),
  297. $a, $p, $a)
  298. if $a eq 'any' or $a eq 'all';
  299. push(@sourcearch, $a) unless $archadded{$a}++;
  300. }
  301. }
  302. } elsif (m/^Homepage$/) {
  303. # Do not overwrite the same field from the source entry
  304. } else {
  305. field_transfer_single($pkg, $fields);
  306. }
  307. }
  308. }
  309. unless (scalar(@pkglist)) {
  310. error(g_("%s doesn't list any binary package"), $controlfile);
  311. }
  312. if (any { $_ eq 'any' } @sourcearch) {
  313. # If we encounter one 'any' then the other arches become insignificant
  314. # except for 'all' that must also be kept
  315. if (any { $_ eq 'all' } @sourcearch) {
  316. @sourcearch = qw(any all);
  317. } else {
  318. @sourcearch = qw(any);
  319. }
  320. } else {
  321. # Minimize arch list, by removing arches already covered by wildcards
  322. my @arch_wildcards = grep { debarch_is_wildcard($_) } @sourcearch;
  323. my @mini_sourcearch = @arch_wildcards;
  324. foreach my $arch (@sourcearch) {
  325. if (none { debarch_is($arch, $_) } @arch_wildcards) {
  326. push @mini_sourcearch, $arch;
  327. }
  328. }
  329. @sourcearch = @mini_sourcearch;
  330. }
  331. $fields->{'Architecture'} = join(' ', @sourcearch);
  332. $fields->{'Package-List'} = "\n" . join("\n", sort @pkglist);
  333. # Check if we have a testsuite, and handle manual and automatic values.
  334. set_testsuite_field($fields);
  335. set_testsuite_triggers_field($fields, @binarypackages);
  336. # Scan fields of dpkg-parsechangelog
  337. foreach (keys %{$changelog}) {
  338. my $v = $changelog->{$_};
  339. if (m/^Source$/) {
  340. set_source_package($v);
  341. $fields->{$_} = $v;
  342. } elsif (m/^Version$/) {
  343. my ($ok, $error) = version_check($v);
  344. error($error) unless $ok;
  345. $fields->{$_} = $v;
  346. } elsif (m/^Binary-Only$/) {
  347. error(g_('building source for a binary-only release'))
  348. if $v eq 'yes' and $options{opmode} eq 'build';
  349. } elsif (m/^Maintainer$/i) {
  350. # Do not replace the field coming from the source entry
  351. } else {
  352. field_transfer_single($changelog, $fields);
  353. }
  354. }
  355. $fields->{'Binary'} = join(', ', @binarypackages);
  356. # Avoid overly long line by splitting over multiple lines
  357. if (length($fields->{'Binary'}) > 980) {
  358. $fields->{'Binary'} =~ s/(.{0,980}), ?/$1,\n/g;
  359. }
  360. # Select the format to use
  361. if (not defined $build_format) {
  362. if (-e "$dir/debian/source/format") {
  363. open(my $format_fh, '<', "$dir/debian/source/format")
  364. or syserr(g_('cannot read %s'), "$dir/debian/source/format");
  365. $build_format = <$format_fh>;
  366. chomp($build_format) if defined $build_format;
  367. error(g_('%s is empty'), "$dir/debian/source/format")
  368. unless defined $build_format and length $build_format;
  369. close($format_fh);
  370. } else {
  371. warning(g_('no source format specified in %s, ' .
  372. 'see dpkg-source(1)'), 'debian/source/format')
  373. if $options{opmode} eq 'build';
  374. $build_format = '1.0';
  375. }
  376. }
  377. $fields->{'Format'} = $build_format;
  378. $srcpkg->upgrade_object_type(); # Fails if format is unsupported
  379. # Parse command line options
  380. $srcpkg->init_options();
  381. $srcpkg->parse_cmdline_options(@cmdline_options);
  382. if ($options{opmode} eq 'print-format') {
  383. print $fields->{'Format'} . "\n";
  384. exit(0);
  385. } elsif ($options{opmode} eq 'before-build') {
  386. $srcpkg->before_build($dir);
  387. exit(0);
  388. } elsif ($options{opmode} eq 'after-build') {
  389. $srcpkg->after_build($dir);
  390. exit(0);
  391. } elsif ($options{opmode} eq 'commit') {
  392. $srcpkg->commit($dir);
  393. exit(0);
  394. }
  395. # Verify pre-requisites are met
  396. my ($res, $msg) = $srcpkg->can_build($dir);
  397. error(g_("can't build with source format '%s': %s"), $build_format, $msg) unless $res;
  398. # Only -b left
  399. info(g_("using source format '%s'"), $fields->{'Format'});
  400. run_vendor_hook('before-source-build', $srcpkg);
  401. # Build the files (.tar.gz, .diff.gz, etc)
  402. $srcpkg->build($dir);
  403. # Write the .dsc
  404. my $dscname = $srcpkg->get_basename(1) . '.dsc';
  405. info(g_('building %s in %s'), get_source_package(), $dscname);
  406. $srcpkg->write_dsc(filename => $dscname,
  407. remove => \%remove,
  408. override => \%override,
  409. substvars => $substvars);
  410. exit(0);
  411. } elsif ($options{opmode} eq 'extract') {
  412. # Check command line
  413. unless (scalar(@ARGV)) {
  414. usageerr(g_('--%s needs at least one argument, the .dsc'),
  415. $options{opmode});
  416. }
  417. if (scalar(@ARGV) > 2) {
  418. usageerr(g_('--%s takes no more than two arguments'), $options{opmode});
  419. }
  420. my $dsc = shift(@ARGV);
  421. if (-d $dsc) {
  422. usageerr(g_('--%s needs the .dsc file as first argument, not a directory'),
  423. $options{opmode});
  424. }
  425. # Create the object that does everything
  426. my $srcpkg = Dpkg::Source::Package->new(filename => $dsc,
  427. options => \%options);
  428. # Parse command line options
  429. $srcpkg->parse_cmdline_options(@cmdline_options);
  430. # Decide where to unpack
  431. my $newdirectory = $srcpkg->get_basename();
  432. $newdirectory =~ s/_/-/g;
  433. if (@ARGV) {
  434. $newdirectory = File::Spec->catdir(shift(@ARGV));
  435. if (-e $newdirectory) {
  436. error(g_('unpack target exists: %s'), $newdirectory);
  437. }
  438. }
  439. # Various checks before unpacking
  440. unless ($options{no_check}) {
  441. if ($srcpkg->is_signed()) {
  442. $srcpkg->check_signature();
  443. } else {
  444. if ($options{require_valid_signature}) {
  445. error(g_("%s doesn't contain a valid OpenPGP signature"), $dsc);
  446. } else {
  447. warning(g_('extracting unsigned source package (%s)'), $dsc);
  448. }
  449. }
  450. $srcpkg->check_checksums();
  451. }
  452. # Unpack the source package (delegated to Dpkg::Source::Package::*)
  453. info(g_('extracting %s in %s'), $srcpkg->{fields}{'Source'}, $newdirectory);
  454. $srcpkg->extract($newdirectory);
  455. exit(0);
  456. }
  457. sub set_testsuite_field
  458. {
  459. my $fields = shift;
  460. my $testsuite_field = $fields->{'Testsuite'} // '';
  461. my %testsuite = map { $_ => 1 } split /\s*,\s*/, $testsuite_field;
  462. if (-e "$dir/debian/tests/control") {
  463. error(g_('test control %s is not a regular file'),
  464. 'debian/tests/control') unless -f _;
  465. $testsuite{autopkgtest} = 1;
  466. } elsif ($testsuite{autopkgtest}) {
  467. warning(g_('%s field contains value %s, but no tests control file %s'),
  468. 'Testsuite', 'autopkgtest', 'debian/tests/control');
  469. delete $testsuite{autopkgtest};
  470. }
  471. $fields->{'Testsuite'} = join ', ', sort keys %testsuite;
  472. }
  473. sub set_testsuite_triggers_field
  474. {
  475. my ($fields, @binarypackages) = @_;
  476. my %testdeps;
  477. # Never overwrite a manually defined field.
  478. return if $fields->{'Testsuite-Triggers'};
  479. # We only support autopkgtests.
  480. return unless -e "$dir/debian/tests/control";
  481. my $tests = Dpkg::Control::Tests->new();
  482. $tests->load("$dir/debian/tests/control");
  483. foreach my $test ($tests->get()) {
  484. next unless $test->{Depends};
  485. my $deps = deps_parse($test->{Depends}, use_arch => 0, tests_dep => 1);
  486. deps_iterate($deps, sub { $testdeps{$_[0]->{package}} = 1 });
  487. }
  488. # Remove our own binaries and meta-depends.
  489. foreach my $pkg (@binarypackages, qw(@ @builddeps@)) {
  490. delete $testdeps{$pkg};
  491. }
  492. $fields->{'Testsuite-Triggers'} = join ', ', sort keys %testdeps;
  493. }
  494. sub setopmode {
  495. my $opmode = shift;
  496. if (defined($options{opmode})) {
  497. usageerr(g_('two commands specified: --%s and --%s'),
  498. $options{opmode}, $opmode);
  499. }
  500. $options{opmode} = $opmode;
  501. }
  502. sub print_option {
  503. my $opt = shift;
  504. my $help;
  505. if (length $opt->{name} > 25) {
  506. $help .= sprintf " %-25s\n%s%s.\n", $opt->{name}, ' ' x 27, $opt->{help};
  507. } else {
  508. $help .= sprintf " %-25s%s.\n", $opt->{name}, $opt->{help};
  509. }
  510. }
  511. sub get_format_help {
  512. $build_format //= '1.0';
  513. my $srcpkg = Dpkg::Source::Package->new();
  514. $srcpkg->{fields}->{'Format'} = $build_format;
  515. $srcpkg->upgrade_object_type(); # Fails if format is unsupported
  516. my @cmdline = $srcpkg->describe_cmdline_options();
  517. my $help_build = my $help_extract = '';
  518. my $help;
  519. foreach my $opt (@cmdline) {
  520. $help_build .= print_option($opt) if $opt->{when} eq 'build';
  521. $help_extract .= print_option($opt) if $opt->{when} eq 'extract';
  522. }
  523. if ($help_build) {
  524. $help .= "\n";
  525. $help .= "Build format $build_format options:\n";
  526. $help .= $help_build || C_('source options', '<none>');
  527. }
  528. if ($help_extract) {
  529. $help .= "\n";
  530. $help .= "Extract format $build_format options:\n";
  531. $help .= $help_extract || C_('source options', '<none>');
  532. }
  533. return $help;
  534. }
  535. sub version {
  536. printf g_("Debian %s version %s.\n"), $Dpkg::PROGNAME, $Dpkg::PROGVERSION;
  537. print g_('
  538. This is free software; see the GNU General Public License version 2 or
  539. later for copying conditions. There is NO warranty.
  540. ');
  541. }
  542. sub usage {
  543. printf g_(
  544. 'Usage: %s [<option>...] <command>')
  545. . "\n\n" . g_(
  546. 'Commands:
  547. -x, --extract <filename>.dsc [<output-dir>]
  548. extract source package.
  549. -b, --build <dir> build source package.
  550. --print-format <dir> print the format to be used for the source package.
  551. --commit [<dir> [<patch-name>]]
  552. store upstream changes in a new patch.')
  553. . "\n\n" . g_(
  554. "Build options:
  555. -c<control-file> get control info from this file.
  556. -l<changelog-file> get per-version info from this file.
  557. -F<changelog-format> force changelog format.
  558. --format=<source-format> set the format to be used for the source package.
  559. -V<name>=<value> set a substitution variable.
  560. -T<substvars-file> read variables here.
  561. -D<field>=<value> override or add a .dsc field and value.
  562. -U<field> remove a field.
  563. -i, --diff-ignore[=<regex>]
  564. filter out files to ignore diffs of
  565. (defaults to: '%s').
  566. -I, --tar-ignore[=<pattern>]
  567. filter out files when building tarballs
  568. (defaults to: %s).
  569. -Z, --compression=<compression>
  570. select compression to use (defaults to '%s',
  571. supported are: %s).
  572. -z, --compression-level=<level>
  573. compression level to use (defaults to '%d',
  574. supported are: '1'-'9', 'best', 'fast')")
  575. . "\n\n" . g_(
  576. "Extract options:
  577. --no-copy don't copy .orig tarballs
  578. --no-check don't check signature and checksums before unpacking
  579. --require-valid-signature abort if the package doesn't have a valid signature
  580. --require-strong-checksums
  581. abort if the package contains no strong checksums
  582. --ignore-bad-version allow bad source package versions.")
  583. . "\n" .
  584. get_format_help()
  585. . "\n" . g_(
  586. 'General options:
  587. -q quiet mode.
  588. -?, --help show this help message.
  589. --version show the version.')
  590. . "\n\n" . g_(
  591. 'Source format specific build and extract options are available;
  592. use --format with --help to see them.') . "\n",
  593. $Dpkg::PROGNAME,
  594. get_default_diff_ignore_regex(),
  595. join(' ', map { "-I$_" } get_default_tar_ignore_pattern()),
  596. compression_get_default(),
  597. join(' ', compression_get_list()),
  598. compression_get_default_level();
  599. }