dpkg-buildpackage.pl 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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. my $arg = $1;
  200. @rootcommand = split /\s+/, $arg;
  201. } elsif (/^--check-command=(.*)$/) {
  202. $check_command = $1;
  203. } elsif (/^--check-option=(.*)$/) {
  204. push @check_opts, $1;
  205. } elsif (/^--hook-(.+)=(.*)$/) {
  206. my ($hook_name, $hook_cmd) = ($1, $2);
  207. usageerr(_g('unknown hook name %s'), $hook_name)
  208. if not exists $hook{$hook_name};
  209. usageerr(_g('missing hook %s command'), $hook_name)
  210. if not defined $hook_cmd;
  211. $hook{$hook_name} = $hook_cmd;
  212. } elsif (/^-p(.*)$/) {
  213. $signcommand = $1;
  214. } elsif (/^-k(.*)$/) {
  215. $signkey = $1;
  216. } elsif (/^-([dD])$/) {
  217. $checkbuilddep = ($1 eq 'D');
  218. } elsif (/^-s(gpg|pgp)$/) {
  219. # Deprecated option
  220. warning(_g('-s%s is deprecated; always using gpg style interface'), $1);
  221. } elsif (/^--force-sign$/) {
  222. $signforce = 1;
  223. } elsif (/^-us$/) {
  224. $signsource = 0;
  225. } elsif (/^-uc$/) {
  226. $signchanges = 0;
  227. } elsif (/^-ap$/) {
  228. $signpause = 1;
  229. } elsif (/^-a(.*)$/) {
  230. $targetarch = $1;
  231. } elsif (/^-P(.*)$/) {
  232. my $arg = $1;
  233. @build_profiles = split /,/, $arg;
  234. } elsif (/^-s[iad]$/) {
  235. push @changes_opts, $_;
  236. } elsif (/^-(?:s[insAkurKUR]|[zZ].*|i.*|I.*)$/) {
  237. push @source_opts, $_; # passed to dpkg-source
  238. } elsif (/^-tc$/) {
  239. $cleansource = 1;
  240. } elsif (/^-t(.*)$/) {
  241. $targetgnusystem = $1; # Order DOES matter!
  242. } elsif (/^(?:--target|-T)$/) {
  243. $call_target = shift @ARGV;
  244. } elsif (/^(?:--target=|-T)(.+)$/) {
  245. $call_target = $1;
  246. } elsif (/^--as-root$/) {
  247. $call_target_as_root = 1;
  248. } elsif (/^-nc$/) {
  249. $noclean = 1;
  250. } elsif (/^-b$/) {
  251. usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
  252. if build_sourceonly;
  253. $include = BUILD_BINARY;
  254. push @changes_opts, '-b';
  255. @checkbuilddep_opts = ();
  256. $buildtarget = 'build';
  257. $binarytarget = 'binary';
  258. } elsif (/^-B$/) {
  259. usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
  260. if build_sourceonly;
  261. $include = BUILD_ARCH_DEP;
  262. push @changes_opts, '-B';
  263. @checkbuilddep_opts = qw(-B);
  264. $buildtarget = 'build-arch';
  265. $binarytarget = 'binary-arch';
  266. } elsif (/^-A$/) {
  267. usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
  268. if build_sourceonly;
  269. $include = BUILD_ARCH_INDEP;
  270. push @changes_opts, '-A';
  271. @checkbuilddep_opts = qw(-A);
  272. $buildtarget = 'build-indep';
  273. $binarytarget = 'binary-indep';
  274. } elsif (/^-S$/) {
  275. usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
  276. if build_binaryonly;
  277. $include = BUILD_SOURCE;
  278. push @changes_opts, '-S';
  279. @checkbuilddep_opts = qw(-A -B);
  280. } elsif (/^-F$/) {
  281. usageerr(_g('cannot combine %s and %s'), build_opt(), $_)
  282. if not build_normal;
  283. $include = BUILD_ALL;
  284. @checkbuilddep_opts = ();
  285. } elsif (/^-v(.*)$/) {
  286. $since = $1;
  287. } elsif (/^-m(.*)$/) {
  288. $maint = $1;
  289. } elsif (/^-e(.*)$/) {
  290. $changedby = $1;
  291. } elsif (/^-C(.*)$/) {
  292. $desc = $1;
  293. } elsif (m/^-[EW]$/) {
  294. # Deprecated option
  295. warning(_g('-E and -W are deprecated, they are without effect'));
  296. } elsif (/^-R(.*)$/) {
  297. my $arg = $1;
  298. @debian_rules = split /\s+/, $arg;
  299. } else {
  300. usageerr(_g('unknown option or argument %s'), $_);
  301. }
  302. }
  303. if ($noclean) {
  304. # -nc without -b/-B/-A/-S/-F implies -b
  305. $include = BUILD_BINARY if ($include & BUILD_DEFAULT);
  306. }
  307. if ($< == 0) {
  308. warning(_g('using a gain-root-command while being root')) if (@rootcommand);
  309. } else {
  310. push @rootcommand, 'fakeroot' unless @rootcommand;
  311. }
  312. if (@rootcommand and not find_command($rootcommand[0])) {
  313. if ($rootcommand[0] eq 'fakeroot' and $< != 0) {
  314. error(_g("fakeroot not found, either install the fakeroot\n" .
  315. 'package, specify a command with the -r option, ' .
  316. 'or run this as root'));
  317. } else {
  318. error(_g("gain-root-commmand '%s' not found"), $rootcommand[0]);
  319. }
  320. }
  321. if ($check_command and not find_command($check_command)) {
  322. error(_g("check-commmand '%s' not found"), $check_command);
  323. }
  324. if ($signcommand) {
  325. if (!find_command($signcommand)) {
  326. error(_g("sign-commmand '%s' not found"), $signcommand);
  327. }
  328. } elsif (($ENV{GNUPGHOME} && -e $ENV{GNUPGHOME}) ||
  329. ($ENV{HOME} && -e "$ENV{HOME}/.gnupg")) {
  330. if (find_command('gpg2')) {
  331. $signcommand = 'gpg2';
  332. } elsif (find_command('gpg')) {
  333. $signcommand = 'gpg';
  334. }
  335. }
  336. if (defined $parallel) {
  337. $parallel = $build_opts->get('parallel') if $build_opts->has('parallel');
  338. $ENV{MAKEFLAGS} ||= '';
  339. $ENV{MAKEFLAGS} .= " -j$parallel";
  340. $build_opts->set('parallel', $parallel);
  341. $build_opts->export();
  342. }
  343. set_build_profiles(@build_profiles) if @build_profiles;
  344. my $cwd = cwd();
  345. my $dir = basename($cwd);
  346. my $changelog = changelog_parse();
  347. my $pkg = mustsetvar($changelog->{source}, _g('source package'));
  348. my $version = mustsetvar($changelog->{version}, _g('source version'));
  349. my $v = Dpkg::Version->new($version);
  350. my ($ok, $error) = version_check($v);
  351. error($error) unless $ok;
  352. my $sversion = $v->as_string(omit_epoch => 1);
  353. my $uversion = $v->version();
  354. my $distribution = mustsetvar($changelog->{distribution}, _g('source distribution'));
  355. my $maintainer;
  356. if ($changedby) {
  357. $maintainer = $changedby;
  358. } elsif ($maint) {
  359. $maintainer = $maint;
  360. } else {
  361. $maintainer = mustsetvar($changelog->{maintainer}, _g('source changed by'));
  362. }
  363. open my $arch_env, '-|', 'dpkg-architecture', "-a$targetarch",
  364. "-t$targetgnusystem", '-f' or subprocerr('dpkg-architecture');
  365. while ($_ = <$arch_env>) {
  366. chomp;
  367. my ($key, $value) = split /=/, $_, 2;
  368. $ENV{$key} = $value;
  369. }
  370. close $arch_env or subprocerr('dpkg-architecture');
  371. my $arch;
  372. if (build_sourceonly) {
  373. $arch = 'source';
  374. } elsif (build_binaryindep) {
  375. $arch = 'all';
  376. } else {
  377. $arch = mustsetvar($ENV{DEB_HOST_ARCH}, _g('host architecture'));
  378. }
  379. my $pv = "${pkg}_$sversion";
  380. my $pva = "${pkg}_${sversion}_$arch";
  381. if (not $signcommand) {
  382. $signsource = 0;
  383. $signchanges = 0;
  384. } elsif ($signforce) {
  385. $signsource = 1;
  386. $signchanges = 1;
  387. } elsif (($signsource or $signchanges) and $distribution eq 'UNRELEASED') {
  388. $signreleased = 0;
  389. $signsource = 0;
  390. $signchanges = 0;
  391. }
  392. if ($signsource && build_binaryonly) {
  393. $signsource = 0;
  394. }
  395. #
  396. # Preparation of environment stops here
  397. #
  398. run_hook('init', 1);
  399. if (not -x 'debian/rules') {
  400. warning(_g('debian/rules is not executable; fixing that'));
  401. chmod(0755, 'debian/rules'); # No checks of failures, non fatal
  402. }
  403. unless ($call_target) {
  404. chdir('..') or syserr('chdir ..');
  405. withecho('dpkg-source', @source_opts, '--before-build', $dir);
  406. chdir($dir) or syserr("chdir $dir");
  407. }
  408. if ($checkbuilddep) {
  409. push @checkbuilddep_opts, "--admindir=$admindir" if $admindir;
  410. system('dpkg-checkbuilddeps', @checkbuilddep_opts);
  411. if (not WIFEXITED($?)) {
  412. subprocerr('dpkg-checkbuilddeps');
  413. } elsif (WEXITSTATUS($?)) {
  414. warning(_g('build dependencies/conflicts unsatisfied; aborting'));
  415. warning(_g('(Use -d flag to override.)'));
  416. if (build_sourceonly) {
  417. warning(_g('this is currently a non-fatal warning with -S, but ' .
  418. 'will probably become fatal in the future'));
  419. } else {
  420. exit 3;
  421. }
  422. }
  423. }
  424. if ($call_target) {
  425. if ($call_target_as_root or
  426. $call_target =~ /^(clean|binary(|-arch|-indep))$/)
  427. {
  428. withecho(@rootcommand, @debian_rules, $call_target);
  429. } else {
  430. withecho(@debian_rules, $call_target);
  431. }
  432. exit 0;
  433. }
  434. run_hook('preclean', ! $noclean);
  435. unless ($noclean) {
  436. withecho(@rootcommand, @debian_rules, 'clean');
  437. }
  438. run_hook('source', $include & BUILD_SOURCE);
  439. if ($include & BUILD_SOURCE) {
  440. warning(_g('building a source package without cleaning up as you asked; ' .
  441. 'it might contain undesired files')) if $noclean;
  442. chdir('..') or syserr('chdir ..');
  443. withecho('dpkg-source', @source_opts, '-b', $dir);
  444. chdir($dir) or syserr("chdir $dir");
  445. }
  446. run_hook('build', $include & BUILD_BINARY);
  447. if ($buildtarget ne 'build' and scalar(@debian_rules) == 1) {
  448. # Verify that build-{arch,indep} are supported. If not, fallback to build.
  449. # This is a temporary measure to not break too many packages on a flag day.
  450. my $pid = spawn(exec => [ 'make', '-f', @debian_rules, '-qn', $buildtarget ],
  451. from_file => '/dev/null', to_file => '/dev/null',
  452. error_to_file => '/dev/null');
  453. my $cmdline = "make -f @debian_rules -qn $buildtarget";
  454. wait_child($pid, nocheck => 1, cmdline => $cmdline);
  455. my $exitcode = WEXITSTATUS($?);
  456. subprocerr($cmdline) unless WIFEXITED($?);
  457. if ($exitcode == 2) {
  458. warning(_g("%s must be updated to support the 'build-arch' and " .
  459. "'build-indep' targets (at least '%s' seems to be " .
  460. 'missing)'), "@debian_rules", $buildtarget);
  461. $buildtarget = 'build';
  462. }
  463. }
  464. if ($include & BUILD_BINARY) {
  465. withecho(@debian_rules, $buildtarget);
  466. run_hook('binary', 1);
  467. withecho(@rootcommand, @debian_rules, $binarytarget);
  468. }
  469. run_hook('changes', 1);
  470. push @changes_opts, "-m$maint" if defined $maint;
  471. push @changes_opts, "-e$changedby" if defined $changedby;
  472. push @changes_opts, "-v$since" if defined $since;
  473. push @changes_opts, "-C$desc" if defined $desc;
  474. my $chg = "../$pva.changes";
  475. my $changes = Dpkg::Control->new(type => CTRL_FILE_CHANGES);
  476. print { *STDERR } " dpkg-genchanges @changes_opts >$chg\n";
  477. open my $changes_fh, '-|', 'dpkg-genchanges', @changes_opts
  478. or subprocerr('dpkg-genchanges');
  479. $changes->parse($changes_fh, _g('parse changes file'));
  480. $changes->save($chg);
  481. close $changes_fh or subprocerr(_g('dpkg-genchanges'));
  482. run_hook('postclean', $cleansource);
  483. if ($cleansource) {
  484. withecho(@rootcommand, @debian_rules, 'clean');
  485. }
  486. chdir('..') or syserr('chdir ..');
  487. withecho('dpkg-source', @source_opts, '--after-build', $dir);
  488. chdir($dir) or syserr("chdir $dir");
  489. printf "$Dpkg::PROGNAME: %s\n", describe_build($changes->{'Files'});
  490. run_hook('check', $check_command);
  491. if ($check_command) {
  492. withecho($check_command, @check_opts, $chg);
  493. }
  494. if ($signpause && ($signchanges || $signsource)) {
  495. print _g("Press the return key to start signing process\n");
  496. getc();
  497. }
  498. run_hook('sign', $signsource || $signchanges);
  499. if ($signsource) {
  500. if (signfile("$pv.dsc")) {
  501. error(_g('failed to sign .dsc and .changes file'));
  502. }
  503. # Recompute the checksums as the .dsc has changed now.
  504. my $checksums = Dpkg::Checksums->new();
  505. $checksums->add_from_control($changes);
  506. $checksums->add_from_file("../$pv.dsc", update => 1, key => "$pv.dsc");
  507. $checksums->export_to_control($changes);
  508. delete $changes->{'Checksums-Md5'};
  509. my $md5sum_regex = checksums_get_property('md5', 'regex');
  510. my $dsc_md5sum = $checksums->get_checksum("$pv.dsc", 'md5');
  511. my $dsc_size = $checksums->get_size("$pv.dsc");
  512. my $dsc_files_regex = qr/$md5sum_regex\s+\d+\s+(\S+\s+\S+\s+\Q$pv\E\.dsc)/;
  513. $changes->{'Files'} =~ s/^$dsc_files_regex$/$dsc_md5sum $dsc_size $1/m;
  514. $changes->save($chg);
  515. }
  516. if ($signchanges && signfile("$pva.changes")) {
  517. error(_g('failed to sign .changes file'));
  518. }
  519. if (not $signreleased) {
  520. warning(_g('not signing UNRELEASED build; use --force-sign to override'));
  521. }
  522. run_hook('done', 1);
  523. sub mustsetvar {
  524. my ($var, $text) = @_;
  525. error(_g('unable to determine %s'), $text)
  526. unless defined($var);
  527. print "$Dpkg::PROGNAME: $text $var\n";
  528. return $var;
  529. }
  530. sub withecho {
  531. print { *STDERR } " @_\n";
  532. system(@_)
  533. and subprocerr("@_");
  534. }
  535. sub run_hook {
  536. my ($name, $enabled) = @_;
  537. my $cmd = $hook{$name};
  538. return if not $cmd;
  539. print { *STDERR } "$Dpkg::PROGNAME: running hook $name\n";
  540. my %hook_vars = (
  541. '%' => '%',
  542. 'a' => $enabled ? 1 : 0,
  543. 'p' => $pkg,
  544. 'v' => $version,
  545. 's' => $sversion,
  546. 'u' => $uversion,
  547. );
  548. my $subst_hook_var = sub {
  549. my ($var) = @_;
  550. if (exists $hook_vars{$var}) {
  551. return $hook_vars{$var};
  552. } else {
  553. warning(_g('unknown %% substitution in hook: %%%s'), $var);
  554. return "\%$var";
  555. }
  556. };
  557. $cmd =~ s/\%(.)/&$subst_hook_var($1)/eg;
  558. withecho($cmd);
  559. }
  560. sub signfile {
  561. my ($file) = @_;
  562. print { *STDERR } " signfile $file\n";
  563. my $qfile = quotemeta($file);
  564. system("(cat ../$qfile ; echo '') | " .
  565. "$signcommand --utf8-strings --local-user " .
  566. quotemeta($signkey || $maintainer) .
  567. " --clearsign --armor --textmode > ../$qfile.asc");
  568. my $status = $?;
  569. unless ($status) {
  570. system('mv', '--', "../$file.asc", "../$file")
  571. and subprocerr('mv');
  572. } else {
  573. system('rm', '-f', "../$file.asc")
  574. and subprocerr('rm -f');
  575. }
  576. print "\n";
  577. return $status
  578. }
  579. sub fileomitted {
  580. my ($files, $regex) = @_;
  581. return $files !~ /$regex/
  582. }
  583. sub describe_build {
  584. my ($files) = @_;
  585. my $ext = compression_get_file_extension_regex();
  586. if (fileomitted($files, qr/\.deb/)) {
  587. # source-only upload
  588. if (fileomitted($files, qr/\.diff\.$ext/) and
  589. fileomitted($files, qr/\.debian\.tar\.$ext/)) {
  590. return _g('source-only upload: Debian-native package');
  591. } elsif (fileomitted($files, qr/\.orig\.tar\.$ext/)) {
  592. return _g('source-only, diff-only upload (original source NOT included)');
  593. } else {
  594. return _g('source-only upload (original source is included)');
  595. }
  596. } elsif (fileomitted($files, qr/\.dsc/)) {
  597. return _g('binary-only upload (no source included)');
  598. } elsif (fileomitted($files, qr/\.diff\.$ext/) and
  599. fileomitted($files, qr/\.debian\.tar\.$ext/)) {
  600. return _g('full upload; Debian-native package (full source is included)');
  601. } elsif (fileomitted($files, qr/\.orig\.tar\.$ext/)) {
  602. return _g('binary and diff upload (original source NOT included)');
  603. } else {
  604. return _g('full upload (original source is included)');
  605. }
  606. }