How can I uninstall a version of a Cabal package? - haskell

Happstack Lite is breaking on me because it's getting blaze-html version 0.5 and it wants version 0.4. Cabal says that both versions 0.4.3.4 and 0.5.0.0 are installed. I want to remove the 0.5.0.0 and use just the older version. But cabal does not have an "uninstall" command, and when I try ghc-pkg unregister --force blaze-html, ghc-pkg says my command has been ignored.
What do I do?
UPDATE: Don't believe it. Although ghc-pkg claims to ignore the command, the command isn't ignored. And with Don Stewart's accepted answer you can remove exactly the version you wish to eliminate.

You can ghc-pkg unregister a specific version, like so:
$ ghc-pkg unregister --force regex-compat-0.95.1
That should be sufficient.

If you are outside a sandbox:
ghc-pkg unregister --force regex-compat-0.95.1
If you are inside a cabal sandbox:
cabal sandbox hc-pkg -- unregister attoparsec --force
The first -- is the argument separator for hc-pkg. This runs ghc-pkg in a sandbox aware manner.

There is also the cabal-uninstall package which provides a cabal-uninstall command. It unregisters the package and deletes the folder. It is worth mentioning though that it passes --force to ghc-pkg unregister so it can break other packages.

Here's a shell script I use to uninstall a package. It supports multiple installed versions of GHC and also wipes relevant files (but is provided without warranty, don't blame me if you hose your installation!)
#!/bin/bash -eu
# Usage: ./uninstall.sh [--force | --no-unregister] pkgname-version
# if you set VER in the environment to e.g. "-7.0.1" you can use
# the ghc-pkg associated with a different GHC version
: ${VER:=}
if [ "$#" -lt 1 ]
then
echo "Usage: $0 [--force | --no-unregister] pkgname-version"
exit 1
fi
if [ "$1" == "--force" ]
then force=--force; shift; # passed to ghc-pkg unregister
else force=
fi
if [ "$1" == "--no-unregister" ]
then shift # skip unregistering and just delete files
else
if [ "$(ghc-pkg$VER latest $1)" != "$1" ]
then
# full version not specified: list options and exit
ghc-pkg$VER list $1; exit 1
fi
ghc-pkg$VER unregister $force $1
fi
# wipe library files
rm -rfv -- ~/.cabal/lib/$1/ghc-$(ghc$VER --numeric-version)/
# if the directory is left empty, i.e. not on any other GHC version
if rmdir -- ~/.cabal/lib/$1
then rm -rfv -- ~/.cabal/share/{,doc/}$1 # then wipe the shared files as well
fi

Related

How to use Sass with NetBeans on Linux / macOS

