dpkg-genchanges.pl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use POSIX;
  5. use POSIX qw(:errno_h :signal_h);
  6. use Dpkg;
  7. use Dpkg::Gettext;
  8. use Dpkg::ErrorHandling qw(warning error failure unknown internerr syserr
  9. subprocerr usageerr);
  10. use Dpkg::Arch qw(get_host_arch debarch_eq debarch_is);
  11. use Dpkg::Fields qw(capit set_field_importance sort_field_by_importance);
  12. push(@INC,$dpkglibdir);
  13. require 'controllib.pl';
  14. our (%f, %fi);
  15. our %p2i;
  16. our %substvar;
  17. our $sourcepackage;
  18. textdomain("dpkg-dev");
  19. my @changes_fields = qw(Format Date Source Binary Architecture Version
  20. Distribution Urgency Maintainer Changed-By
  21. Description Closes Changes Files);
  22. my $controlfile = 'debian/control';
  23. my $changelogfile = 'debian/changelog';
  24. my $changelogformat;
  25. my $fileslistfile = 'debian/files';
  26. my $varlistfile = 'debian/substvars';
  27. my $uploadfilesdir = '..';
  28. my $sourcestyle = 'i';
  29. my $quiet = 0;
  30. my %f2p; # - file to package map
  31. my %p2f; # - package to file map, has entries for both "packagename"
  32. # and "packagename architecture"
  33. my %p2ver; # - package to version map
  34. my %p2arch;
  35. my %f2sec; # - file to section map
  36. my %f2seccf;
  37. my %f2pri; # - file to priority map
  38. my %f2pricf;
  39. my %sourcedefault; # - default values as taken from source (used for Section,
  40. # Priority and Maintainer)
  41. my @descriptions;
  42. my @sourcefiles;
  43. my @fileslistfiles;
  44. my %md5sum; # - md5sum to file map
  45. my %remove; # - fields to remove
  46. my %override;
  47. my %archadded;
  48. my @archvalues;
  49. my $dsc;
  50. my $changesdescription;
  51. my $sourceonly;
  52. my $binaryonly;
  53. my $archspecific;
  54. my $forcemaint;
  55. my $forcechangedby;
  56. my $since;
  57. sub version {
  58. printf _g("Debian %s version %s.\n"), $progname, $version;
  59. printf _g("
  60. Copyright (C) 1996 Ian Jackson.
  61. Copyright (C) 2000,2001 Wichert Akkerman.");
  62. printf _g("
  63. This is free software; see the GNU General Public Licence version 2 or
  64. later for copying conditions. There is NO warranty.
  65. ");
  66. }
  67. sub usage {
  68. printf _g(
  69. "Usage: %s [<option> ...]
  70. Options:
  71. -b binary-only build - no source files.
  72. -B arch-specific - no source or arch-indep files.
  73. -S source-only upload.
  74. -c<controlfile> get control info from this file.
  75. -l<changelogfile> get per-version info from this file.
  76. -f<fileslistfile> get .deb files list from this file.
  77. -v<sinceversion> include all changes later than version.
  78. -C<changesdescription> use change description from this file.
  79. -m<maintainer> override control's maintainer value.
  80. -e<maintainer> override changelog's maintainer value.
  81. -u<uploadfilesdir> directory with files (default is \`..').
  82. -si (default) src includes orig for debian-revision 0 or 1.
  83. -sa source includes orig src.
  84. -sd source is diff and .dsc only.
  85. -q quiet - no informational messages on stderr.
  86. -F<changelogformat> force change log format.
  87. -V<name>=<value> set a substitution variable.
  88. -T<varlistfile> read variables here, not debian/substvars.
  89. -D<field>=<value> override or add a field and value.
  90. -U<field> remove a field.
  91. -h, --help show this help message.
  92. --version show the version.
  93. "), $progname;
  94. }
  95. while (@ARGV) {
  96. $_=shift(@ARGV);
  97. if (m/^-b$/) {
  98. $sourceonly && &usageerr(_g("cannot combine -b or -B and -S"));
  99. $binaryonly= 1;
  100. } elsif (m/^-B$/) {
  101. $sourceonly && &usageerr(_g("cannot combine -b or -B and -S"));
  102. $archspecific=1;
  103. $binaryonly= 1;
  104. printf STDERR _g("%s: arch-specific upload - not including arch-independent packages")."\n", $progname;
  105. } elsif (m/^-S$/) {
  106. $binaryonly && &usageerr(_g("cannot combine -b or -B and -S"));
  107. $sourceonly= 1;
  108. } elsif (m/^-s([iad])$/) {
  109. $sourcestyle= $1;
  110. } elsif (m/^-q$/) {
  111. $quiet= 1;
  112. } elsif (m/^-c/) {
  113. $controlfile= $';
  114. } elsif (m/^-l/) {
  115. $changelogfile= $';
  116. } elsif (m/^-C/) {
  117. $changesdescription= $';
  118. } elsif (m/^-f/) {
  119. $fileslistfile= $';
  120. } elsif (m/^-v/) {
  121. $since= $';
  122. } elsif (m/^-T/) {
  123. $varlistfile= $';
  124. } elsif (m/^-m/) {
  125. $forcemaint= $';
  126. } elsif (m/^-e/) {
  127. $forcechangedby= $';
  128. } elsif (m/^-F([0-9a-z]+)$/) {
  129. $changelogformat=$1;
  130. } elsif (m/^-D([^\=:]+)[=:]/) {
  131. $override{$1}= $';
  132. } elsif (m/^-u/) {
  133. $uploadfilesdir= $';
  134. } elsif (m/^-U([^\=:]+)$/) {
  135. $remove{$1}= 1;
  136. } elsif (m/^-V(\w[-:0-9A-Za-z]*)[=:]/) {
  137. $substvar{$1}= $';
  138. } elsif (m/^-(h|-help)$/) {
  139. &usage; exit(0);
  140. } elsif (m/^--version$/) {
  141. &version; exit(0);
  142. } else {
  143. usageerr(_g("unknown option \`%s'"), $_);
  144. }
  145. }
  146. parsechangelog($changelogfile, $changelogformat, $since);
  147. parsecontrolfile($controlfile);
  148. if (not $sourceonly) {
  149. $fileslistfile="./$fileslistfile" if $fileslistfile =~ m/^\s/;
  150. open(FL,"< $fileslistfile") || &syserr(_g("cannot read files list file"));
  151. while(<FL>) {
  152. if (m/^(([-+.0-9a-z]+)_([^_]+)_([-\w]+)\.u?deb) (\S+) (\S+)$/) {
  153. defined($p2f{"$2 $4"}) &&
  154. warning(_g("duplicate files list entry for package %s (line %d)"),
  155. $2, $.);
  156. $f2p{$1}= $2;
  157. $p2f{"$2 $4"}= $1;
  158. $p2f{$2}= $1;
  159. $p2ver{$2}= $3;
  160. defined($f2sec{$1}) &&
  161. warning(_g("duplicate files list entry for file %s (line %d)"),
  162. $1, $.);
  163. $f2sec{$1}= $5;
  164. $f2pri{$1}= $6;
  165. push(@fileslistfiles,$1);
  166. } elsif (m/^([-+.0-9a-z]+_[^_]+_([-\w]+)\.[a-z0-9.]+) (\S+) (\S+)$/) {
  167. # A non-deb package
  168. $f2sec{$1}= $3;
  169. $f2pri{$1}= $4;
  170. push(@archvalues,$2) unless !$2 || $archadded{$2}++;
  171. push(@fileslistfiles,$1);
  172. } elsif (m/^([-+.,_0-9a-zA-Z]+) (\S+) (\S+)$/) {
  173. defined($f2sec{$1}) &&
  174. warning(_g("duplicate files list entry for file %s (line %d)"),
  175. $1, $.);
  176. $f2sec{$1}= $2;
  177. $f2pri{$1}= $3;
  178. push(@fileslistfiles,$1);
  179. } else {
  180. error(_g("badly formed line in files list file, line %d"), $.);
  181. }
  182. }
  183. close(FL);
  184. }
  185. for $_ (keys %fi) {
  186. my $v = $fi{$_};
  187. if (s/^C //) {
  188. if (m/^Source$/) {
  189. setsourcepackage($v);
  190. }
  191. elsif (m/^Section$|^Priority$/i) { $sourcedefault{$_}= $v; }
  192. elsif (m/^Maintainer$/i) { $f{$_}= $v; }
  193. elsif (s/^X[BS]*C[BS]*-//i) { $f{$_}= $v; }
  194. elsif (m/^X[BS]+-/i ||
  195. m/^Build-(Depends|Conflicts)(-Indep)?$/i ||
  196. m/^(Standards-Version|Uploaders|Homepage|Origin|Bugs)$/i ||
  197. m/^Vcs-(Browser|Arch|Bzr|Cvs|Darcs|Git|Hg|Mtn|Svn)$/i) {
  198. }
  199. else { &unknown(_g('general section of control info file')); }
  200. } elsif (s/^C(\d+) //) {
  201. my $i = $1;
  202. my $p = $fi{"C$i Package"};
  203. my $a = $fi{"C$i Architecture"};
  204. my $host_arch = get_host_arch();
  205. if (!defined($p2f{$p}) && not $sourceonly) {
  206. if ((debarch_eq('all', $a) && !$archspecific) ||
  207. grep(debarch_is($host_arch, $_), split(/\s+/, $a))) {
  208. warning(_g("package %s in control file but not in files list"),
  209. $p);
  210. next;
  211. }
  212. } else {
  213. my $f = $p2f{$p};
  214. $p2arch{$p}=$a;
  215. if (m/^Description$/) {
  216. $v=$` if $v =~ m/\n/;
  217. if (defined($f) && $f =~ m/\.udeb$/) {
  218. push(@descriptions,sprintf("%-10s - %-.65s (udeb)",$p,$v));
  219. } else {
  220. push(@descriptions,sprintf("%-10s - %-.65s",$p,$v));
  221. }
  222. } elsif (m/^Section$/) {
  223. $f2seccf{$f} = $v if defined($f);
  224. } elsif (m/^Priority$/) {
  225. $f2pricf{$f} = $v if defined($f);
  226. } elsif (s/^X[BS]*C[BS]*-//i) {
  227. $f{$_}= $v;
  228. } elsif (m/^Architecture$/) {
  229. if (not $sourceonly) {
  230. if (grep(debarch_is($host_arch, $_), split(/\s+/, $v))) {
  231. $v = $host_arch;
  232. } elsif (!debarch_eq('all', $v)) {
  233. $v= '';
  234. }
  235. } else {
  236. $v = '';
  237. }
  238. push(@archvalues,$v) unless !$v || $archadded{$v}++;
  239. } elsif (m/^(Package|Package-Type|Kernel-Version|Essential)$/ ||
  240. m/^(Tag|Installer-Menu-Item|Subarchitecture)$/i ||
  241. m/^(Pre-Depends|Depends|Recommends|Suggests|Provides)$/ ||
  242. m/^(Enhances|Conflicts|Breaks|Replaces)$/ ||
  243. m/^X[BS]+-/i) {
  244. } else {
  245. &unknown(_g("package's section of control info file"));
  246. }
  247. }
  248. } elsif (s/^L //) {
  249. if (m/^Source$/i) {
  250. setsourcepackage($v);
  251. } elsif (m/^Maintainer$/i) {
  252. $f{"Changed-By"}=$v;
  253. } elsif (m/^(Version|Changes|Urgency|Distribution|Date|Closes)$/i) {
  254. $f{$_}= $v;
  255. } elsif (s/^X[BS]*C[BS]*-//i) {
  256. $f{$_}= $v;
  257. } elsif (!m/^X[BS]+-/i) {
  258. &unknown(_g("parsed version of changelog"));
  259. }
  260. } elsif (m/^o:.*/) {
  261. } else {
  262. internerr(_g("value from nowhere, with key >%s< and value >%s<"),
  263. $_, $v);
  264. }
  265. }
  266. if ($changesdescription) {
  267. $changesdescription="./$changesdescription" if $changesdescription =~ m/^\s/;
  268. $f{'Changes'}= '';
  269. open(X,"< $changesdescription") || &syserr(_g("read changesdescription"));
  270. while(<X>) {
  271. s/\s*\n$//;
  272. $_= '.' unless m/\S/;
  273. $f{'Changes'}.= "\n $_";
  274. }
  275. }
  276. for my $p (keys %p2f) {
  277. my ($pp, $aa) = (split / /, $p);
  278. defined($p2i{"C $pp"}) ||
  279. warning(_g("package %s listed in files list but not in control info"),
  280. $pp);
  281. }
  282. for my $p (keys %p2f) {
  283. my $f = $p2f{$p};
  284. my $sec = $f2seccf{$f};
  285. $sec = $sourcedefault{'Section'} if !defined($sec);
  286. if (!defined($sec)) {
  287. $sec = '-';
  288. warning(_g("missing Section for binary package %s; using '-'"), $p);
  289. }
  290. $sec eq $f2sec{$f} || error(_g("package %s has section %s in " .
  291. "control file but %s in files list"),
  292. $p, $sec, $f2sec{$f});
  293. my $pri = $f2pricf{$f};
  294. $pri = $sourcedefault{'Priority'} if !defined($pri);
  295. if (!defined($pri)) {
  296. $pri = '-';
  297. warning(_g("missing Priority for binary package %s; using '-'"), $p);
  298. }
  299. $pri eq $f2pri{$f} || error(_g("package %s has priority %s in " .
  300. "control file but %s in files list"),
  301. $p, $pri, $f2pri{$f});
  302. }
  303. &init_substvars;
  304. init_substvar_arch();
  305. my $origsrcmsg;
  306. if (!$binaryonly) {
  307. my $sec = $sourcedefault{'Section'};
  308. if (!defined($sec)) {
  309. $sec = '-';
  310. warning(_g("missing Section for source files"));
  311. }
  312. my $pri = $sourcedefault{'Priority'};
  313. if (!defined($pri)) {
  314. $pri = '-';
  315. warning(_g("missing Priority for source files"));
  316. }
  317. (my $sversion = $substvar{'source:Version'}) =~ s/^\d+://;
  318. $dsc= "$uploadfilesdir/${sourcepackage}_${sversion}.dsc";
  319. open(CDATA,"< $dsc") || error(_g("cannot open .dsc file %s: %s"), $dsc, $!);
  320. push(@sourcefiles,"${sourcepackage}_${sversion}.dsc");
  321. parsecdata(\*CDATA, 'S', -1, sprintf(_g("source control file %s"), $dsc));
  322. my $files = $fi{'S Files'};
  323. for my $file (split(/\n /, $files)) {
  324. next if $file eq '';
  325. $file =~ m/^([0-9a-f]{32})[ \t]+\d+[ \t]+([0-9a-zA-Z][-+:.,=0-9a-zA-Z_~]+)$/
  326. || error(_g("Files field contains bad line \`%s'"), $file);
  327. ($md5sum{$2},$file) = ($1,$2);
  328. push(@sourcefiles,$file);
  329. }
  330. for my $f (@sourcefiles) {
  331. $f2sec{$f} = $sec;
  332. $f2pri{$f} = $pri;
  333. }
  334. if (($sourcestyle =~ m/i/ && $sversion !~ m/-(0|1|0\.1)$/ ||
  335. $sourcestyle =~ m/d/) &&
  336. grep(m/\.diff\.gz$/,@sourcefiles)) {
  337. $origsrcmsg= _g("not including original source code in upload");
  338. @sourcefiles= grep(!m/\.orig\.tar\.gz$/,@sourcefiles);
  339. } else {
  340. if ($sourcestyle =~ m/d/ && !grep(m/\.diff\.gz$/,@sourcefiles)) {
  341. warning(_g("ignoring -sd option for native Debian package"));
  342. }
  343. $origsrcmsg= _g("including full source code in upload");
  344. }
  345. } else {
  346. $origsrcmsg= _g("binary-only upload - not including any source code");
  347. }
  348. print(STDERR "$progname: $origsrcmsg\n") ||
  349. &syserr(_g("write original source message")) unless $quiet;
  350. $f{'Format'}= $substvar{'Format'};
  351. if (!defined($f{'Date'})) {
  352. chop(my $date822 = `date -R`);
  353. $? && subprocerr("date -R");
  354. $f{'Date'}= $date822;
  355. }
  356. $f{'Binary'}= join(' ',grep(s/C //,keys %p2i));
  357. unshift(@archvalues,'source') unless $binaryonly;
  358. $f{'Architecture'}= join(' ',@archvalues);
  359. $f{'Description'}= "\n ".join("\n ",sort @descriptions);
  360. $f{'Files'}= '';
  361. my %filedone;
  362. for my $f (@sourcefiles, @fileslistfiles) {
  363. next if ($archspecific && debarch_eq('all', $p2arch{$f2p{$f}}));
  364. next if $filedone{$f}++;
  365. my $uf = "$uploadfilesdir/$f";
  366. open(STDIN, "< $uf") ||
  367. syserr(_g("cannot open upload file %s for reading"), $uf);
  368. (my @s = stat(STDIN)) || syserr(_g("cannot fstat upload file %s"), $uf);
  369. my $size = $s[7];
  370. $size || warning(_g("upload file %s is empty"), $uf);
  371. my $md5sum = `md5sum`;
  372. $? && subprocerr(_g("md5sum upload file %s"), $uf);
  373. $md5sum =~ m/^([0-9a-f]{32})\s*-?\s*$/i ||
  374. failure(_g("md5sum upload file %s gave strange output \`%s'"),
  375. $uf, $md5sum);
  376. $md5sum= $1;
  377. defined($md5sum{$f}) && $md5sum{$f} ne $md5sum &&
  378. error(_g("md5sum of source file %s (%s) is different from md5sum " .
  379. "in %s (%s)"), $uf, $md5sum, $dsc, $md5sum{$f});
  380. $f{'Files'}.= "\n $md5sum $size $f2sec{$f} $f2pri{$f} $f";
  381. }
  382. $f{'Source'}= $sourcepackage;
  383. if ($f{'Version'} ne $substvar{'source:Version'}) {
  384. $f{'Source'} .= " ($substvar{'source:Version'})";
  385. }
  386. $f{'Maintainer'} = $forcemaint if defined($forcemaint);
  387. $f{'Changed-By'} = $forcechangedby if defined($forcechangedby);
  388. for my $f (qw(Version Distribution Maintainer Changes)) {
  389. defined($f{$f}) ||
  390. error(_g("missing information for critical output field %s"), $f);
  391. }
  392. for my $f (qw(Urgency)) {
  393. defined($f{$f}) ||
  394. warning(_g("missing information for output field %s"), $f);
  395. }
  396. for my $f (keys %override) {
  397. $f{capit($f)} = $override{$f};
  398. }
  399. for my $f (keys %remove) {
  400. delete $f{capit($f)};
  401. }
  402. set_field_importance(@changes_fields);
  403. outputclose();