logging working in NewParallel, but changed to be default. Need to figure out how...
[scons.git] / SCons / Tool / PharLapCommon.py
blob9ffafa9e51492c93d29a800df9a6bdfd3e626b6f
1 """SCons.Tool.PharLapCommon
3 This module contains common code used by all Tools for the
4 Phar Lap ETS tool chain. Right now, this is linkloc and
5 386asm.
7 """
10 # __COPYRIGHT__
12 # Permission is hereby granted, free of charge, to any person obtaining
13 # a copy of this software and associated documentation files (the
14 # "Software"), to deal in the Software without restriction, including
15 # without limitation the rights to use, copy, modify, merge, publish,
16 # distribute, sublicense, and/or sell copies of the Software, and to
17 # permit persons to whom the Software is furnished to do so, subject to
18 # the following conditions:
20 # The above copyright notice and this permission notice shall be included
21 # in all copies or substantial portions of the Software.
23 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
24 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
25 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
34 import os
35 import os.path
36 import SCons.Errors
37 import SCons.Util
38 import re
40 def getPharLapPath():
41 """Reads the registry to find the installed path of the Phar Lap ETS
42 development kit.
44 Raises UserError if no installed version of Phar Lap can
45 be found."""
47 if not SCons.Util.can_read_reg:
48 raise SCons.Errors.InternalError("No Windows registry module was found")
49 try:
50 k=SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE,
51 'SOFTWARE\\Pharlap\\ETS')
52 val, type = SCons.Util.RegQueryValueEx(k, 'BaseDir')
54 # The following is a hack...there is (not surprisingly)
55 # an odd issue in the Phar Lap plug in that inserts
56 # a bunch of junk data after the phar lap path in the
57 # registry. We must trim it.
58 idx=val.find('\0')
59 if idx >= 0:
60 val = val[:idx]
62 return os.path.normpath(val)
63 except SCons.Util.RegError:
64 raise SCons.Errors.UserError("Cannot find Phar Lap ETS path in the registry. Is it installed properly?")
66 REGEX_ETS_VER = re.compile(r'#define\s+ETS_VER\s+([0-9]+)')
68 def getPharLapVersion():
69 """Returns the version of the installed ETS Tool Suite as a
70 decimal number. This version comes from the ETS_VER #define in
71 the embkern.h header. For example, '#define ETS_VER 1010' (which
72 is what Phar Lap 10.1 defines) would cause this method to return
73 1010. Phar Lap 9.1 does not have such a #define, but this method
74 will return 910 as a default.
76 Raises UserError if no installed version of Phar Lap can
77 be found."""
79 include_path = os.path.join(getPharLapPath(), os.path.normpath("include/embkern.h"))
80 if not os.path.exists(include_path):
81 raise SCons.Errors.UserError("Cannot find embkern.h in ETS include directory.\nIs Phar Lap ETS installed properly?")
82 with open(include_path, 'r') as f:
83 mo = REGEX_ETS_VER.search(f.read())
84 if mo:
85 return int(mo.group(1))
86 # Default return for Phar Lap 9.1
87 return 910
89 def addPharLapPaths(env):
90 """This function adds the path to the Phar Lap binaries, includes,
91 and libraries, if they are not already there."""
92 ph_path = getPharLapPath()
94 try:
95 env_dict = env['ENV']
96 except KeyError:
97 env_dict = {}
98 env['ENV'] = env_dict
99 SCons.Util.AddPathIfNotExists(env_dict, 'PATH',
100 os.path.join(ph_path, 'bin'))
101 SCons.Util.AddPathIfNotExists(env_dict, 'INCLUDE',
102 os.path.join(ph_path, 'include'))
103 SCons.Util.AddPathIfNotExists(env_dict, 'LIB',
104 os.path.join(ph_path, 'lib'))
105 SCons.Util.AddPathIfNotExists(env_dict, 'LIB',
106 os.path.join(ph_path, os.path.normpath('lib/vclib')))
108 env['PHARLAP_PATH'] = getPharLapPath()
109 env['PHARLAP_VERSION'] = str(getPharLapVersion())
112 # Local Variables:
113 # tab-width:4
114 # indent-tabs-mode:nil
115 # End:
116 # vim: set expandtab tabstop=4 shiftwidth=4: