dpkg-genchanges.pl 14 KB

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