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
10 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
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__ = "src/engine/SCons/Tool/PharLapCommon.py 5023 2010/06/14 22:05:46 scons"
41 """Reads the registry to find the installed path of the Phar Lap ETS
44 Raises UserError if no installed version of Phar Lap can
47 if not SCons.Util.can_read_reg:
48 raise SCons.Errors.InternalError("No Windows registry module was found")
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.
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
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 mo = REGEX_ETS_VER.search(open(include_path, 'r').read())
84 return int(mo.group(1))
85 # Default return for Phar Lap 9.1
88 def addPathIfNotExists(env_dict, key, path, sep=os.pathsep):
89 """This function will take 'key' out of the dictionary
90 'env_dict', then add the path 'path' to that key if it is not
91 already there. This treats the value of env_dict[key] as if it
92 has a similar format to the PATH variable...a list of paths
93 separated by tokens. The 'path' will get added to the list if it
94 is not already there."""
98 if not SCons.Util.is_List(env_dict[key]):
99 paths = paths.split(sep)
101 if os.path.normcase(path) not in list(map(os.path.normcase, paths)):
102 paths = [ path ] + paths
104 env_dict[key] = paths
106 env_dict[key] = sep.join(paths)
110 def addPharLapPaths(env):
111 """This function adds the path to the Phar Lap binaries, includes,
112 and libraries, if they are not already there."""
113 ph_path = getPharLapPath()
116 env_dict = env['ENV']
119 env['ENV'] = env_dict
120 addPathIfNotExists(env_dict, 'PATH',
121 os.path.join(ph_path, 'bin'))
122 addPathIfNotExists(env_dict, 'INCLUDE',
123 os.path.join(ph_path, 'include'))
124 addPathIfNotExists(env_dict, 'LIB',
125 os.path.join(ph_path, 'lib'))
126 addPathIfNotExists(env_dict, 'LIB',
127 os.path.join(ph_path, os.path.normpath('lib/vclib')))
129 env['PHARLAP_PATH'] = getPharLapPath()
130 env['PHARLAP_VERSION'] = str(getPharLapVersion())
135 # indent-tabs-mode:nil
137 # vim: set expandtab tabstop=4 shiftwidth=4: