dpkg-genchanges.pl 13 KB

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