dpkg-genchanges.pl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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;
  122. &parsecontrolfile;
  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$/) { &setsourcepackage; }
  161. elsif (m/^Section$|^Priority$/i) { $sourcedefault{$_}= $v; }
  162. elsif (m/^Maintainer$/i) { $f{$_}= $v; }
  163. elsif (s/^X[BS]*C[BS]*-//i) { $f{$_}= $v; }
  164. elsif (m/|^X[BS]+-|^Standards-Version$/i) { }
  165. else { &unknown(_g('general section of control info file')); }
  166. } elsif (s/^C(\d+) //) {
  167. $i=$1; $p=$fi{"C$i Package"}; $a=$fi{"C$i Architecture"};
  168. if (!defined($p2f{$p}) && not $sourceonly) {
  169. if ((debian_arch_eq('all', $a) && !$archspecific) ||
  170. debian_arch_is($arch, $a) ||
  171. grep(debian_arch_is($arch, $_), split(/\s+/, $a))) {
  172. &warn(sprintf(_g("package %s in control file but not in files list"), $p));
  173. next;
  174. }
  175. } else {
  176. $p2arch{$p}=$a;
  177. $f=$p2f{$p};
  178. if (m/^Description$/) {
  179. $v=$` if $v =~ m/\n/;
  180. if ($f =~ m/\.udeb$/) {
  181. push(@descriptions,sprintf("%-10s - %-.65s (udeb)",$p,$v));
  182. } else {
  183. push(@descriptions,sprintf("%-10s - %-.65s",$p,$v));
  184. }
  185. } elsif (m/^Section$/) {
  186. $f2seccf{$f}= $v;
  187. } elsif (m/^Priority$/) {
  188. $f2pricf{$f}= $v;
  189. } elsif (s/^X[BS]*C[BS]*-//i) {
  190. $f{$_}= $v;
  191. } elsif (m/^Architecture$/) {
  192. if (not $sourceonly) {
  193. if (debian_arch_is($arch, $v) ||
  194. grep(debian_arch_is($arch, $_), split(/\s+/, $v))) {
  195. $v= $arch;
  196. } elsif (!debian_arch_eq('all', $v)) {
  197. $v= '';
  198. }
  199. } else {
  200. $v = '';
  201. }
  202. push(@archvalues,$v) unless !$v || $archadded{$v}++;
  203. } elsif (m/^(Package|Essential|Pre-Depends|Depends|Provides)$/ ||
  204. m/^(Recommends|Suggests|Enhances|Optional|Conflicts|Replaces)$/ ||
  205. m/^X[CS]+-/i) {
  206. } else {
  207. &unknown(_g("package's section of control info file"));
  208. }
  209. }
  210. } elsif (s/^L //) {
  211. if (m/^Source$/i) {
  212. &setsourcepackage;
  213. } elsif (m/^Maintainer$/i) {
  214. $f{"Changed-By"}=$v;
  215. } elsif (m/^(Version|Changes|Urgency|Distribution|Date|Closes)$/i) {
  216. $f{$_}= $v;
  217. } elsif (s/^X[BS]*C[BS]*-//i) {
  218. $f{$_}= $v;
  219. } elsif (!m/^X[BS]+-/i) {
  220. &unknown(_g("parsed version of changelog"));
  221. }
  222. } elsif (m/^o:.*/) {
  223. } else {
  224. &internerr(sprintf(_g("value from nowhere, with key >%s< and value >%s<"), $_, $v));
  225. }
  226. }
  227. if ($changesdescription) {
  228. $changesdescription="./$changesdescription" if $changesdescription =~ m/^\s/;
  229. $f{'Changes'}= '';
  230. open(X,"< $changesdescription") || &syserr(_g("read changesdescription"));
  231. while(<X>) {
  232. s/\s*\n$//;
  233. $_= '.' unless m/\S/;
  234. $f{'Changes'}.= "\n $_";
  235. }
  236. }
  237. for $p (keys %p2f) {
  238. my ($pp, $aa) = (split / /, $p);
  239. defined($p2i{"C $pp"}) ||
  240. &warn(sprintf(_g("package %s listed in files list but not in control info"), $pp));
  241. }
  242. for $p (keys %p2f) {
  243. $f= $p2f{$p};
  244. $sec= $f2seccf{$f}; $sec= $sourcedefault{'Section'} if !length($sec);
  245. if (!length($sec)) { $sec='-'; &warn(sprintf(_g("missing Section for binary package %s; using '-'"), $p)); }
  246. $sec eq $f2sec{$f} || &error(sprintf(_g("package %s has section %s in ".
  247. "control file but %s in files list"),
  248. $p, $sec, $f2sec{$f}));
  249. $pri= $f2pricf{$f}; $pri= $sourcedefault{'Priority'} if !length($pri);
  250. if (!length($pri)) { $pri='-'; &warn("missing Priority for binary package $p; using '-'"); }
  251. $pri eq $f2pri{$f} || &error(sprintf(_g("package %s has priority %s in ".
  252. "control file but %s in files list"),
  253. $p, $pri, $f2pri{$f}));
  254. }
  255. &init_substvars;
  256. if (!$binaryonly) {
  257. $sec= $sourcedefault{'Section'};
  258. if (!length($sec)) { $sec='-'; &warn(_g("missing Section for source files")); }
  259. $pri= $sourcedefault{'Priority'};
  260. if (!length($pri)) { $pri='-'; &warn(_g("missing Priority for source files")); }
  261. ($sversion = $substvar{'source:Version'}) =~ s/^\d+://;
  262. $dsc= "$uploadfilesdir/${sourcepackage}_${sversion}.dsc";
  263. open(CDATA,"< $dsc") || &error(sprintf(_g("cannot open .dsc file %s: %s"), $dsc, $!));
  264. push(@sourcefiles,"${sourcepackage}_${sversion}.dsc");
  265. &parsecdata('S',-1,"source control file $dsc");
  266. $files= $fi{'S Files'};
  267. for $file (split(/\n /,$files)) {
  268. next if $file eq '';
  269. $file =~ m/^([0-9a-f]{32})[ \t]+\d+[ \t]+([0-9a-zA-Z][-+:.,=0-9a-zA-Z_~]+)$/
  270. || &error(sprintf(_g("Files field contains bad line \`%s'"), $file));
  271. ($md5sum{$2},$file) = ($1,$2);
  272. push(@sourcefiles,$file);
  273. }
  274. for $f (@sourcefiles) { $f2sec{$f}= $sec; $f2pri{$f}= $pri; }
  275. if (($sourcestyle =~ m/i/ && $sversion !~ m/-(0|1|0\.1)$/ ||
  276. $sourcestyle =~ m/d/) &&
  277. grep(m/\.diff\.gz$/,@sourcefiles)) {
  278. $origsrcmsg= _g("not including original source code in upload");
  279. @sourcefiles= grep(!m/\.orig\.tar\.gz$/,@sourcefiles);
  280. } else {
  281. if ($sourcestyle =~ m/d/ && !grep(m/\.diff\.gz$/,@sourcefiles)) {
  282. &warn(_g("Ignoring -sd option for native Debian package"));
  283. }
  284. $origsrcmsg= _g("including full source code in upload");
  285. }
  286. } else {
  287. $origsrcmsg= _g("binary-only upload - not including any source code");
  288. }
  289. print(STDERR "$progname: $origsrcmsg\n") ||
  290. &syserr(_g("write original source message")) unless $quiet;
  291. $f{'Format'}= $substvar{'Format'};
  292. if (!length($f{'Date'})) {
  293. chop($date822=`date -R`); $? && subprocerr("date -R");
  294. $f{'Date'}= $date822;
  295. }
  296. $f{'Binary'}= join(' ',grep(s/C //,keys %p2i));
  297. unshift(@archvalues,'source') unless $binaryonly;
  298. $f{'Architecture'}= join(' ',@archvalues);
  299. $f{'Description'}= "\n ".join("\n ",sort @descriptions);
  300. $f{'Files'}= '';
  301. for $f (@sourcefiles,@fileslistfiles) {
  302. next if ($archspecific && debian_arch_eq('all', $p2arch{$f2p{$f}}));
  303. next if $filedone{$f}++;
  304. $uf= "$uploadfilesdir/$f";
  305. open(STDIN,"< $uf") || &syserr(sprintf(_g("cannot open upload file %s for reading"), $uf));
  306. (@s=stat(STDIN)) || &syserr(sprintf(_g("cannot fstat upload file %s"), $uf));
  307. $size= $s[7]; $size || &warn(sprintf(_g("upload file %s is empty"), $uf));
  308. $md5sum=`md5sum`; $? && subprocerr(sprintf(_g("md5sum upload file %s"), $uf));
  309. $md5sum =~ m/^([0-9a-f]{32})\s*-?\s*$/i ||
  310. &failure(sprintf(_g("md5sum upload file %s gave strange output \`%s'"), $uf, $md5sum));
  311. $md5sum= $1;
  312. defined($md5sum{$f}) && $md5sum{$f} ne $md5sum &&
  313. &error(sprintf(_g("md5sum of source file %s (%s) is different ".
  314. "from md5sum in %s (%s)"),
  315. $uf, $md5sum, $dsc, $md5sum{$f}));
  316. $f{'Files'}.= "\n $md5sum $size $f2sec{$f} $f2pri{$f} $f";
  317. }
  318. $f{'Source'}= $sourcepackage;
  319. if ($f{'Version'} ne $substvar{'source:Version'}) {
  320. $f{'Source'} .= " ($substvar{'source:Version'})";
  321. }
  322. $f{'Maintainer'}= $forcemaint if length($forcemaint);
  323. $f{'Changed-By'}= $forcechangedby if length($forcechangedby);
  324. for $f (qw(Version Distribution Maintainer Changes)) {
  325. defined($f{$f}) || &error(sprintf(_g("missing information for critical output field %s"), $f));
  326. }
  327. for $f (qw(Urgency)) {
  328. defined($f{$f}) || &warn(sprintf(_g("missing information for output field %s"), $f));
  329. }
  330. for $f (keys %override) { $f{&capit($f)}= $override{$f}; }
  331. for $f (keys %remove) { delete $f{&capit($f)}; }
  332. &outputclose(0);