60
60
# Compression related
61
61
compression => compression_get_default(),
62
62
comp_level => compression_get_default_level(),
63
comp_ext => compression_get_property(compression_get_default(), "file_ext"),
63
comp_ext => compression_get_property(compression_get_default(), 'file_ext'),
66
66
diff_ignore_regexp => '',
101
if (defined($options{'opmode'}) &&
102
$options{'opmode'} =~ /^(-b|--print-format|--(before|after)-build|--commit)$/) {
101
if (defined($options{opmode}) &&
102
$options{opmode} =~ /^(-b|--print-format|--(before|after)-build|--commit)$/) {
103
103
if (not scalar(@ARGV)) {
104
usageerr(_g("%s needs a directory"), $options{'opmode'})
105
unless $1 eq "--commit";
104
usageerr(_g('%s needs a directory'), $options{opmode})
105
unless $1 eq '--commit';
108
108
$dir = File::Spec->catdir(shift(@ARGV));
110
stat($dir) || syserr(_g("cannot stat directory %s"), $dir);
110
stat($dir) || syserr(_g('cannot stat directory %s'), $dir);
111
111
if (not -d $dir) {
112
error(_g("directory argument %s is not a directory"), $dir);
112
error(_g('directory argument %s is not a directory'), $dir);
115
115
# . is never correct, adjust automatically
116
116
$dir = basename(cwd());
117
chdir("..") || syserr(_g("unable to chdir to `%s'"), "..");
117
chdir('..') || syserr(_g("unable to chdir to `%s'"), '..');
119
119
# --format options are not allowed, they would take precedence
120
120
# over real command line options, debian/source/format should be used
122
122
# --unapply-patches is only allowed in local-options as it's a matter
123
123
# of personal taste and the default should be to keep patches applied
124
124
my $forbidden_opts_re = {
125
"options" => qr/^--(?:format=|unapply-patches$|abort-on-upstream-changes$)/,
126
"local-options" => qr/^--format=/,
125
'options' => qr/^--(?:format=|unapply-patches$|abort-on-upstream-changes$)/,
126
'local-options' => qr/^--format=/,
128
foreach my $filename ("local-options", "options") {
128
foreach my $filename ('local-options', 'options') {
129
129
my $conf = Dpkg::Conf->new();
130
my $optfile = File::Spec->catfile($dir, "debian", "source", $filename);
130
my $optfile = File::Spec->catfile($dir, 'debian', 'source', $filename);
131
131
next unless -f $optfile;
132
132
$conf->load($optfile);
133
133
$conf->filter(remove => sub { $_[0] =~ $forbidden_opts_re->{$filename} });
135
info(_g("using options from %s: %s"), $optfile, join(" ", @$conf))
136
unless $options{'opmode'} eq "--print-format";
135
info(_g('using options from %s: %s'), $optfile, join(' ', @$conf))
136
unless $options{opmode} eq '--print-format';
137
137
unshift @options, @$conf;
142
142
while (@options) {
143
143
$_ = shift(@options);
144
144
if (m/^--format=(.*)$/) {
145
$build_format = $1 unless defined $build_format;
145
$build_format //= $1;
146
146
} elsif (m/^-(?:Z|-compression=)(.*)$/) {
147
147
my $compression = $1;
148
$options{'compression'} = $compression;
149
$options{'comp_ext'} = compression_get_property($compression, "file_ext");
150
usageerr(_g("%s is not a supported compression"), $compression)
148
$options{compression} = $compression;
149
$options{comp_ext} = compression_get_property($compression, 'file_ext');
150
usageerr(_g('%s is not a supported compression'), $compression)
151
151
unless compression_is_supported($compression);
152
152
compression_set_default($compression);
153
153
} elsif (m/^-(?:z|-compression-level=)(.*)$/) {
154
154
my $comp_level = $1;
155
$options{'comp_level'} = $comp_level;
156
usageerr(_g("%s is not a compression level"), $comp_level)
155
$options{comp_level} = $comp_level;
156
usageerr(_g('%s is not a compression level'), $comp_level)
157
157
unless compression_is_valid_level($comp_level);
158
158
compression_set_default_level($comp_level);
159
159
} elsif (m/^-c(.*)$/) {
167
167
} elsif (m/^-U([^\=:]+)$/) {
169
169
} elsif (m/^-(?:i|-diff-ignore(?:$|=))(.*)$/) {
170
$options{'diff_ignore_regexp'} = $1 ? $1 : $Dpkg::Source::Package::diff_ignore_default_regexp;
170
$options{diff_ignore_regexp} = $1 ? $1 : $Dpkg::Source::Package::diff_ignore_default_regexp;
171
171
} elsif (m/^--extend-diff-ignore=(.+)$/) {
172
172
$Dpkg::Source::Package::diff_ignore_default_regexp .= "|$1";
173
if ($options{'diff_ignore_regexp'}) {
174
$options{'diff_ignore_regexp'} .= "|$1";
173
if ($options{diff_ignore_regexp}) {
174
$options{diff_ignore_regexp} .= "|$1";
176
176
} elsif (m/^-(?:I|-tar-ignore=)(.+)$/) {
177
push @{$options{'tar_ignore'}}, $1;
177
push @{$options{tar_ignore}}, $1;
178
178
} elsif (m/^-(?:I|-tar-ignore)$/) {
179
179
unless ($tar_ignore_default_pattern_done) {
180
push @{$options{'tar_ignore'}}, @Dpkg::Source::Package::tar_ignore_default_pattern;
180
push @{$options{tar_ignore}}, @Dpkg::Source::Package::tar_ignore_default_pattern;
181
181
# Prevent adding multiple times
182
182
$tar_ignore_default_pattern_done = 1;
184
184
} elsif (m/^--no-copy$/) {
185
$options{'copy_orig_tarballs'} = 0;
185
$options{copy_orig_tarballs} = 0;
186
186
} elsif (m/^--no-check$/) {
187
$options{'no_check'} = 1;
187
$options{no_check} = 1;
188
188
} elsif (m/^--require-valid-signature$/) {
189
$options{'require_valid_signature'} = 1;
189
$options{require_valid_signature} = 1;
190
190
} elsif (m/^-V(\w[-:0-9A-Za-z]*)[=:](.*)$/s) {
191
191
$substvars->set($1, $2);
192
192
} elsif (m/^-T(.*)$/) {
213
unless (defined($options{'opmode'})) {
214
usageerr(_g("need a command (-x, -b, --before-build, --after-build, --print-format, --commit)"));
213
unless (defined($options{opmode})) {
214
usageerr(_g('need a command (-x, -b, --before-build, --after-build, --print-format, --commit)'));
217
if ($options{'opmode'} =~ /^(-b|--print-format|--(before|after)-build|--commit)$/) {
217
if ($options{opmode} =~ /^(-b|--print-format|--(before|after)-build|--commit)$/) {
219
$options{'ARGV'} = \@ARGV;
219
$options{ARGV} = \@ARGV;
221
221
$changelogfile ||= "$dir/debian/changelog";
222
222
$controlfile ||= "$dir/debian/control";
224
224
my %ch_options = (file => $changelogfile);
225
$ch_options{"changelogformat"} = $changelogformat if $changelogformat;
225
$ch_options{changelogformat} = $changelogformat if $changelogformat;
226
226
my $changelog = changelog_parse(%ch_options);
227
227
my $control = Dpkg::Control::Info->new($controlfile);
229
229
my $srcpkg = Dpkg::Source::Package->new(options => \%options);
230
my $fields = $srcpkg->{'fields'};
230
my $fields = $srcpkg->{fields};
237
237
my $src_fields = $control->get_source();
238
238
error(_g("%s doesn't contain any information about the source package"),
239
239
$controlfile) unless defined $src_fields;
240
my $src_sect = $src_fields->{'Section'} || "unknown";
241
my $src_prio = $src_fields->{'Priority'} || "unknown";
242
foreach $_ (keys %{$src_fields}) {
240
my $src_sect = $src_fields->{'Section'} || 'unknown';
241
my $src_prio = $src_fields->{'Priority'} || 'unknown';
242
foreach (keys %{$src_fields}) {
243
243
my $v = $src_fields->{$_};
244
244
if (m/^Source$/i) {
245
245
set_source_package($v);
251
251
my $type = field_get_dep_type($_);
252
252
$dep = deps_parse($v, build_dep => 1, union => $type eq 'union');
253
error(_g("error occurred while parsing %s"), $_) unless defined $dep;
253
error(_g('error occurred while parsing %s'), $_) unless defined $dep;
254
254
my $facts = Dpkg::Deps::KnownFacts->new();
255
255
$dep->simplify_deps($facts);
256
256
$dep->sort() if $type eq 'union';
268
268
my $prio = $pkg->{'Priority'} || $src_prio;
269
269
my $type = $pkg->{'Package-Type'} ||
270
270
$pkg->get_custom_field('Package-Type') || 'deb';
271
push @pkglist, sprintf("%s %s %s %s", $p, $type, $sect, $prio);
271
push @pkglist, sprintf('%s %s %s %s', $p, $type, $sect, $prio);
272
272
push(@binarypackages,$p);
273
foreach $_ (keys %{$pkg}) {
273
foreach (keys %{$pkg}) {
274
274
my $v = $pkg->{$_};
275
275
if (m/^Architecture$/) {
276
276
# Gather all binary architectures in one set. 'any' and 'all'
283
283
error(_g("`%s' is not a legal architecture string"),
285
285
unless $a =~ /^[\w-]+$/;
286
error(_g("architecture %s only allowed on its " .
286
error(_g('architecture %s only allowed on its ' .
287
287
"own (list for package %s is `%s')"),
289
if grep($a eq $_, 'any', 'all');
289
if $a eq 'any' or $a eq 'all';
290
290
push(@sourcearch, $a) unless $archadded{$a}++;
300
300
unless (scalar(@pkglist)) {
301
301
error(_g("%s doesn't list any binary package"), $controlfile);
303
if (grep($_ eq 'any', @sourcearch)) {
303
if (any { $_ eq 'any' } @sourcearch) {
304
304
# If we encounter one 'any' then the other arches become insignificant
305
305
# except for 'all' that must also be kept
306
if (grep($_ eq 'all', @sourcearch)) {
307
@sourcearch = ('any', 'all');
306
if (any { $_ eq 'all' } @sourcearch) {
307
@sourcearch = qw(any all);
309
@sourcearch = ('any');
309
@sourcearch = qw(any);
312
# Minimize arch list, by remoing arches already covered by wildcards
313
my @arch_wildcards = grep(debarch_is_wildcard($_), @sourcearch);
312
# Minimize arch list, by removing arches already covered by wildcards
313
my @arch_wildcards = grep { debarch_is_wildcard($_) } @sourcearch;
314
314
my @mini_sourcearch = @arch_wildcards;
315
315
foreach my $arch (@sourcearch) {
316
if (!grep(debarch_is($arch, $_), @arch_wildcards)) {
316
if (none { debarch_is($arch, $_) } @arch_wildcards) {
317
317
push @mini_sourcearch, $arch;
334
334
error($error) unless $ok;
335
335
$fields->{$_} = $v;
336
336
} elsif (m/^Binary-Only$/) {
337
error(_g("building source for a binary-only release"))
338
if $v eq "yes" and $options{'opmode'} eq "-b";
337
error(_g('building source for a binary-only release'))
338
if $v eq 'yes' and $options{opmode} eq '-b';
339
339
} elsif (m/^Maintainer$/i) {
340
340
# Do not replace the field coming from the source entry
342
342
field_transfer_single($changelog, $fields);
346
346
$fields->{'Binary'} = join(', ', @binarypackages);
347
347
# Avoid overly long line by splitting over multiple lines
348
348
if (length($fields->{'Binary'}) > 980) {
352
352
# Select the format to use
353
353
if (not defined $build_format) {
354
354
if (-e "$dir/debian/source/format") {
355
open(FORMAT, "<", "$dir/debian/source/format") ||
356
syserr(_g("cannot read %s"), "$dir/debian/source/format");
357
$build_format = <FORMAT>;
355
open(my $format_fh, '<', "$dir/debian/source/format") ||
356
syserr(_g('cannot read %s'), "$dir/debian/source/format");
357
$build_format = <$format_fh>;
358
358
chomp($build_format) if defined $build_format;
359
error(_g("%s is empty"), "$dir/debian/source/format")
359
error(_g('%s is empty'), "$dir/debian/source/format")
360
360
unless defined $build_format and length $build_format;
363
warning(_g("no source format specified in %s, " .
364
"see dpkg-source(1)"), "debian/source/format")
365
if $options{'opmode'} eq "-b";
366
$build_format = "1.0";
363
warning(_g('no source format specified in %s, ' .
364
'see dpkg-source(1)'), 'debian/source/format')
365
if $options{opmode} eq '-b';
366
$build_format = '1.0';
369
369
$fields->{'Format'} = $build_format;
372
372
$srcpkg->init_options();
373
373
$srcpkg->parse_cmdline_options(@cmdline_options);
375
if ($options{'opmode'} eq "--print-format") {
375
if ($options{opmode} eq '--print-format') {
376
376
print $fields->{'Format'} . "\n";
378
} elsif ($options{'opmode'} eq "--before-build") {
378
} elsif ($options{opmode} eq '--before-build') {
379
379
$srcpkg->before_build($dir);
381
} elsif ($options{'opmode'} eq "--after-build") {
381
} elsif ($options{opmode} eq '--after-build') {
382
382
$srcpkg->after_build($dir);
384
} elsif ($options{'opmode'} eq "--commit") {
384
} elsif ($options{opmode} eq '--commit') {
385
385
$srcpkg->commit($dir);
394
394
info(_g("using source format `%s'"), $fields->{'Format'});
395
run_vendor_hook("before-source-build", $srcpkg);
395
run_vendor_hook('before-source-build', $srcpkg);
396
396
# Build the files (.tar.gz, .diff.gz, etc)
397
397
$srcpkg->build($dir);
400
my $dscname = $srcpkg->get_basename(1) . ".dsc";
401
info(_g("building %s in %s"), $sourcepackage, $dscname);
400
my $dscname = $srcpkg->get_basename(1) . '.dsc';
401
info(_g('building %s in %s'), $sourcepackage, $dscname);
402
402
$srcpkg->write_dsc(filename => $dscname,
403
403
remove => \%remove,
404
404
override => \%override,
405
405
substvars => $substvars);
408
} elsif ($options{'opmode'} eq '-x') {
408
} elsif ($options{opmode} eq '-x') {
410
410
# Check command line
411
411
unless (scalar(@ARGV)) {
412
usageerr(_g("-x needs at least one argument, the .dsc"));
412
usageerr(_g('-x needs at least one argument, the .dsc'));
414
414
if (scalar(@ARGV) > 2) {
415
usageerr(_g("-x takes no more than two arguments"));
415
usageerr(_g('-x takes no more than two arguments'));
417
417
my $dsc = shift(@ARGV);
419
usageerr(_g("-x needs the .dsc file as first argument, not a directory"));
419
usageerr(_g('-x needs the .dsc file as first argument, not a directory'));
422
422
# Create the object that does everything
433
433
$newdirectory = File::Spec->catdir(shift(@ARGV));
434
434
if (-e $newdirectory) {
435
error(_g("unpack target exists: %s"), $newdirectory);
435
error(_g('unpack target exists: %s'), $newdirectory);
439
439
# Various checks before unpacking
440
unless ($options{'no_check'}) {
440
unless ($options{no_check}) {
441
441
if ($srcpkg->is_signed()) {
442
442
$srcpkg->check_signature();
444
if ($options{'require_valid_signature'}) {
444
if ($options{require_valid_signature}) {
445
445
error(_g("%s doesn't contain a valid OpenPGP signature"), $dsc);
447
warning(_g("extracting unsigned source package (%s)"), $dsc);
447
warning(_g('extracting unsigned source package (%s)'), $dsc);
450
450
$srcpkg->check_checksums();
453
453
# Unpack the source package (delegated to Dpkg::Source::Package::*)
454
info(_g("extracting %s in %s"), $srcpkg->{'fields'}{'Source'}, $newdirectory);
454
info(_g('extracting %s in %s'), $srcpkg->{fields}{'Source'}, $newdirectory);
455
455
$srcpkg->extract($newdirectory);
461
if (defined($options{'opmode'})) {
462
usageerr(_g("only one of -x, -b or --print-format allowed, and only once"));
461
if (defined($options{opmode})) {
462
usageerr(_g('only one of -x, -b or --print-format allowed, and only once'));
464
$options{'opmode'} = $_[0];
464
$options{opmode} = $_[0];
468
printf _g("Debian %s version %s.\n"), $progname, $version;
468
printf _g("Debian %s version %s.\n"), $Dpkg::PROGNAME, $Dpkg::PROGVERSION;
471
471
This is free software; see the GNU General Public License version 2 or
472
472
later for copying conditions. There is NO warranty.
478
"Usage: %s [<option>...] <command>")
478
'Usage: %s [<option>...] <command>')
481
481
-x <filename>.dsc [<output-dir>]
482
482
extract source package.
483
483
-b <dir> build source package.
484
484
--print-format <dir> print the source format that would be
485
485
used to build the source package.
486
486
--commit [<dir> [<patch-name>]]
487
store upstream changes in a new patch.")
487
store upstream changes in a new patch.')
490
490
-c<control-file> get control info from this file.
509
509
--no-check don't check signature and checksums before unpacking
510
510
--require-valid-signature abort if the package doesn't have a valid signature")
513
513
-?, --help show this help message.
514
--version show the version.")
514
--version show the version.')
516
"More options are available but they depend on the source package format.
517
See dpkg-source(1) for more info.") . "\n",
516
'More options are available but they depend on the source package format.
517
See dpkg-source(1) for more info.') . "\n",
519
519
$Dpkg::Source::Package::diff_ignore_default_regexp,
520
520
join(' ', map { "-I$_" } @Dpkg::Source::Package::tar_ignore_default_pattern),
521
521
compression_get_default(),
522
join(" ", compression_get_list()),
522
join(' ', compression_get_list()),
523
523
compression_get_default_level();