Skip to content

Instantly share code, notes, and snippets.

@kgadek
Created August 21, 2014 10:45
Show Gist options
  • Save kgadek/205f217edec07a70a4c3 to your computer and use it in GitHub Desktop.
Save kgadek/205f217edec07a70a4c3 to your computer and use it in GitHub Desktop.
def remove_all_of_haskell(noninteractive=False):
with _section("Finding all haskell artifacts..."):
remove = [
"~/.flowbox"
]
remove.extend(
local("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)' | awk '{print $1}'",
capture=True)
.split("\n")
)
remove.extend([
"/Library/Frameworks/GHC.framework",
"/Library/Frameworks/HaskellPlatform.framework",
"/Library/Haskell",
"~/.cabal",
"~/.ghc",
"~/Library/Haskell"
])
remove.extend( glob.glob(os.path.expanduser("~/.ghc-*")) )
remove = [ os.path.expanduser(d) for d in remove if d and os.path.exists(os.path.expanduser(d)) ]
if remove:
print(red(_f("To be removed:")))
for d in remove:
print(red(_f(" {d}")))
if noninteractive or confirm("Do you want to remove the directories listed above?\n"):
with _measured_time("Removing"):
for d in remove:
local(_f("trash {d}")) # this will err on global things… so far good, but TODO
else:
abort("I IZ CONFUSD. I quit.")
else:
print(green("No artifacts to be removed"))
_cabal_urls = {
"1.20.0.3": "http://www.haskell.org/cabal/release/cabal-install-1.20.0.3/cabal-install-1.20.0.3.tar.gz"
}
_ghc_urls = {
"7.8.3": "http://www.haskell.org/ghc/dist/7.8.3/ghc-7.8.3-x86_64-apple-darwin.tar.xz",
"7.8.2": "http://www.haskell.org/ghc/dist/7.8.2/ghc-7.8.2-x86_64-apple-darwin-mavericks.tar.xz",
"7.6.3": "http://www.haskell.org/ghc/dist/7.6.3/ghc-7.6.3-x86_64-apple-darwin.tar.bz2"
}
_default_ghc = "7.8.3"
_default_cabal = "1.20.0.3"
def get_fresh_ghc_cabal(ghc=None, ghc_prefix="~/.ghc-{ghc_ver}", cabal=None, noninteractive=False):
get_fresh_ghc(ghc, ghc_prefix, noninteractive)
get_fresh_cabal(cabal, noninteractive)
def get_fresh_ghc(ghc=None, ghc_prefix="~/.ghc-{ghc_ver}", cabal=None, noninteractive=False):
ghc_ver = ghc or _default_ghc
ghc_url = _ghc_urls[ghc_ver]
ghc_prefix = os.path.expanduser(_f(ghc_prefix))
ghc_current = os.path.expanduser("~/.ghc-current")
with _section("Verifying environment for haskell"):
if os.path.exists(ghc_prefix): abort(_f("{ghc_prefix} already exists"))
path = os.environ["PATH"].split(":")
for dir_in_path in ["~/.cabal/bin", "~/.ghc-current/bin"]:
if dir_in_path not in path and os.path.expanduser(dir_in_path) not in path:
abort(_f("You don't have {dir_in_path} in your PATH -- add it!"))
with _section(_f("Getting GHC {ghc_ver}")):
with _temporary_directory() as tmpdir:
if ghc_url.endswith(".tar.bz2"):
local(_f("curl {ghc_url} | bzcat | tar xf - --strip 1"))
else:
local(_f("curl {ghc_url} | tar xf - --strip 1"))
local(_f("./configure --prefix={ghc_prefix} && make install"))
with ignored(OSError):
os.remove(ghc_current)
os.symlink(ghc_prefix, ghc_current)
path_list = [ (file, path + os.sep + file)
for path in os.environ["PATH"].split(os.pathsep)
if os.path.isdir(path)
for file in os.listdir(path)
]
if ghc_ver.split(".") < "7.8.0".split("."):
gccs = sorted([ (file, path) for file, path in path_list if re.match('gcc-\d\.\d', file) ],
key=lambda x: x[0],
reverse=True)
gcc_command, gcc_path = gccs[0]
gccs = ', '.join(path for _, path in gccs[1:]) or 'no other [real] gcc available'
print(yellow(_f("GHC < 7.8.x requires *real* gcc. {gcc_path} selected. Alternatives: {gccs}")))
else:
gccs = sorted([ (file, path) for file, path in path_list if re.match('gcc$', file) ],
key=lambda x: x[0],
reverse=True)
gcc_command, gcc_path = gccs[0]
gccs = ', '.join(path for _, path in gccs[1:]) or 'no other [real] gcc available'
print(yellow(_f("GHC >= 7.8.x does not require any special gcc. {gcc_path} selected. Alternatives: {gccs}")))
opts = sorted([ (file, path) for file, path in path_list if re.match('opt-\d\.\d', file) ],
key=lambda x: x[0],
reverse=True)
llcs = sorted([ (file, path) for file, path in path_list if re.match('llc-\d\.\d', file) ],
key=lambda x: x[0],
reverse=True)
opt_command, opt_path = opts[0]
llc_command, llc_path = llcs[0]
opts = ', '.join(path for _, path in opts[1:]) or 'no other opt available'
llcs = ', '.join(path for _, path in llcs[1:]) or 'no other llc available'
print(yellow(_f("Some packages require full LLVM (missing `opt` and `llc`). {opt_path} & {llc_path} selected. Alternatives (opt): {opts}. Alternatives (llc): {llcs}.")))
print(yellow("Formatting the patch..."))
patch_ghcsettings = _f(patch_ghcsettings_template)
print('\n'.join(" | " + x for x in patch_ghcsettings.split('\n')))
print(yellow("Patching the settings file -- setting the correct path for gcc and opt..."))
_patch(patch_ghcsettings, "flowbox-env")
def get_fresh_cabal(cabal=None, noninteractive=False):
# abort("OKAY, this is weird but... for now, get binary cabal and then `cabal update && cabal install cabal-install`")
cabal_ver = cabal or _default_cabal
cabal_url = _cabal_urls[cabal_ver]
with _section("Verifying environment for cabal"):
if os.path.exists(os.path.expanduser("~/.cabal")): abort(_f("~/.cabal already exists"))
with _section(_f("Getting cabal {cabal_ver}")):
with _temporary_directory() as tmpdir:
local(_f("curl {cabal_url} | tar -zxf -"))
with lcd(_f("./cabal-install-{cabal_ver}")):
# print(red(_f("I'm sorry, but now you need to perform manual operation:\ncd {tmpdir} && ./bootstrap.sh --user --no-doc")))
# confirm("Press ENTER to continue")
local("./bootstrap.sh --no-doc --user")
local("cabal update")
def _patch(patch, workdir):
# with _section("Preparing flowbox - disabling CUDA", local_directory="flowbox"):
with lcd(workdir):
result = _local_withstdin("patch -u -p1 -N", patch, noerror=True)
try:
ret, out, err = result
except Exception, e:
ret, out, err, fn = result
if ret == 1 and "Reversed (or previously applied) patch detected" in out:
print(yellow("Patch seems to be already applied"))
else:
fn()
def get_fresh_flowbox():
with _section("Getting repositories"):
for repo in ["flowbox", "flowbox-env"]:
if not exists(repo):
local(_f("git clone [email protected]:wdanilo/{repo}.git"))
elif not isdir(repo):
abort(_f("path {repo} exists but does not look like a repository"))
with _section("Preparing flowbox - disabling CUDA"):
_patch(patch_nocuda, workdir="flowbox")
with _section("Bootstrap", local_directory="flowbox-env"):
# with prefix("PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig:PKG_CONFIG_PATH"):
local("./bootstrap.py ../flowbox -y --no-graphics --no-stdlib")
patch_nocuda = """--- a/flowbox/libs/graphics/graphics/graphics.tcabal
+++ b/flowbox/libs/graphics/graphics/graphics.tcabal
@@ -15,8 +15,8 @@ Flag ekg
Flag cuda
Description: Enable the CUDA parallel backend for NVIDIA GPUs
- Default: True
- --Default: False
+ --Default: True
+ Default: False
Flag opencl
Description: Enable the OpenCL parallel backend
"""
patch_ghcsettings_template = """--- a/flowbox-env/dist/darwin-x86_64/base/lib/ghc-7.6.3/settings
+++ b/flowbox-env/dist/darwin-x86_64/base/lib/ghc-7.6.3/settings
@@ -1,5 +1,5 @@
[("GCC extra via C opts", " -fwrapv"),
- ("C compiler command", "/usr/bin/gcc"),
+ ("C compiler command", "{gcc_path}"),
("C compiler flags", " -m64 -fno-stack-protector"),
("C compiler link flags", " -m64"),
("Haskell CPP command","/usr/bin/gcc"),
@@ -25,7 +25,7 @@
("target has .ident directive", "True"),
("target has subsections via symbols", "True"),
("Unregisterised", "NO"),
- ("LLVM llc command", "llc"),
- ("LLVM opt command", "opt")
+ ("LLVM llc command", "{llc_command}"),
+ ("LLVM opt command", "{opt_command}")
]
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment