What's the best workaround for not having "cabal upgrade"? - haskell

I want to upgrade all packages, not just a specific one with cabal install --upgrade-dependencies.

This bit of shell hackery works for me on OS X:
cabal list --simple-output --installed | awk '{print $1}' | uniq | xargs -I {} cabal install {} --reinstall
EDIT: Now forces a reinstall, and avoids installing a package more than once when more than one version is present. Thanks for the comments!
EDIT YEARS LATER: Now that Cabal sandboxes and Stack exist, I strongly recommend against trying to upgrade packages in place. You'll end up with far fewer headaches if you instead can just wipe out an existing sandbox and reinstall up-to-date dependencies.

The .cabal/world file contains a list of every package you installed explicitly (listed in a cabal install command, as opposed to pulled through dependencies). Trim it to remove packages that are only useful as dependencies, packages that are deprecated, and version-locked packages that you'd rather upgrade.
Cabal doesn't know how to clean-up after itself, but you can remove almost everything. The next command will reinstall from .cabal/packages (a tarball cache):
cp -t bin .cabal/bin/cabal
rm -rf .cabal/{bin,lib,share} .ghc/*-*-*/
ghc-pkg check |&egrep -- '^[A-Za-z0-9-]+-[0-9]' |xargs -n1 --no-run-if-empty ghc-pkg unregister
Now reinstall everything that was manually installed:
cabal install world --upgrade-dependencies --force-reinstalls

Related

"cabal install cabal-install" doesn't update cabal version in OSX

I'm a newbie to haskell and cabal, so I'm probably missing something simple.
I updated cabal-install:
sudo cabal install cabal-install
Password:
Resolving dependencies...
Configuring cabal-install-1.22.0.0...
Building cabal-install-1.22.0.0...
Installed cabal-install-1.22.0.0
Updating documentation index
However cabal --version says:
cabal-install version 1.18.0.5
using version 1.18.1.4 of the Cabal library
What happened to cabal-install 1.22.0.0?
There are two ways of making cabal install packages globally. Note that, as a result, cabal may require sudo.
This command will install <PACKAGE> globally:
$ cabal install <PACKAGE> --global
As a more general solution, edit the file ~/.cabal/config and set user-install to False. This will automatically set the --global flag so you can just write cabal install <PACKAGE> without any worry. Here's a snippet of my config file:
...
-- split-objs: False
-- executable-stripping: True
user-install: False
-- package-db:
-- flags:
...
You may also want to set root-cmd to sudo if it's not already, so that cabal will automatically prompt for the root password when it encounters a permission problem.
There's some more info online here.
I see that there's an updated cabal at ~/Library/Haskell/bin, so I could replace /usr/bin/cabal with a symbolic link to this copy or I could copy this binary to /usr/bin.
I'm still interested if there is a more elegant/canonical way to make sure the new cabal is what gets used by default.
TLDR: Try running hash -r
Bash has a PATH hashtable that maps commands to the location of binaries. You may still have an old version of cabal installed somewhere in your PATH (possibly in a sandbox). Since cabal is not a new command, the hashtable will keep serving up the old version. hash -r rebuilds the hashtable, so the shell will correctly find the new version (providing it appears earlier in your path than the old one).

Cabal: where does `cabal update` store its package list?

