dpkg-genchanges.pl 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. #!/usr/bin/perl
  2. $dpkglibdir= ".";
  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. use POSIX;
  12. use POSIX qw(:errno_h :signal_h);
  13. push(@INC,$dpkglibdir);
  14. require 'controllib.pl';
  15. sub usageversion {
  16. print STDERR
  17. "Debian GNU/Linux dpkg-genchanges $version. Copyright (C) 1996
  18. Ian Jackson. This is free software; see the GNU General Public Licence
  19. version 2 or later for copying conditions. There is NO warranty.
  20. Usage: dpkg-genchanges [options ...]
  21. Options: -b or -B (identical) binary-only build - no source files
  22. -c<controlfile> get control info from this file
  23. -l<changelogfile> get per-version info from this file
  24. -f<fileslistfile> get .deb files list from this file
  25. -v<sinceversion> include all changes later than version
  26. -C<changesdescription> use change description from this file
  27. -m<maintainer> override changelog's maintainer value
  28. -u<uploadfilesdir> directory with files (default is \`..')
  29. -si (default) src includes orig for debian-revision 0 or 1
  30. -sa source includes orig src
  31. -sd source is diff and .dsc only
  32. -q quiet - no informational messages on stderr
  33. -F<changelogformat> force change log format
  34. -V<name>=<value> set a substitution variable
  35. -T<varlistfile> read variables here, not debian/substvars
  36. -D<field>=<value> override or add a field and value
  37. -U<field> remove a field
  38. -h print this message
  39. ";
  40. }
  41. $i=100;grep($fieldimps{$_}=$i--,
  42. qw(Format Date Source Binary Architecture Version
  43. Distribution Urgency Maintainer Description Changes Files));
  44. while (@ARGV) {
  45. $_=shift(@ARGV);
  46. if (m/^-b$|^-B$/) {
  47. $binaryonly= 1;
  48. } elsif (m/^-s([iad])$/) {
  49. $sourcestyle= $1;
  50. } elsif (m/^-q$/) {
  51. $quiet= 1;
  52. } elsif (m/^-c/) {
  53. $controlfile= $';
  54. } elsif (m/^-l/) {
  55. $changelogfile= $';
  56. } elsif (m/^-C/) {
  57. $changesdescription= $';
  58. } elsif (m/^-f/) {
  59. $fileslistfile= $';
  60. } elsif (m/^-v/) {
  61. $since= $';
  62. } elsif (m/^-T/) {
  63. $varlistfile= $';
  64. } elsif (m/^-m/) {
  65. $forcemaint= $';
  66. } elsif (m/^-F([0-9a-z]+)$/) {
  67. $changelogformat=$1;
  68. } elsif (m/^-D([^\=:]+)[=:]/) {
  69. $override{$1}= $';
  70. } elsif (m/^-U([^\=:]+)$/) {
  71. $remove{$1}= 1;
  72. } elsif (m/^-V(\w[-:0-9A-Za-z]*)[=:]/) {
  73. $substvar{$1}= $';
  74. } elsif (m/^-h$/) {
  75. &usageversion; exit(0);
  76. } else {
  77. &usageerr("unknown option \`$_'");
  78. }
  79. }
  80. &findarch;
  81. &parsechangelog;
  82. &parsecontrolfile;
  83. $fileslistfile="./$fileslistfile" if $fileslistfile =~ m/^\s/;
  84. open(FL,"< $fileslistfile") || &syserr("cannot read files list file");
  85. while(<FL>) {
  86. if (m/^(([-+.0-9a-z]+)_([^_]+)_(\w+)\.deb) (\S+) (\S+)$/) {
  87. defined($p2f{$2}) &&
  88. &warn("duplicate files list entry for package $2 (line $.)");
  89. $p2f{$2}= $1;
  90. $p2ver{$2}= $3;
  91. defined($f2sec{$1}) &&
  92. &warn("duplicate files list entry for file $1 (line $.)");
  93. $f2sec{$1}= $5;
  94. $f2pri{$1}= $6;
  95. push(@fileslistfiles,$1);
  96. } elsif (m/^([-+.,_0-9a-zA-Z]+) (\S+) (\S+)$/) {
  97. defined($f2sec{$1}) &&
  98. &warn("duplicate files list entry for file $1 (line $.)");
  99. $f2sec{$1}= $2;
  100. $f2pri{$1}= $3;
  101. push(@fileslistfiles,$1);
  102. } else {
  103. &error("badly formed line in files list file, line $.");
  104. }
  105. }
  106. close(FL);
  107. $archspecific=0;
  108. for $_ (keys %fi) {
  109. $v= $fi{$_};
  110. if (s/^C //) {
  111. #print STDERR "G key >$_< value >$v<\n";
  112. if (m/^Source$/) { &setsourcepackage; }
  113. elsif (m/^Section$|^Priority$/) { $sourcedefault{$_}= $v; }
  114. elsif (s/^X[BS]*C[BS]*-//i) { $f{$_}= $v; }
  115. elsif (m/|^X[BS]+-|^Standards-Version$|^Maintainer$/i) { }
  116. else { &unknown('general section of control info file'); }
  117. } elsif (s/^C(\d+) //) {
  118. #print STDERR "P key >$_< value >$v<\n";
  119. $i=$1; $p=$fi{"C$i Package"};
  120. defined($p2f{$p}) || &error("package $p in control file but not in files list");
  121. $f= $p2f{$p};
  122. if (m/^Description$/) {
  123. $v=$` if $v =~ m/\n/;
  124. push(@descriptions,sprintf("%-10s - %-.65s",$p,$v));
  125. } elsif (m/^Section$/) {
  126. $f2seccf{$f}= $v;
  127. } elsif (m/^Priority$/) {
  128. $f2pricf{$f}= $v;
  129. } elsif (s/^X[BS]*C[BS]*-//i) {
  130. $f{$_}= $v;
  131. } elsif (m/^Architecture$/) {
  132. $v= $arch if $v eq 'any';
  133. push(@archvalues,$v) unless $archadded{$v}++;
  134. } elsif (m/^(Package|Essential|Pre-Depends|Depends|Provides)$/ ||
  135. m/^(Recommends|Suggests|Optional|Conflicts|Replaces)$/ ||
  136. m/^X[CS]+-/i) {
  137. } else {
  138. &unknown("package's section of control info file");
  139. }
  140. } elsif (s/^L //) {
  141. #print STDERR "L key >$_< value >$v<\n";
  142. if (m/^Source$/) {
  143. &setsourcepackage;
  144. } elsif (m/^(Version|Maintainer|Changes|Urgency|Distribution|Date)$/) {
  145. $f{$_}= $v;
  146. } elsif (s/^X[BS]*C[BS]*-//i) {
  147. $f{$_}= $v;
  148. } elsif (!m/^X[BS]+-/i) {
  149. &unknown("parsed version of changelog");
  150. }
  151. } else {
  152. &internerr("value from nowhere, with key >$_< and value >$v<");
  153. }
  154. }
  155. if ($changesdescription) {
  156. $changesdescription="./$changesdescription" if $changesdescription =~ m/^\s/;
  157. $f{'Changes'}= '';
  158. open(X,"< $changesdescription") || &syserr("read changesdescription");
  159. while(<X>) {
  160. s/\s*\n$//;
  161. $_= '.' unless m/\S/;
  162. $f{'Changes'}.= "\n $_";
  163. }
  164. }
  165. for $p (keys %p2f) {
  166. defined($p2i{"C $p"}) ||
  167. &warn("package $p listed in files list but not in control info");
  168. }
  169. for $p (keys %p2f) {
  170. $f= $p2f{$p};
  171. $sec= $f2seccf{$f}; $sec= $sourcedefault{'Section'} if !length($sec);
  172. if (!length($sec)) { $sec='-'; &warn("missing Section for binary package $p"); }
  173. $sec eq $f2sec{$f} || &error("package $p has section $sec in control file".
  174. " but $f2sec{$f} in files list");
  175. $pri= $f2pricf{$f}; $pri= $sourcedefault{'Priority'} if !length($pri);
  176. if (!length($pri)) { $pri='-'; &warn("missing Priority for binary package $p"); }
  177. $pri eq $f2pri{$f} || &error("package $p has priority $pri in control".
  178. " file but $f2pri{$f} in files list");
  179. }
  180. if (!$binaryonly) {
  181. $version= $f{'Version'};
  182. $origversion= $version; $origversion =~ s/-[^-]+$//;
  183. $sec= $sourcedefault{'Section'};
  184. if (!length($sec)) { $sec='-'; &warn("missing Section for source files"); }
  185. $pri= $sourcedefault{'Priority'};
  186. if (!length($pri)) { $pri='-'; &warn("missing Priority for source files"); }
  187. $dsc= "$uploadfilesdir/${sourcepackage}_${version}.dsc";
  188. open(CDATA,"< $dsc") || &error("cannot open .dsc file $dsc: $!");
  189. push(@sourcefiles,"${sourcepackage}_${version}.dsc");
  190. &parsecdata('S',-1,"source control file $dsc");
  191. $files= $fi{'S Files'};
  192. for $file (split(/\n /,$files)) {
  193. next if $file eq '';
  194. $file =~ m/^([0-9a-f]{32})[ \t]+\d+[ \t]+([0-9a-zA-Z][-+:.,=0-9a-zA-Z_]+)$/
  195. || &error("Files field contains bad line \`$file'");
  196. ($md5sum{$2},$file) = ($1,$2);
  197. push(@sourcefiles,$file);
  198. }
  199. for $f (@sourcefiles) { $f2sec{$f}= $sec; $f2pri{$f}= $pri; }
  200. if (($sourcestyle =~ m/i/ && $version !~ m/-[01]$/ ||
  201. $sourcestyle =~ m/d/) &&
  202. grep(m/\.diff\.gz$/,@sourcefiles)) {
  203. $origsrcmsg= "not including original source code in upload";
  204. @sourcefiles= grep(!m/\.orig\.tar\.gz$/,@sourcefiles);
  205. } else {
  206. $origsrcmsg= "including full source code in upload";
  207. }
  208. } else {
  209. $origsrcmsg= "binary-only upload - not including any source code";
  210. }
  211. print(STDERR "$progname: $origsrcmsg\n") ||
  212. &syserr("write original source message") unless $quiet;
  213. $f{'Format'}= $substvar{'Format'};
  214. if (!length($f{'Date'})) {
  215. chop($date822=`822-date`); $? && subprocerr("822-date");
  216. $f{'Date'}= $date822;
  217. }
  218. $f{'Binary'}= join(' ',grep(s/C //,keys %p2i));
  219. unshift(@archvalues,'source') unless $binaryonly;
  220. $f{'Architecture'}= join(' ',@archvalues);
  221. $f{'Description'}= "\n ".join("\n ",sort @descriptions);
  222. $f{'Files'}= '';
  223. for $f (@sourcefiles,@fileslistfiles) {
  224. next if $filedone{$f}++;
  225. $uf= "$uploadfilesdir/$f";
  226. open(STDIN,"< $uf") || &syserr("cannot open upload file $uf for reading");
  227. (@s=stat(STDIN)) || &syserr("cannot fstat upload file $uf");
  228. $size= $s[7]; $size || &warn("upload file $uf is empty");
  229. $md5sum=`md5sum`; $? && subprocerr("md5sum upload file $uf");
  230. $md5sum =~ m/^([0-9a-f]{32})\s*$/i ||
  231. &failure("md5sum upload file $uf gave strange output \`$md5sum'");
  232. $md5sum= $1;
  233. defined($md5sum{$f}) && $md5sum{$f} ne $md5sum &&
  234. &error("md5sum of source file $uf ($md5sum) is different from md5sum in $dsc".
  235. " ($md5sum{$f})");
  236. $f{'Files'}.= "\n $md5sum $size $f2sec{$f} $f2pri{$f} $f";
  237. }
  238. $f{'Source'}= $sourcepackage;
  239. $f{'Maintainer'}= $forcemaint if length($forcemaint);
  240. for $f (qw(Version Distribution Maintainer Changes)) {
  241. defined($f{$f}) || &error("missing information for critical output field $f");
  242. }
  243. for $f (qw(Urgency)) {
  244. defined($f{$f}) || &warn("missing information for output field $f");
  245. }
  246. for $f (keys %override) { $f{&capit($f)}= $override{$f}; }
  247. for $f (keys %remove) { delete $f{&capit($f)}; }
  248. &outputclose;