dpkg-genchanges.pl 13 KB

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