dpkg-buildpackage.pl 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. #!/usr/bin/perl
  2. #
  3. # dpkg-buildpackage
  4. #
  5. # Copyright © 1996 Ian Jackson
  6. # Copyright © 2000 Wichert Akkerman
  7. # Copyright © 2006-2010,2012-2013 Guillem Jover <guillem@debian.org>
  8. # Copyright © 2007 Frank Lichtenheld
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. use strict;
  23. use warnings;
  24. use Carp;
  25. use Cwd;
  26. use File::Basename;
  27. use POSIX qw(:sys_wait_h);
  28. use Dpkg ();
  29. use Dpkg::Gettext;
  30. use Dpkg::ErrorHandling;
  31. use Dpkg::BuildOptions;
  32. use Dpkg::BuildProfiles qw(set_build_profiles);
  33. use Dpkg::Compression;
  34. use Dpkg::Checksums;
  35. use Dpkg::Version;
  36. use Dpkg::Control;
  37. use Dpkg::Changelog::Parse;
  38. use Dpkg::Path qw(find_command);
  39. use Dpkg::IPC;
  40. textdomain('dpkg-dev');
  41. sub showversion {
  42. printf _g("Debian %s version %s.\n"), $Dpkg::PROGNAME, $Dpkg::PROGVERSION;
  43. print _g('
  44. This is free software; see the GNU General Public License version 2 or
  45. later for copying conditions. There is NO warranty.
  46. ');
  47. }
  48. sub usage {
  49. printf _g(
  50. 'Usage: %s [<option>...]')
  51. . "\n\n" . _g(
  52. 'Options:
  53. -F (default) normal full build (binaries and sources).
  54. -b binary-only, do not build source.
  55. -B binary-only, no arch-indep files.
  56. -A binary-only, only arch-indep files.
  57. -S source-only, no binary files.
  58. -nc do not clean source tree (implies -b).
  59. -tc clean source tree when finished.
  60. -D (default) check build dependencies and conflicts.
  61. -d do not check build dependencies and conflicts.
  62. -P<profiles> assume given build profiles as active (comma-separated list).
  63. -R<rules> rules file to execute (default is debian/rules).
  64. -T<target> call debian/rules <target> with the proper environment.
  65. --as-root ensure -T calls the target with root rights.
  66. -j[<number>] specify jobs to run simultaneously (passed to <rules>).
  67. -r<gain-root-command>
  68. command to gain root privileges (default is fakeroot).
  69. --check-command=<check-command>
  70. command to check the .changes file (no default).
  71. --check-option=<opt>
  72. pass <opt> to <check-command>.
  73. --hook-<hook-name>=<hook-command>
  74. set <hook-command> as the hook <hook-name>, known hooks:
  75. init preclean source build binary changes postclean
  76. check sign done
  77. -p<sign-command>
  78. command to sign .dsc and/or .changes files
  79. (default is gpg2 or gpg).
  80. -k<keyid> the key to use for signing.
  81. -ap add pause before starting signature process.
  82. -us unsigned source package.
  83. -uc unsigned .changes file.
  84. --force-sign
  85. force signing the resulting files.
  86. --admindir=<directory>
  87. change the administrative directory.
  88. -?, --help show this help message.
  89. --version show the version.')
  90. . "\n\n" . _g(
  91. 'Options passed to dpkg-architecture:
  92. -a<arch> Debian architecture we build for.
  93. -t<system> set GNU system type.')
  94. . "\n\n" . _g(
  95. 'Options passed to dpkg-genchanges:
  96. -si (default) source includes orig if new upstream.
  97. -sa uploaded source always includes orig.
  98. -sd uploaded source is diff and .dsc only.
  99. -v<version> changes since version <version>.
  100. -m<maint> maintainer for package is <maint>.
  101. -e<maint> maintainer for release is <maint>.
  102. -C<descfile> changes are described in <descfile>.
  103. --changes-option=<opt>
  104. pass option <opt> to dpkg-genchanges.')
  105. . "\n\n" . _g(
  106. 'Options passed to dpkg-source:
  107. -sn force Debian native source format.
  108. -s[sAkurKUR] see dpkg-source for explanation.
  109. -z<level> compression level to use for source.
  110. -Z<compressor> compression to use for source (gz|xz|bzip2|lzma).
  111. -i[<regex>] ignore diffs of files matching regex.
  112. -I[<pattern>] filter out files when building tarballs.
  113. --source-option=<opt>
  114. pass option <opt> to dpkg-source.
  115. '), $Dpkg::PROGNAME;
  116. }
  117. my $admindir;
  118. my @debian_rules = ('debian/rules');
  119. my @rootcommand = ();
  120. my $signcommand;
  121. my $noclean;
  122. my $cleansource;
  123. my $parallel;
  124. my $checkbuilddep = 1;
  125. my @checkbuilddep_opts;
  126. my @source_opts;
  127. my $check_command = $ENV{DEB_CHECK_COMMAND};
  128. my @check_opts;
  129. my $signpause;
  130. my $signkey = $ENV{DEB_SIGN_KEYID};
  131. my $signforce = 0;
  132. my $signreleased = 1;
  133. my $signsource = 1;
  134. my $signchanges = 1;
  135. my $buildtarget = 'build';
  136. my $binarytarget = 'binary';
  137. my $targetarch = '';
  138. my $targetgnusystem = '';
  139. my @build_profiles = ();
  140. my $call_target = '';
  141. my $call_target_as_root = 0;
  142. my $since;
  143. my $maint;
  144. my $changedby;
  145. my $desc;
  146. my @changes_opts;
  147. my @hook_names = qw(
  148. init preclean source build binary changes postclean check sign done
  149. );
  150. my %hook;
  151. $hook{$_} = undef foreach @hook_names;
  152. use constant BUILD_DEFAULT => 1;
  153. use constant BUILD_SOURCE => 2;
  154. use constant BUILD_ARCH_DEP => 4;
  155. use constant BUILD_ARCH_INDEP => 8;
  156. use constant BUILD_BINARY => BUILD_ARCH_DEP | BUILD_ARCH_INDEP;
  157. use constant BUILD_ALL => BUILD_BINARY | BUILD_SOURCE;
  158. my $include = BUILD_ALL | BUILD_DEFAULT;
  159. sub build_normal() { return ($include & BUILD_ALL) == BUILD_ALL; }
  160. sub build_sourceonly() { return $include == BUILD_SOURCE; }
  161. sub build_binaryonly() { return !($include & BUILD_SOURCE); }
  162. sub build_binaryindep() { return ($include == BUILD_ARCH_INDEP); }
  163. sub build_opt {
  164. if ($include == BUILD_BINARY) {
  165. return '-b';
  166. } elsif ($include == BUILD_ARCH_DEP) {
  167. return '-B';
  168. } elsif ($include == BUILD_ARCH_INDEP) {
  169. return '-A';
  170. } elsif ($include == BUILD_SOURCE) {
  171. return '-S';
  172. } else {
  173. croak "build_opt called with include=$include";
  174. }
  175. }
  176. my $build_opts = Dpkg::BuildOptions->new();
  177. if ($build_opts->has('nocheck')) {
  178. $check_command = undef;
  179. }
  180. while (@ARGV) {
  181. $_ = shift @ARGV;
  182. if (/^(--help|-\?)$/) {
  183. usage;
  184. exit 0;
  185. } elsif (/^--version$/) {
  186. showversion;
  187. exit 0;
  188. } elsif (/^--admindir$/) {
  189. $admindir = shift @ARGV;
  190. } elsif (/^--admindir=(.*)$/) {
  191. $admindir = $1;
  192. } elsif (/^--source-option=(.*)$/) {
  193. push @source_opts, $1;
  194. } elsif (/^--changes-option=(.*)$/) {
  195. push @changes_opts, $1;
  196. } elsif (/^-j(\d*)$/) {
  197. $parallel = $1 || '';
  198. } elsif (/^-r(.*)$/) {
  199. @rootcommand = split /\s+/, $1;
  200. } elsif (/^--check-command=(.*)$/) {
  201. $check_command = $1;
  202. } elsif (/^--check-option=(.*)$/) {
  203. push @check_opts, $1;
  204. } elsif (/^--hook-(.+)=(.*)$/) {
  205. my ($hook_name, $hook_cmd) = ($1, $2);
  206. usageerr(_g('unknown hook name %s'), $hook_name)
  207. if not exists $hook{$hook_name};
  208. usageerr(_g('missing hook %s command'), $hook_name)
  209. if not defined $hook_cmd;
  210. $hook{$hook_name} = $hook_cmd;
  211. } elsif (/^-p(.*)$/) {
  212. $signcommand = $1;
  213. } elsif (/^-k(.*)$/) {
  214. $signkey = $1;
  215. } elsif (/^-([dD])$/) {
  216. $checkbuilddep = ($1 eq 'D');
  217. } elsif (/^-s(gpg|pgp)$/) {
  218. # Deprecated option
  219. warning(_g('-s%s is deprecated; always using gpg style interface'), $1);
  220. } elsif (/^--force-sign$/) {
  221. $signforce = 1;
  222. } elsif (/^-us$/) {
  223. $signsource = 0;
  224. } elsif (/^-uc$/) {
  225. $signchanges = 0;
  226. } elsif (/^-ap$/) {
  227. $signpause = 1;
  228. } elsif (/^-a(.*)$/) {
  229. $targetarch = $1;
  230. } elsif (/^-P(.*)$/) {
  231. @build_profiles = split /,/, $1;
  232. } elsif (/^-s[iad]$/) {
  233. push @changes_opts, $_;
  234. } elsif (/^-(?:s[insAkurKUR]|[zZ].*|i.*|I.*)$/) {
  235. push @source_opts, $_; # passed to dpkg-source
  236. } elsif (/^-tc$/) {
  237. $cleansource = 1;
  238. } elsif (/^-t(.*)$/) {
  239. $targetgnusystem = $1; # Order DOES matter!
  240. } elsif (/^(--target|-T)$/) {
  241. $call_target = shift @ARGV;
  242. } elsif (/^(--target=|-T)(.+)$/) {
  243. $call_target = $2;
  244. } elsif (/^--as-root$/) {
  245. $call_target_as_root = 1;
  246. } elsif (/^-nc$/) {
  247. $noclean = 1;
  248. } elsif (/^-b$/) {
  249. usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
  250. if build_sourceonly;
  251. $include = BUILD_BINARY;
  252. push @changes_opts, '-b';
  253. @checkbuilddep_opts = ();
  254. $buildtarget = 'build';
  255. $binarytarget = 'binary';
  256. } elsif (/^-B$/) {
  257. usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
  258. if build_sourceonly;
  259. $include = BUILD_ARCH_DEP;
  260. push @changes_opts, '-B';
  261. @checkbuilddep_opts = qw(-B);
  262. $buildtarget = 'build-arch';
  263. $binarytarget = 'binary-arch';
  264. } elsif (/^-A$/) {
  265. usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
  266. if build_sourceonly;
  267. $include = BUILD_ARCH_INDEP;
  268. push @changes_opts, '-A';
  269. @checkbuilddep_opts = qw(-A);
  270. $buildtarget = 'build-indep';
  271. $binarytarget = 'binary-indep';
  272. } elsif (/^-S$/) {
  273. usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
  274. if build_binaryonly;
  275. $include = BUILD_SOURCE;
  276. push @changes_opts, '-S';
  277. @checkbuilddep_opts = qw(-A -B);
  278. } elsif (/^-F$/) {
  279. usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
  280. if not build_normal;
  281. $include = BUILD_ALL;
  282. @checkbuilddep_opts = ();
  283. } elsif (/^-v(.*)$/) {
  284. $since = $1;
  285. } elsif (/^-m(.*)$/) {
  286. $maint = $1;
  287. } elsif (/^-e(.*)$/) {
  288. $changedby = $1;
  289. } elsif (/^-C(.*)$/) {
  290. $desc = $1;
  291. } elsif (m/^-[EW]$/) {
  292. # Deprecated option
  293. warning(_g('-E and -W are deprecated, they are without effect'));
  294. } elsif (/^-R(.*)$/) {
  295. @debian_rules = split /\s+/, $1;
  296. } else {
  297. usageerr(_g('unknown option or argument %s'), $_);
  298. }
  299. }
  300. if ($noclean) {
  301. # -nc without -b/-B/-A/-S/-F implies -b
  302. $include = BUILD_BINARY if ($include & BUILD_DEFAULT);
  303. }
  304. if ($< == 0) {
  305. warning(_g('using a gain-root-command while being root')) if (@rootcommand);
  306. } else {
  307. push @rootcommand, 'fakeroot' unless @rootcommand;
  308. }
  309. if (@rootcommand and not find_command($rootcommand[0])) {
  310. if ($rootcommand[0] eq 'fakeroot' and $< != 0) {
  311. error(_g("fakeroot not found, either install the fakeroot\n" .
  312. 'package, specify a command with the -r option, ' .
  313. 'or run this as root'));
  314. } else {
  315. error(_g("gain-root-commmand '%s' not found"), $rootcommand[0]);
  316. }
  317. }
  318. if ($check_command and not find_command($check_command)) {
  319. error(_g("check-commmand '%s' not found"), $check_command);
  320. }
  321. if ($signcommand) {
  322. if (!find_command($signcommand)) {
  323. error(_g("sign-commmand '%s' not found"), $signcommand);
  324. }
  325. } elsif (($ENV{GNUPGHOME} && -e $ENV{GNUPGHOME}) ||
  326. ($ENV{HOME} && -e "$ENV{HOME}/.gnupg")) {
  327. if (find_command('gpg2')) {
  328. $signcommand = 'gpg2';
  329. } elsif (find_command('gpg')) {
  330. $signcommand = 'gpg';
  331. }
  332. }
  333. if (defined $parallel) {
  334. $parallel = $build_opts->get('parallel') if $build_opts->has('parallel');
  335. $ENV{MAKEFLAGS} ||= '';
  336. $ENV{MAKEFLAGS} .= " -j$parallel";
  337. $build_opts->set('parallel', $parallel);
  338. $build_opts->export();
  339. }
  340. set_build_profiles(@build_profiles) if @build_profiles;
  341. my $cwd = cwd();
  342. my $dir = basename($cwd);
  343. my $changelog = changelog_parse();
  344. my $pkg = mustsetvar($changelog->{source}, _g('source package'));
  345. my $version = mustsetvar($changelog->{version}, _g('source version'));
  346. my $v = Dpkg::Version->new($version);
  347. my ($ok, $error) = version_check($v);
  348. error($error) unless $ok;
  349. my $sversion = $v->as_string(omit_epoch => 1);
  350. my $uversion = $v->version();
  351. my $distribution = mustsetvar($changelog->{distribution}, _g('source distribution'));
  352. my $maintainer;
  353. if ($changedby) {
  354. $maintainer = $changedby;
  355. } elsif ($maint) {
  356. $maintainer = $maint;
  357. } else {
  358. $maintainer = mustsetvar($changelog->{maintainer}, _g('source changed by'));
  359. }
  360. open my $arch_env, '-|', 'dpkg-architecture', "-a$targetarch",
  361. "-t$targetgnusystem", '-f' or subprocerr('dpkg-architecture');
  362. while ($_ = <$arch_env>) {
  363. chomp;
  364. my ($key, $value) = split /=/, $_, 2;
  365. $ENV{$key} = $value;
  366. }
  367. close $arch_env or subprocerr('dpkg-architecture');
  368. my $arch;
  369. if (build_sourceonly) {
  370. $arch = 'source';
  371. } elsif (build_binaryindep) {
  372. $arch = 'all';
  373. } else {
  374. $arch = mustsetvar($ENV{DEB_HOST_ARCH}, _g('host architecture'));
  375. }
  376. my $pv = "${pkg}_$sversion";
  377. my $pva = "${pkg}_${sversion}_$arch";
  378. if (not $signcommand) {
  379. $signsource = 0;
  380. $signchanges = 0;
  381. } elsif ($signforce) {
  382. $signsource = 1;
  383. $signchanges = 1;
  384. } elsif (($signsource or $signchanges) and $distribution eq 'UNRELEASED') {
  385. $signreleased = 0;
  386. $signsource = 0;
  387. $signchanges = 0;
  388. }
  389. if ($signsource && build_binaryonly) {
  390. $signsource = 0;
  391. }
  392. #
  393. # Preparation of environment stops here
  394. #
  395. run_hook('init', 1);
  396. if (not -x 'debian/rules') {
  397. warning(_g('debian/rules is not executable; fixing that'));
  398. chmod(0755, 'debian/rules'); # No checks of failures, non fatal
  399. }
  400. unless ($call_target) {
  401. chdir('..') or syserr('chdir ..');
  402. withecho('dpkg-source', @source_opts, '--before-build', $dir);
  403. chdir($dir) or syserr("chdir $dir");
  404. }
  405. if ($checkbuilddep) {
  406. push @checkbuilddep_opts, "--admindir=$admindir" if $admindir;
  407. system('dpkg-checkbuilddeps', @checkbuilddep_opts);
  408. if (not WIFEXITED($?)) {
  409. subprocerr('dpkg-checkbuilddeps');
  410. } elsif (WEXITSTATUS($?)) {
  411. warning(_g('build dependencies/conflicts unsatisfied; aborting'));
  412. warning(_g('(Use -d flag to override.)'));
  413. if (build_sourceonly) {
  414. warning(_g('this is currently a non-fatal warning with -S, but ' .
  415. 'will probably become fatal in the future'));
  416. } else {
  417. exit 3;
  418. }
  419. }
  420. }
  421. if ($call_target) {
  422. if ($call_target_as_root or
  423. $call_target =~ /^(clean|binary(|-arch|-indep))$/)
  424. {
  425. withecho(@rootcommand, @debian_rules, $call_target);
  426. } else {
  427. withecho(@debian_rules, $call_target);
  428. }
  429. exit 0;
  430. }
  431. run_hook('preclean', ! $noclean);
  432. unless ($noclean) {
  433. withecho(@rootcommand, @debian_rules, 'clean');
  434. }
  435. run_hook('source', $include & BUILD_SOURCE);
  436. if ($include & BUILD_SOURCE) {
  437. warning(_g('building a source package without cleaning up as you asked; ' .
  438. 'it might contain undesired files')) if $noclean;
  439. chdir('..') or syserr('chdir ..');
  440. withecho('dpkg-source', @source_opts, '-b', $dir);
  441. chdir($dir) or syserr("chdir $dir");
  442. }
  443. run_hook('build', $include & BUILD_BINARY);
  444. if ($buildtarget ne 'build' and scalar(@debian_rules) == 1) {
  445. # Verify that build-{arch,indep} are supported. If not, fallback to build.
  446. # This is a temporary measure to not break too many packages on a flag day.
  447. my $pid = spawn(exec => [ 'make', '-f', @debian_rules, '-qn', $buildtarget ],
  448. from_file => '/dev/null', to_file => '/dev/null',
  449. error_to_file => '/dev/null');
  450. my $cmdline = "make -f @debian_rules -qn $buildtarget";
  451. wait_child($pid, nocheck => 1, cmdline => $cmdline);
  452. my $exitcode = WEXITSTATUS($?);
  453. subprocerr($cmdline) unless WIFEXITED($?);
  454. if ($exitcode == 2) {
  455. warning(_g("%s must be updated to support the 'build-arch' and " .
  456. "'build-indep' targets (at least '%s' seems to be " .
  457. 'missing)'), "@debian_rules", $buildtarget);
  458. $buildtarget = 'build';
  459. }
  460. }
  461. if ($include & BUILD_BINARY) {
  462. withecho(@debian_rules, $buildtarget);
  463. run_hook('binary', 1);
  464. withecho(@rootcommand, @debian_rules, $binarytarget);
  465. }
  466. run_hook('changes', 1);
  467. push @changes_opts, "-m$maint" if defined $maint;
  468. push @changes_opts, "-e$changedby" if defined $changedby;
  469. push @changes_opts, "-v$since" if defined $since;
  470. push @changes_opts, "-C$desc" if defined $desc;
  471. my $chg = "../$pva.changes";
  472. my $changes = Dpkg::Control->new(type => CTRL_FILE_CHANGES);
  473. print { *STDERR } " dpkg-genchanges @changes_opts >$chg\n";
  474. open my $changes_fh, '-|', 'dpkg-genchanges', @changes_opts
  475. or subprocerr('dpkg-genchanges');
  476. $changes->parse($changes_fh, _g('parse changes file'));
  477. $changes->save($chg);
  478. close $changes_fh or subprocerr(_g('dpkg-genchanges'));
  479. run_hook('postclean', $cleansource);
  480. if ($cleansource) {
  481. withecho(@rootcommand, @debian_rules, 'clean');
  482. }
  483. chdir('..') or syserr('chdir ..');
  484. withecho('dpkg-source', @source_opts, '--after-build', $dir);
  485. chdir($dir) or syserr("chdir $dir");
  486. printf "$Dpkg::PROGNAME: %s\n", describe_build($changes->{'Files'});
  487. run_hook('check', $check_command);
  488. if ($check_command) {
  489. withecho($check_command, @check_opts, $chg);
  490. }
  491. if ($signpause && ($signchanges || $signsource)) {
  492. print _g("Press the return key to start signing process\n");
  493. getc();
  494. }
  495. run_hook('sign', $signsource || $signchanges);
  496. if ($signsource) {
  497. if (signfile("$pv.dsc")) {
  498. error(_g('failed to sign .dsc and .changes file'));
  499. }
  500. # Recompute the checksums as the .dsc has changed now.
  501. my $checksums = Dpkg::Checksums->new();
  502. $checksums->add_from_control($changes);
  503. $checksums->add_from_file("../$pv.dsc", update => 1, key => "$pv.dsc");
  504. $checksums->export_to_control($changes);
  505. delete $changes->{'Checksums-Md5'};
  506. my $md5sum_regex = checksums_get_property('md5', 'regex');
  507. my $dsc_md5sum = $checksums->get_checksum("$pv.dsc", 'md5');
  508. my $dsc_size = $checksums->get_size("$pv.dsc");
  509. my $dsc_files_regex = qr/$md5sum_regex\s+\d+\s+(\S+\s+\S+\s+\Q$pv\E\.dsc)/;
  510. $changes->{'Files'} =~ s/^$dsc_files_regex$/$dsc_md5sum $dsc_size $1/m;
  511. $changes->save($chg);
  512. }
  513. if ($signchanges && signfile("$pva.changes")) {
  514. error(_g('failed to sign .changes file'));
  515. }
  516. if (not $signreleased) {
  517. warning(_g('not signing UNRELEASED build; use --force-sign to override'));
  518. }
  519. run_hook('done', 1);
  520. sub mustsetvar {
  521. my ($var, $text) = @_;
  522. error(_g('unable to determine %s'), $text)
  523. unless defined($var);
  524. print "$Dpkg::PROGNAME: $text $var\n";
  525. return $var;
  526. }
  527. sub withecho {
  528. print { *STDERR } " @_\n";
  529. system(@_)
  530. and subprocerr("@_");
  531. }
  532. sub run_hook {
  533. my ($name, $enabled) = @_;
  534. my $cmd = $hook{$name};
  535. return if not $cmd;
  536. print { *STDERR } "$Dpkg::PROGNAME: running hook $name\n";
  537. my %hook_vars = (
  538. '%' => '%',
  539. 'a' => $enabled ? 1 : 0,
  540. 'p' => $pkg,
  541. 'v' => $version,
  542. 's' => $sversion,
  543. 'u' => $uversion,
  544. );
  545. $cmd =~ s/\%(.)/exists $hook_vars{$1} ? $hook_vars{$1} :
  546. (warning(_g('unknown %% substitution in hook: %%%s'), $1), "\%$1")/eg;
  547. withecho($cmd);
  548. }
  549. sub signfile {
  550. my ($file) = @_;
  551. print { *STDERR } " signfile $file\n";
  552. my $qfile = quotemeta($file);
  553. system("(cat ../$qfile ; echo '') | " .
  554. "$signcommand --utf8-strings --local-user " .
  555. quotemeta($signkey || $maintainer) .
  556. " --clearsign --armor --textmode > ../$qfile.asc");
  557. my $status = $?;
  558. unless ($status) {
  559. system('mv', '--', "../$file.asc", "../$file")
  560. and subprocerr('mv');
  561. } else {
  562. system('rm', '-f', "../$file.asc")
  563. and subprocerr('rm -f');
  564. }
  565. print "\n";
  566. return $status
  567. }
  568. sub fileomitted {
  569. my ($files, $regex) = @_;
  570. return $files !~ /$regex/
  571. }
  572. sub describe_build {
  573. my ($files) = @_;
  574. my $ext = compression_get_file_extension_regex();
  575. if (fileomitted($files, qr/\.deb/)) {
  576. # source-only upload
  577. if (fileomitted($files, qr/\.diff\.$ext/) and
  578. fileomitted($files, qr/\.debian\.tar\.$ext/)) {
  579. return _g('source-only upload: Debian-native package');
  580. } elsif (fileomitted($files, qr/\.orig\.tar\.$ext/)) {
  581. return _g('source-only, diff-only upload (original source NOT included)');
  582. } else {
  583. return _g('source-only upload (original source is included)');
  584. }
  585. } elsif (fileomitted($files, qr/\.dsc/)) {
  586. return _g('binary-only upload (no source included)');
  587. } elsif (fileomitted($files, qr/\.diff\.$ext/) and
  588. fileomitted($files, qr/\.debian\.tar\.$ext/)) {
  589. return _g('full upload; Debian-native package (full source is included)');
  590. } elsif (fileomitted($files, qr/\.orig\.tar\.$ext/)) {
  591. return _g('binary and diff upload (original source NOT included)');
  592. } else {
  593. return _g('full upload (original source is included)');
  594. }
  595. }