1 |
jpye |
1854 |
import os, os.path, platform, subprocess |
2 |
jpye |
1853 |
from SCons.Script import * |
3 |
|
|
|
4 |
jpye |
2429 |
HKLM_GRAPHVIZ = r"SOFTWARE\AT&T Research Labs\Graphviz" |
5 |
|
|
|
6 |
jpye |
1854 |
munge = lambda s: s |
7 |
|
|
try: |
8 |
|
|
# if we have access to GetShortPathName, we'll use it... |
9 |
|
|
import win32api |
10 |
|
|
def munge1(s): |
11 |
|
|
s1 = s |
12 |
|
|
try: |
13 |
|
|
# we can only munge the path if it actually exists |
14 |
|
|
s1 = win32api.GetShortPathName(s) |
15 |
|
|
except: |
16 |
|
|
# if it doesn't exist, we just return the un-munged path |
17 |
|
|
pass |
18 |
|
|
return s1 |
19 |
|
|
munge = munge1 |
20 |
|
|
except: |
21 |
|
|
pass |
22 |
|
|
|
23 |
jpye |
1853 |
def generate(env): |
24 |
|
|
""" |
25 |
|
|
Detect Graphviz settings and add them to the environment. |
26 |
|
|
""" |
27 |
|
|
try: |
28 |
|
|
if platform.system()=="Windows": |
29 |
|
|
import _winreg |
30 |
|
|
x=_winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE) |
31 |
jpye |
2429 |
y= _winreg.OpenKey(x,HKLM_GRAPHVIZ) |
32 |
jpye |
1854 |
PATH,t = _winreg.QueryValueEx(y,"InstallPath") |
33 |
|
|
LIB = os.path.join(PATH,"lib") |
34 |
|
|
BIN = os.path.join(PATH,"bin") |
35 |
jpye |
2429 |
INCLUDE = os.path.join(PATH,"include","graphviz") |
36 |
jpye |
1853 |
|
37 |
jpye |
1854 |
env['GRAPHVIZ_CPPPATH'] = [munge(INCLUDE)] |
38 |
|
|
env['GRAPHVIZ_LIBPATH'] = [munge(BIN)] |
39 |
|
|
env['GRAPHVIZ_LIBS'] = ['gvc','graph'] |
40 |
jpye |
1853 |
env['HAVE_GRAPHVIZ'] = True |
41 |
|
|
|
42 |
|
|
else: |
43 |
jpye |
2426 |
env1 = env.Clone() |
44 |
|
|
env1['CPPPATH'] = None |
45 |
|
|
env1['LIBPATH'] = None |
46 |
|
|
env1['LIBS'] = None |
47 |
jpye |
2425 |
try: |
48 |
jpye |
2426 |
cmd = ['pkg-config','libgvc','libcgraph','--cflags','--libs'] |
49 |
jpye |
2425 |
env1.ParseConfig(cmd) |
50 |
jpye |
2426 |
# we might get an error from this with older versions of GraphViz, so failover to below... |
51 |
jpye |
2425 |
env['GRAPHVIZ_CPPPATH'] = env1.get('CPPPATH') |
52 |
|
|
env['GRAPHVIZ_LIBPATH'] = env1.get('LIBPATH') |
53 |
|
|
env['GRAPHVIZ_LIBS'] = env1.get('LIBS') |
54 |
|
|
env['HAVE_GRAPHVIZ'] = True |
55 |
|
|
except: |
56 |
jpye |
2426 |
cmd = ['pkg-config','libgvc','libagraph','--cflags','--libs'] |
57 |
jpye |
2425 |
env1.ParseConfig(cmd) |
58 |
|
|
env['GRAPHVIZ_CPPPATH'] = env1.get('CPPPATH') |
59 |
|
|
env['GRAPHVIZ_LIBPATH'] = env1.get('LIBPATH') |
60 |
|
|
env['GRAPHVIZ_LIBS'] = env1.get('LIBS') |
61 |
|
|
env['HAVE_GRAPHVIZ'] = True |
62 |
|
|
|
63 |
jpye |
1853 |
print "GRAPHVIZ_LIBS =",env.get('GRAPHVIZ_LIBS') |
64 |
|
|
print "GRAPHVIZ_LIBPATH =",env.get('GRAPHVIZ_LIBPATH') |
65 |
|
|
print "GRAPHVIZ_CPPPATH =",env.get('GRAPHVIZ_CPPPATH') |
66 |
|
|
|
67 |
jpye |
2429 |
except Exception,e: |
68 |
|
|
print "NO GRAPHVIZ (%s)" % str(e) |
69 |
jpye |
1853 |
env['HAVE_GRAPHVIZ'] = False |
70 |
|
|
|
71 |
|
|
def exists(env): |
72 |
|
|
""" |
73 |
|
|
Make sure this tool exists. |
74 |
|
|
""" |
75 |
jpye |
2429 |
print "CHECKING FOR GRAPHVIZ" |
76 |
jpye |
1853 |
if platform.system()=="Windows": |
77 |
|
|
try: |
78 |
|
|
import _winreg |
79 |
|
|
x=_winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE) |
80 |
jpye |
2429 |
y= _winreg.OpenKey(x,HKLM_GRAPHVIZ) |
81 |
|
|
INCLUDE,t = _winreg.QueryValueEx(y,'InstallPath') |
82 |
|
|
print "GRAPHVIZ EXISTS" |
83 |
jpye |
1853 |
return True |
84 |
|
|
except: |
85 |
jpye |
2429 |
print "GRAPHVIZ DOESN'T EXIST" |
86 |
jpye |
1853 |
return False |
87 |
|
|
else: |
88 |
jpye |
2429 |
print "NOT WINDOWS" |
89 |
jpye |
1853 |
if not subprocess.call('pkg-config libgvc libagraph --exists'): |
90 |
|
|
return True |
91 |
|
|
return False |
92 |
|
|
|