Skip to content

Instantly share code, notes, and snippets.

@UnkindPartition
Created June 16, 2014 06:17
Show Gist options
  • Save UnkindPartition/27534164554c62b6cd00 to your computer and use it in GitHub Desktop.
Save UnkindPartition/27534164554c62b6cd00 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# A script to generate constraints based on the package versions installed
# in a cabal sandbox.
#
# Like cabal freeze / cabal-constraints, but is not limited to a single
# package or build tree.
#
# For this to work, you have either to be in a directory with
# cabal.sandbox.config, or have the environment set up
# (see http://ro-che.info/articles/2014-03-05-cabal-sandbox-tips.html)
#
# Then the usage is simply
#
# gen-constraints >> cabal.config
use warnings;
use strict;
my $pkg_list;
open $pkg_list, "-|", "cabal sandbox hc-pkg list";
# state machine
# 0 = skipping
# 1 = interpreting
my $state = 0;
my @constrs;
while (<$pkg_list>) {
chomp;
if ( $state == 1 ) {
my ($pkg_name, $pkg_ver) =
/\s+(.*?)-([\d.]+)/ or next;
push @constrs, " $pkg_name == $pkg_ver";
} else
{
if ( /\.cabal-sandbox.*packages\.conf\.d/ ) {
$state = 1;
}
}
}
print
"constraints:\n",
join(",\n", @constrs),
"\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment