[Pkg-haskell-commits] darcs: tools: Allow applying patches to cabal files before running cabal-install on it

Joachim Breitner mail at joachim-breitner.de
Fri Jun 14 22:09:16 UTC 2013


Fri Jun 14 22:08:35 UTC 2013  Joachim Breitner <mail at joachim-breitner.de>
  * Allow applying patches to cabal files before running cabal-install on it

    M ./all-packages/test-packages.pl -1 +39

Fri Jun 14 22:08:35 UTC 2013  Joachim Breitner <mail at joachim-breitner.de>
  * Allow applying patches to cabal files before running cabal-install on it
diff -rN -u old-tools/all-packages/test-packages.pl new-tools/all-packages/test-packages.pl
--- old-tools/all-packages/test-packages.pl	2013-06-14 22:09:16.167354982 +0000
+++ new-tools/all-packages/test-packages.pl	2013-06-14 22:09:16.183049969 +0000
@@ -6,6 +6,9 @@
 use Dpkg::Version;
 use Cwd;
 use File::Copy;
+use Archive::Tar;
+use File::Slurp;
+use Text::Patch;
 
 my %packages;
 my %versions;
@@ -64,6 +67,7 @@
 print "Creating local hackage \"repository\"...\n";
 system("rm -rf cabal-sandbox");
 my $sandboxdir = cwd() . "/cabal-sandbox";
+my $tarpath = "$sandboxdir/packages/debian/00-index.tar";
 mkdir "$sandboxdir" or die $!;
 mkdir "$sandboxdir/packages" or die $!;
 mkdir "$sandboxdir/packages/debian" or die $!;
@@ -79,7 +83,38 @@
   prefix: /does-not-exist
 __END__
 close CABALCONFIG or die $!;
-copy($ENV{HOME}."/.cabal/packages/hackage.haskell.org/00-index.tar", "$sandboxdir/packages/debian/00-index.tar") or die $!;
+copy($ENV{HOME}."/.cabal/packages/hackage.haskell.org/00-index.tar",$tarpath) or die $!;
+
+print "Applying patches to repository .cabal files...\n";
+my $tar = Archive::Tar->new($tarpath);
+for my $patchfile (<./patches/*>) {
+	unless ($patchfile =~ m!^./patches/(.*)-(.*?).patch$!) {
+		printf "Ignoring $patchfile, does not match naming scheme <pkg>-<version>.patch\n";
+		next
+	}
+	my $pkg = $1;
+	my $version = $2;
+	unless (exists $versions{$pkg}) {
+		printf "Ignoring patch for %s-%s, not listed in all-packages.txt\n", $pkg ,$version;
+		next
+	}
+	unless ($version eq $versions{$pkg}) {
+		printf "Ignoring patch for %s-%s, version does not match %s in all-packages.txt\n", $pkg ,$version, $versions{$pkg};
+		next
+	}
+	my $cabalpath = sprintf "%s/%s/%s.cabal", $pkg, $version, $pkg;
+	unless ($tar->contains_file($cabalpath)) {
+		printf "File %s not found in 00-index.tar", $cabalpath;
+		next
+	}
+	my ($tarfile) = $tar->get_files($cabalpath);
+	printf "Patching %s.cabal (version %s)\n", $pkg, $version;
+	my $old = $tarfile->get_content();
+	my $patch = read_file($patchfile);
+	my $new = patch($old, $patch, STYLE => "Unified");
+	$tarfile->replace_content($new) or die;
+}
+$tar->write($tarpath);
 
 
 print "Creating all-packages.cabal...\n";
@@ -120,3 +155,6 @@
 
 print "Running cabal-install...\n";
 (system @params) == 0 or die "cabal install failed: $?";
+
+
+system("rm -rf cabal-sandbox");




More information about the Pkg-haskell-commits mailing list