I used to be able to install and use Sass with NetBeans 8 as described in the top answer on How to use SASS with Netbeans 8.0.1
Now, with the current version of Sass (1.14.1), installing is different. Basically just download and untar. That's done and I've pointed NetBeans to the correct location. But this current version of Sass won't run correctly from NetBeans:
"/opt/dart-sass/sass" "--cache-location"
"/home/jasper/.cache/netbeans/8.2/sass-compiler"
"path_to_my.scss" "path_to_my.css"
Could not find an option named "cache-location".
This error is also covered by Sass output error in Netbeans 8.2 where they are using Windows.
I tried to add the cache location parameter (similar to the solution for Windows) to this line in the sass file:
exec "$path/src/dart" --no-preview-dart-2 "-Dversion=1.14.1" "$path/src/sass.dart.snapshot" "$#"
but I could not get it working (same error keeps appearing).
Anybody any ideas on how to get Sass 1.14.1 working from NetBeans 8.2 on Linux (Ubuntu)?
The issue is that --cache-location is no longer supported and should be removed. All of the original parameters are used by "$#". To remove the first two parameters, you should be able to use "${#:3}" (see Process all arguments except the first one (in a bash script)), but somehow that resulted into a "Bad substitution" error for me. So I opted to use shift 2 to remove them:
#!/bin/sh
# Copyright 2016 Google Inc. Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
# This script drives the standalone Sass package, which bundles together a Dart
# executable and a snapshot of Sass. It can be created with `pub run grinder
# package`.
follow_links() {
file="$1"
while [ -h "$file" ]; do
# On Mac OS, readlink -f doesn't work.
file="$(readlink "$file")"
done
echo "$file"
}
# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
path=`dirname "$(follow_links "$0")"`
shift 2
exec "$path/src/dart" --no-preview-dart-2 "-Dversion=1.14.1" "$path/src/sass.dart.snapshot" "${#}"
Make sure to keep the original file and create a copy to only be used with NetBeans and make the change there.
macOS (Home Brew)
If you are looking for the Dart Sass install location (after installing it with Home Brew), it is located here:
/usr/local/Cellar/sass/{version}/bin
macOS (node.js)
When using node.js, you will run into the "env: node: No such file or directory" issue.
To work around that I created (make sure you make it executable (chmod a+x)):
/usr/local/lib/node_modules/sass/sass_nb.sh
and added:
#!/bin/zsh
export PATH="$PATH:"/usr/local/bin/
shift 3
sass ${#}
NetBeans 11+
On NetBeans 11 and 12 I had to use shift 3 instead of shift 2.
My response is based heavily on Jasper de Vries'one:
It seems that Netbeans simply adds some additional parameters that are no longer supported by sass compiler.
In my case the complete command issued by Netbeans was:
"/home/alex/tools/dart-sass/sass" "--cache-location" "/home/alex/snap/netbeans/common/cache/12.0/sass-compiler" "--debug-info" "/home/alex/projects/alexgheorghiu.com/web/aaa.scss" "/home/alex/projects/alexgheorghiu.com/web/aaa.css"
So the first 3 parameters
"--cache-location" "/home/alex/snap/netbeans/common/cache/12.0/sass-compiler" "--debug-info"
must be "deleted" or ignored.
So you need to either alter the sass file or make a copy of it (safest way)
and add
shift 3
instruction.
So if you start from original version like:
#!/bin/sh
# This script drives the standalone dart-sass package, which bundles together a
# Dart executable and a snapshot of dart-sass.
follow_links() {
file="$1"
while [ -h "$file" ]; do
# On Mac OS, readlink -f doesn't work.
file="$(readlink "$file")"
done
echo "$file"
}
# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
path=`dirname "$(follow_links "$0")"`
exec "$path/src/dart" "$path/src/sass.snapshot" "$#"
You need to end up with something like:
#!/bin/sh
# This script drives the standalone dart-sass package, which bundles together a
# Dart executable and a snapshot of dart-sass.
follow_links() {
file="$1"
while [ -h "$file" ]; do
# On Mac OS, readlink -f doesn't work.
file="$(readlink "$file")"
done
echo "$file"
}
# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
path=`dirname "$(follow_links "$0")"`
shift 3
exec "$path/src/dart" "$path/src/sass.snapshot" "$#"
An interesting aspect is that this bug is known by Netbeans developers (See: Could not find an option named "cache-location") but I was not able to achieve that because under my Xubuntu 18 the Netbeans is a "snap" and therefore it's netbeans.conf file is read only.
But in case you CAN modify that file it might be a cleaner solution.

Getting a list of `PackageDescriptions` from the local database

Is there anyway, presumably using the Cabal package, to get a list of PackageDesciptions in the current local database?
I don't know if there's a "built-in"-way of doing this, but I've used this
ghc-pkg list | grep -v "\(^/\|^$\|(\)" | xargs cabal info | grep "\(^\*\|License\)"
to extract "License" info for all installed packages.
If you use stack or cabal-sandbox - the first command needs to be replaced by either stack exec -- ghc-pkg list or cabal sandbox hc-pkg list.
the (first) regex removes the path-lines like /opt/ghc/8.0.2/lib/ghc-8.0.2/package.conf.d, empty lines and lines starting with ( - somehow the colored lines produced by ghc-pkg like ghc-8.0.2 end up with starting ( in my terminal when grepping.
"map cabal info over all packages"
[optional] extracting the package information for the package itself (starting with * and the License field.
I hope this is what you were looking for. Another way, I think, would be writing a haskell program and use Cabal as a library.

Use different filename for npm than "package.json"

Is there a way to tell npm from the command line to use a different file than "package.json"?
Edit:
Thank you for your answers. I already checked the docs and hoped there was a workaround or a non-documented way to achieve that. I'll think of something else then.
Using only client-space tools, it seems pretty straightforward you can't. npm doc is positive about this :
A package is:
a) a folder containing a program described by a package.json file
b) a gzipped tarball containing (a)
c) a url thatresolves to (b)
d) a <name>#<version> that is published on theregistry with (c)
e) a <name>#<tag> that points to (d)
f) a <name>that has a "latest" tag satisfying (e)
g) a git url that, when cloned,results in (a).
[...]
You need to have a package.json file in the root of your project to do
much of anything with npm. That is basically the whole interface.
source : npm doc
As you can see, they make it really clear a package.json is required for anything to work.
You'd have to dig into the code, for a result which would not be reusable. If it's what you want, please make it clear in your question for others to understand why it's necessary.
Nope. As described in the npm-install docs, this is the only syntaxes you can use :
npm install (with no args in a package dir)
npm install <tarball file>
npm install <tarball url>
npm install <folder>
npm install [#<scope>/]<name> [--save|--save-dev|--save-optional] [--save-exact]
npm install [#<scope>/]<name>#<tag>
npm install [#<scope>/]<name>#<version>
npm install [#<scope>/]<name>#<version range>
npm i (with any of the previous argument usage)
With no args, the command will install a folder containing a program described by a package.json file.
I've end up with following bash script which I've included in $PATH
#!/bin/bash
# npm.sh - script will symlik pkg.json to package.json and execute specified npm commands
#
# usage:
# npm.sh <pkg.json> <npm commands>
#
# example:
# npm.sh some.package.json install
# npm.sh some.other.package.json run build
package_json=$1
if [ "$#" -lt 2 ]; then
echo "Illegal number of parameters"
exit 1
fi
if [ ! -e "${package_json}" ]; then
echo "Non existing file"
exit 1
fi
if [ "${package_json}" = "package.json" ]; then
echo "Cannot link to same file"
exit 1
fi
if [ -f "package.json" ]; then
if [ ! -L "package.json" ]; then
cp "package.json" "package.json.bak"
fi
fi
ln -fs "${package_json}" package.json
npm ${#:2}

Don't add "+" to linux kernel version

I am building linux kernel, if my kernel under git, then kernel version every time is:
Image Name: Linux-2.6.39+
If I am not using git, then everything is OK without any plus at the end.
I know that this done by scripts/setlocalversion script:
if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then
# full scm version string
res="$res$(scm_version)"
else
# append a plus sign if the repository is not in a clean
# annotated or signed tagged state (as git describe only
# looks at signed or annotated tags - git tag -a/-s) and
# LOCALVERSION= is not specified
if test "${LOCALVERSION+set}" != "set"; then
scm=$(scm_version --short)
res="$res${scm:++}"
fi
fi
So, it is possible without code changes say to build system that no need to add "+" at the end of version line?
The plus sign at the end of your version string is there as an indicator that the kernel was built from modified sources (that is, there were non-committed changes). This is also indicated by the comments in scripts/setlocalversion.
To avoid the '+' being appended despite having a dirty working directory, simply set LOCALVERSION explicityly when running make:
make LOCALVERSION=
You may also have to change the configuration option CONFIG_LOCALVERSION_AUTO to n in your kernel config (.config) before building:
sed -i "s|CONFIG_LOCALVERSION_AUTO=.*|CONFIG_LOCALVERSION_AUTO=n|" .config
To prevent the script scripts/setlocalversion to append the + to the end of the kernel local version, create an empty .scmversion file in the root of the kernel sources.
touch .scmversion
this way, you'll be able to leave LOCALVERSION as is in the kernel configuration file, in case you want to append a local signature to the kernel name.
Manipulating scripts/setlocalversion seems to be the only way for me.
Force return in scm_version():
scm_version()
{
local short
short=false
**return**
Add this line to your local.conf if you're using yocto and imx soc
SCMVERSION_pn-linux-imx = ""
Tested on imx-4.9.88-2.0.0_ga release
Just comment the line as a workaround/quickfix in scripts/setlocalversion. Then the kernel version should be same as "make kernelversion".
# Check for git and a git repo.
if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
head=$(git rev-parse --verify HEAD 2>/dev/null); then
# If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
# it, because this version is defined in the top level Makefile.
if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then
# If only the short version is requested, don't bother
# running further git commands
if $short; then
#echo "+" #comment this line
return
fi

How to use an older version of gcc in Linux

In Linux I am trying to compile something that uses the -fwritable-strings option. Apparently this is a gcc option that doesn't work in newer version of gcc. I installed gcc-3.4 on my system, but I think the newer version is still being used because I'm still get the error that says it can't recognize the command line option -fwritable-strings. How can I get make to use the older version of gcc?
You say nothing about the build system in use, but usually old versions of gcc can be invoked explicitly, by something like (this is for an autotools-based build):
./configure CXX=g++-3.4 CC=gcc-3.4
For a make-based build system, sometimes this will work:
make CXX=g++-3.4 CC=gcc-3.4
Most makefiles ought to recognise overriding CC and CXX in this way.
If editing the configuration/Makefile is not an option, Linux includes a utility called update-alternatives for such situations. However, it's a pain to use (links to various tutorials included below).
This is a little simpler - here's a script (from here) to easily switch your default gcc/g++ version:
#!/bin/bash
usage() {
echo
echo Sets the default version of gcc, g++, etc
echo Usage:
echo
echo " gcc-set-default-version <VERSION>"
echo
exit
}
cd /usr/bin
if [ -z $1 ] ; then
usage;
fi
set_default() {
if [ -e "$1-$2" ] ; then
echo $1-$2 is now the default
ln -sf $1-$2 $1
else
echo $1-$2 is not installed
fi
}
for i in gcc cpp g++ gcov gccbug ; do
set_default $i $1
done
If you 1) name this script switch-gcc, 2) put it in your path, and 3) make it executable (chmod +x switch-gcc), you can then switch compiler versions just by running
sudo switch-gcc 3.2
Further reading on update-alternatives:
https://lektiondestages.blogspot.com/2013/05/installing-and-switching-gccg-versions.html
https://codeyarns.com/2015/02/26/how-to-switch-gcc-version-using-update-alternatives/
https://askubuntu.com/questions/26498/choose-gcc-and-g-version
Maybe you could just give the whole path of the gcc-3.4 install while compiling your program:
/path_to_gcc_3.4/gcc your_program
If you can find where the writeable strings are actually being used, another possibility would be to use strdup and free on the subset of literal strings that the code is actually editing. This might be more complicated than downgrading versions of GCC, but will make the code much more portable.
Edit
In response to the clarification question / comment below, if you saw something like:
char* str = "XXX";
str[1] = 'Y';
str[2] = 'Z';
// ... use of str ...
You would replace the above with something like:
char* str = strdup("XXX");
str[1] = 'Y';
str[2] = 'Z';
// ... use of str ...
free(str);
And where you previously had:
char* str = "Some string that isn't modified";
You would replace the above with:
const char* str = "Some string that isn't modified";
Assuming you made these fixes, "-fwritable-strings" would no longer be necessary.

Resources