(I'm on OS X 10.9)
I run this:
$ cabal update
$ cabal install haskell-platform
cabal: There is no package named 'haskell-platform'.
You may need to run 'cabal update' to get the latest list of available packages.
I installed cabal-install with user:
$ cabal install --user cabal-install
$ which cabal
/Users/sambo/.cabal/bin/cabal
after nuking my Haskell installation with with this that I found online:
$ sudo rm -rf /Library/Frameworks/GHC.framework
$ sudo rm -rf /Library/Frameworks/HaskellPlatform.framework
$ sudo rm -rf /Library/Haskell
$ sudo rm -rf /usr/share/doc/ghc
$ sudo rm /usr/share/man/man1/ghc.1
$ sudo rm -rf /var/db/receipts/org.haskell.HaskellPlatform.*
$ sudo rm -rf ~/.cabal
$ sudo rm -rf ~/.ghc
$ sudo rm -rf ~/Library/Haskell
$ find /usr/bin /usr/local/bin -type l | \
xargs -If sh -c '/bin/echo -n f /; readlink f' | \
egrep '//Library/(Haskell|Frameworks/(GHC|HaskellPlatform).framework)' | \
cut -f 1 -d ' ' | \
xargs sudo rm -f
I'd be okay with a hard reinstall of Haskell, which I had installed with homebrew. Which is what I was trying to do, but seems botched.
I don't really understand your problem, but Cabal stores package list in:
.cabal/packages/hackage.haskell.org/00-index.tar.gz.etag
.cabal/packages/hackage.haskell.org/00-index.cache
.cabal/packages/hackage.haskell.org/00-index.tar.gz
.cabal/packages/hackage.haskell.org/00-index.tar
Here's a tip to manage your Haskell installation: Don't install Haskell Platform. Using your package manager(I guess that's brew on a Mac), install latest GHC(7.8.3), Cabal and cabal-install. After that run cabal update and cabal install Cabal cabal-install again, just to update your Cabal installations in case it's old. Then remove your system-wide installed Cabal, and add ~/.cabal/bin to your path. You should now have cabal sandbox functionality working, install everything in sandboxes.
UPDATE: If your package manager doesn't have GHC 7.8.3: Just install whatever version it has, and install Cabal and cabal-install as I described. Then remove package manager's GHC and install latest pre-compiled version from http://www.haskell.org/ghc/download_ghc_7_8_3.
If you package manager's GHC is not new enough to compile latest Cabal and cabal-install, then you need to boot libraries, starting from older GHC and older Cabal and then updating GHC, installing newer Cabal using up-to-date GHC and older Cabal etc.
Just don't install Haskell Platform, it's just not worth the pain.

Get the Perl rename utility instead of the built-in rename

Many sites (including various SO articles) talk about using "rename" using Perl expressions to rename files.
This would be perfect, but apparently this is not the rename utility I have, and none of these articles seem to comprehend that there are multiple versions of "rename" and I can't seem to find where to get version that accepts Perl expressions.
How can I get my hands on the more powerful rename utility mentioned here, here, and here?
I'm running Fedora 20. My current rename command is from the util-linux package and apparently I need the Perl version, which is better.
I can only speak for Debian. The two programs are called
/usr/bin/rename.ul from the util-linux package (hence the .ul suffix)
/usr/bin/prename from the perl package
The actual rename command works via the /etc/alternatives mechanism, whereby
/usr/bin/rename is a symlink to /etc/alternatives/rename
/etc/alternatives/rename is a symlink to /usr/bin/prename
The same problem has been bugging me on Cygwin, which is a Red Hat product, so should be more similar to Fedora. I'll have a look on my company laptop on Monday. And I remember the Perl-rename having worked there sometimes. Probably before I installed util-linux.
If you install the Perl-rename to /usr/local/bin it will have precedence over rename from util-linux. Same goes for the manpage when installed to /usr/local/share/man/man1/.
I've just created a separate Perl-rename package on Github: https://github.com/subogero/rename
You can install it using cpan, which is the perl repository similar to pip for python.
Here is a tutorial on using cpan.
If you try to run rename it it looks like this
rename --help
call: rename from to files...
To install the perl rename you can do the following. You might need to install a few dependencies, you can generally just push enter
cpan
cpan1> install File::Rename
CPAN: Storable loaded ok (v2.20)
Going to read '/root/.cpan/Metadata'
Database was generated on Wed, 30 Sep 2015 08:17:02 GMT
Running install for module 'File::Rename'
....
Running Build install
Installing /usr/local/share/man/man1/rename.1
Installing /usr/local/share/perl5/File/Rename.pm
Installing /usr/local/share/man/man3/File::Rename.3pm
Installing /usr/local/bin/rename
Writing /usr/local/lib64/perl5/auto/File/Rename/.packlist
RMBARKER/File-Rename-0.20.tar.gz
./Build install -- OK
That is how you would install the rename from cpan.
Next is to get it working on your system. As you might have more then one rename installed.
which rename
/usr/bin/rename
When you actually want this one.
/usr/local/bin/rename --help
Usage:
rename [ -h|-m|-V ] [ -v ] [ -n ] [ -f ] [ -e|-E *perlexpr*]*|*perlexpr*
[ *files* ]
Options:
-v, -verbose
Verbose: print names of files successfully renamed.
-n, -nono
No action: print names of files to be renamed, but don't rename.
-f, -force
Over write: allow existing files to be over-written.
-h, -help
Help: print SYNOPSIS and OPTIONS.
-m, -man
Manual: print manual page.
-V, -version
Version: show version number.
-e Expression: code to act on files name.
May be repeated to build up code (like "perl -e"). If no -e, the
first argument is used as code.
-E Statement: code to act on files name, as -e but terminated by
';'.
I just put it into /usr/bin/ but with a slight different name to make sure I did not break any existing scripts / programs the depend on the old one.
ln -s /usr/local/bin/rename /usr/bin/rename.pl
I had to do the following:
# In bash
sudo yum install perl-CPAN
sudo cpan
# In CPAN shell
install Module::Build
install File::Rename
On RedHat 8.4
sudo yum install perl-CPAN
sudo cpan
install module::Build
install File::Rename
than you can create an alias:
alias prename='/usr/local/bin/rename'
an use:
touch pic.jpeg
prename 's/\.jpeg$/.jpg/' *.jpeg
For Debian-family (.deb) distros, I recommend #SzG's answer.
For RedHat-family (.rpm) distros (e.g. Fedora), if your time is precious (like mine), you can download, compile, and install, from source via cpan in one, terse command:
# Install (replace `rename-1.9` below with another version if desired)
curl -L "http://search.cpan.org/CPAN/authors/id/P/PE/PEDERST/rename-1.9.tar.gz" | tar -xz && ( cd "rename-1.9"; perl "Makefile.PL"; make && make install )
# Cleanup
rm -rf "rename-1.9"
Note:
INSTALL_BASE can be set to modify the base installation directory.
e.g. perl "Makefile.PL" INSTALL_BASE=/usr/local
source
For Arch Linux, its
sudo pacman -S perl-rename
I created a post about Perl's rename for many distro:
https://unix.stackexchange.com/a/727288/12574
rpm based distros:
dnf install prename
archlinux:
pacman -S perl-rename
*BSD:
pkg install p5-File-Rename
Debian like/Ubuntu
apt install rename
slackware:
slackbuild
I recently had to install the glorious Perl rename package to Alpine Linux in a Docker container for a Gitlab CI/CD operation:
apk update
apk add --no-cache make perl-utils
cpan File::Rename

Reinstall all depending packages with cabal manually [duplicate]

I want to compile my program with profiling, so I run:
$ cabal configure --enable-executable-profiling
...
$ cabal build
...
Could not find module 'Graphics.UI.GLUT':
Perhaps you havent installed the profiling libraries for package 'GLUT-2.2.2.0'?
...
$ # indeed I have not installed the prof libs for GLUT, so..
$ cabal install -p GLUT --reinstall
...
Could not find module 'Graphics.Rendering.OpenGL':
Perhaps you havent installed the profiling libraries for package 'OpenGL-2.4.0.1'?
...
So, the problem is, that unlike cabal's usual welcome behavior, cabal doesn't resolve the dependencies and install them when needing profiling libraries.
I can work around it by resolving the dependencies manually (by following errors that appear after a while of compiling):
$ cabal install -p OpenGLRaw --reinstall
$ cabal install -p StateVar --reinstall
$ cabal install -p Tensor --reinstall
$ cabal install -p ObjectName --reinstall
$ cabal install -p GLURaw --reinstall
$ cabal install -p OpenGL --reinstall
$ cabal install -p GLUT --reinstall
And then repeat for my next dependency..
Is there a better way to do this? i.e do make cabal do the work on its own as it does for normal libraries?
I've enabled library-profiling: True in my ~/.cabal/config file. From then on, any new installations will automatically enable profiling.
Unfortunately that still means I had to manually reinstall for the old packages already installed. Although, after a while of doing this manually, I now have most packages reinstalled with profiling enabled...
From a comment by Tom Lokhorst:
I do hope someone will come along with a better answer, one that would not require me to reinstall the complete Haskell Platform manually next time.
For future visitors:
The task of installing profiling versions of all installed libraries has become less of a chore, cabal (cabal-install) now keeps track of what was installed using it in the world file in the .cabal directory (on linux, that would be $HOME/.cabal, on Windows something like C:\Users\%YOU%\AppData\Roaming\cabal\, on OSX ??).
So after enabling profiling in the config file (in the same directory), and clearing GHC's package database (you can find the locations of the global and user db per ghc-pkg list nonexisting; remove the cabal-installed packages from the global database with ghc-pkg unregister packagename if you have any, rename or delete the entire user db - this is necessary because the world file only tracks explicitly installed packages, not their dependencies), installing everything with profiling support should work as follows:
$ cabal install --reinstall world --dry-run
First run with --dry-run to check for problems before actually reinstalling anything. If it would reinstall boot packages like process or directory, that's a bad sign, if you don't know how to handle it, ask on the #haskell IRC channel, one of the mailing lists, or here for guidance. If it fails to find a consistent install plan due to new versions on hackage of some packages which are incompatible with each other, that can usually be solved by editing the world file and constraining allowable versions of some packages.
Then, if you are optimistic that nothing will badly break,
$ cabal install --reinstall world
and have a nice pot of tea while GHC is busy compiling.
Daniel Fischer's answer looks good, but for some reason my ~/.cabal/world library only contained entries for libraries directly installed, and not their dependencies.
Instead, I dumped out a list of all installed libraries using
$ ghc-pkg list > list
This lists the libraries installed system-wide and locally. Therefore, I edited the list file to remove the first portion (containing libraries installed system-wide) leaving only the lines after /home/<user>/.ghc/.... Finally, I ran
$ cabal install --reinstall $(cat list)
This worked for me. You should maybe do --dry-run first. Then go make a pot of tea. Or bake a cake.
it appears there is no way right now: Ticket #282 - profiling versions of libraries not managed well "As usual the problem is lack of devevloper time to implement all these
nice features we all want."
For visitors 2016+: Just install ghc-prof
Debian Linux Systems:
sudo apt-get install ghc-prof
Arch Linux Systems:
sudo pacman -S ghc-prof

Cabal not installing dependencies when needing profiling libraries?

I want to compile my program with profiling, so I run:
$ cabal configure --enable-executable-profiling
...
$ cabal build
...
Could not find module 'Graphics.UI.GLUT':
Perhaps you havent installed the profiling libraries for package 'GLUT-2.2.2.0'?
...
$ # indeed I have not installed the prof libs for GLUT, so..
$ cabal install -p GLUT --reinstall
...
Could not find module 'Graphics.Rendering.OpenGL':
Perhaps you havent installed the profiling libraries for package 'OpenGL-2.4.0.1'?
...
So, the problem is, that unlike cabal's usual welcome behavior, cabal doesn't resolve the dependencies and install them when needing profiling libraries.
I can work around it by resolving the dependencies manually (by following errors that appear after a while of compiling):
$ cabal install -p OpenGLRaw --reinstall
$ cabal install -p StateVar --reinstall
$ cabal install -p Tensor --reinstall
$ cabal install -p ObjectName --reinstall
$ cabal install -p GLURaw --reinstall
$ cabal install -p OpenGL --reinstall
$ cabal install -p GLUT --reinstall
And then repeat for my next dependency..
Is there a better way to do this? i.e do make cabal do the work on its own as it does for normal libraries?
I've enabled library-profiling: True in my ~/.cabal/config file. From then on, any new installations will automatically enable profiling.
Unfortunately that still means I had to manually reinstall for the old packages already installed. Although, after a while of doing this manually, I now have most packages reinstalled with profiling enabled...
From a comment by Tom Lokhorst:
I do hope someone will come along with a better answer, one that would not require me to reinstall the complete Haskell Platform manually next time.
For future visitors:
The task of installing profiling versions of all installed libraries has become less of a chore, cabal (cabal-install) now keeps track of what was installed using it in the world file in the .cabal directory (on linux, that would be $HOME/.cabal, on Windows something like C:\Users\%YOU%\AppData\Roaming\cabal\, on OSX ??).
So after enabling profiling in the config file (in the same directory), and clearing GHC's package database (you can find the locations of the global and user db per ghc-pkg list nonexisting; remove the cabal-installed packages from the global database with ghc-pkg unregister packagename if you have any, rename or delete the entire user db - this is necessary because the world file only tracks explicitly installed packages, not their dependencies), installing everything with profiling support should work as follows:
$ cabal install --reinstall world --dry-run
First run with --dry-run to check for problems before actually reinstalling anything. If it would reinstall boot packages like process or directory, that's a bad sign, if you don't know how to handle it, ask on the #haskell IRC channel, one of the mailing lists, or here for guidance. If it fails to find a consistent install plan due to new versions on hackage of some packages which are incompatible with each other, that can usually be solved by editing the world file and constraining allowable versions of some packages.
Then, if you are optimistic that nothing will badly break,
$ cabal install --reinstall world
and have a nice pot of tea while GHC is busy compiling.
Daniel Fischer's answer looks good, but for some reason my ~/.cabal/world library only contained entries for libraries directly installed, and not their dependencies.
Instead, I dumped out a list of all installed libraries using
$ ghc-pkg list > list
This lists the libraries installed system-wide and locally. Therefore, I edited the list file to remove the first portion (containing libraries installed system-wide) leaving only the lines after /home/<user>/.ghc/.... Finally, I ran
$ cabal install --reinstall $(cat list)
This worked for me. You should maybe do --dry-run first. Then go make a pot of tea. Or bake a cake.
it appears there is no way right now: Ticket #282 - profiling versions of libraries not managed well "As usual the problem is lack of devevloper time to implement all these
nice features we all want."
For visitors 2016+: Just install ghc-prof
Debian Linux Systems:
sudo apt-get install ghc-prof
Arch Linux Systems:
sudo pacman -S ghc-prof

Resources