forked from reflex-frp/reflex-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
work-on
executable file
·47 lines (40 loc) · 2.07 KB
/
work-on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
set -euo pipefail
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
if [ "$#" -lt 2 ] ; then
echo "Usage: $0 PLATFORM PACKAGE ..."
echo " PLATFORM can be either \"ghc\" or \"ghcjs\""
echo " PACKAGE can be any cabal package name or a path (including at least one '/' character) to a nix expression representing a cabal package"
echo " Any extra arguments will be passed along to nix-shell"
echo
echo "This script will drop you into a nix shell with access to the prerequisites of the chosen package on the chosen platform. From there, you should be able to cabal configure [--ghcjs], cabal build, and cabal test. Note that cabal install will not interoperate with Nix packages, and may not work at all."
exit 1
fi
. "$DIR/common-setup.sh"
PLATFORM="$1"
shift
PACKAGE="$1"
shift
if echo "$PLATFORM" | grep -q '^(.*)$' ; then
EFFECTIVE_PLATFORM="$PLATFORM"
elif echo "$PLATFORM" | grep -q / ; then
PLATFORM_PATH="$(cleanup_nix_path "$PLATFORM")"
EFFECTIVE_PLATFORM="(import $PLATFORM { reflex-platform = this; try-reflex = builtins.trace \"WARNING: the try-reflex parameter is deprecated; please update your script to refer to reflex-platform instead\" this; })"
else
EFFECTIVE_PLATFORM="this.$PLATFORM"
fi
if echo "$PACKAGE" | grep -q / ; then
# Package name includes a slash
PACKAGE_PATH="$(cleanup_nix_path "$PACKAGE")"
if ( echo "$PACKAGE_PATH" | grep -q '\.nix$' && [ -f "$PACKAGE_PATH" ] ) || [ -f "$PACKAGE_PATH/default.nix" ] ; then
PACKAGE_INVOCATION="($EFFECTIVE_PLATFORM.callPackage $PACKAGE_PATH {})"
elif test -n "$(shopt -s nullglob ; echo "$PACKAGE_PATH"/*.cabal)" ; then
PACKAGE_INVOCATION="($EFFECTIVE_PLATFORM.callPackage (this.cabal2nixResult $PACKAGE_PATH) {})"
else
user_error 1 "Error: The given path must be a nix expression, a directory with a default.nix, or a directory with a cabal file"
fi
else
PACKAGE_INVOCATION="$EFFECTIVE_PLATFORM.$PACKAGE"
fi
terminate_logging
nix-shell $NIXOPTS -E "let this = import $DIR/. {}; in this.workOn $EFFECTIVE_PLATFORM $PACKAGE_INVOCATION" "$@"