dpkg-genchanges.pl 13 KB

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