dpkg-genchanges.pl 14 KB

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