dpkg-genchanges.pl 12 KB

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