Last active
February 27, 2017 07:59
-
-
Save hvr/9874c7838f93739ea154649b597ded0f to your computer and use it in GitHub Desktop.
Quick'n'dirty cabal new-build exe-symlink script
This file contains 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/env python | |
import sys | |
import os | |
import os.path | |
import json | |
plan = json.load(open("dist-newstyle/cache/plan.json")) | |
cabal_version = list(map(int,plan["cabal-version"].split('.'))) | |
assert cabal_version >= [1,25] | |
if len(sys.argv) != 4: | |
print("usage: link_cabal_exe.py pkgid exe-name symlink-file") | |
sys.exit(1) | |
[_,pkgn,exeid,target] = sys.argv | |
exes = [ x.get("bin-file") for x in plan["install-plan"] if x.get("pkg-name") == pkgn and x.get("component-name") == "exe:"+exeid ] | |
if len(exes) > 1: | |
print("WTF... found multiple entries in plan.json file") | |
sys.exit(2) | |
elif len(exes) < 1: | |
print("target not found in plan.json") | |
sys.exit(2) | |
[exe] = exes | |
exe = os.path.relpath(os.path.abspath(exe), os.path.abspath(os.path.dirname(target))) | |
if os.path.islink(target): | |
if os.readlink(target) == exe: | |
#print("proper symlink exists already, nothing to do") | |
sys.exit(0) # no-op | |
print("Found symlink pointing to wrong destination. Resetting to proper destination...") | |
os.unlink(target) | |
elif os.path.exists(target): | |
print("ERROR: non-symlink detected at '{}'".format(target)) | |
sys.exit(3) | |
os.symlink(exe, target) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment