-
-
Save ChristopherBiscardi/50e7128d1c9f0c4e496a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; | |
} | |
} | |
} | |
"constraints:\n", | |
join(",\n", @constrs), | |
"\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment