dpkg-buildpackage.pl 21 KB

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