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 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 3842 2008/12/20 22:59:52 scons"
42
"""Reads the registry to find the installed path of the Phar Lap ETS
45
Raises UserError if no installed version of Phar Lap can
48
if not SCons.Util.can_read_reg:
49
raise SCons.Errors.InternalError, "No Windows registry module was found"
51
k=SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE,
52
'SOFTWARE\\Pharlap\\ETS')
53
val, type = SCons.Util.RegQueryValueEx(k, 'BaseDir')
55
# The following is a hack...there is (not surprisingly)
56
# an odd issue in the Phar Lap plug in that inserts
57
# a bunch of junk data after the phar lap path in the
58
# registry. We must trim it.
63
return os.path.normpath(val)
64
except SCons.Util.RegError:
65
raise SCons.Errors.UserError, "Cannot find Phar Lap ETS path in the registry. Is it installed properly?"
67
REGEX_ETS_VER = re.compile(r'#define\s+ETS_VER\s+([0-9]+)')
69
def getPharLapVersion():
70
"""Returns the version of the installed ETS Tool Suite as a
71
decimal number. This version comes from the ETS_VER #define in
72
the embkern.h header. For example, '#define ETS_VER 1010' (which
73
is what Phar Lap 10.1 defines) would cause this method to return
74
1010. Phar Lap 9.1 does not have such a #define, but this method
75
will return 910 as a default.
77
Raises UserError if no installed version of Phar Lap can
80
include_path = os.path.join(getPharLapPath(), os.path.normpath("include/embkern.h"))
81
if not os.path.exists(include_path):
82
raise SCons.Errors.UserError, "Cannot find embkern.h in ETS include directory.\nIs Phar Lap ETS installed properly?"
83
mo = REGEX_ETS_VER.search(open(include_path, 'r').read())
85
return int(mo.group(1))
86
# Default return for Phar Lap 9.1
89
def addPathIfNotExists(env_dict, key, path, sep=os.pathsep):
90
"""This function will take 'key' out of the dictionary
91
'env_dict', then add the path 'path' to that key if it is not
92
already there. This treats the value of env_dict[key] as if it
93
has a similar format to the PATH variable...a list of paths
94
separated by tokens. The 'path' will get added to the list if it
95
is not already there."""
99
if not SCons.Util.is_List(env_dict[key]):
100
paths = string.split(paths, sep)
102
if not os.path.normcase(path) in map(os.path.normcase, paths):
103
paths = [ path ] + paths
105
env_dict[key] = paths
107
env_dict[key] = string.join(paths, sep)
111
def addPharLapPaths(env):
112
"""This function adds the path to the Phar Lap binaries, includes,
113
and libraries, if they are not already there."""
114
ph_path = getPharLapPath()
117
env_dict = env['ENV']
120
env['ENV'] = env_dict
121
addPathIfNotExists(env_dict, 'PATH',
122
os.path.join(ph_path, 'bin'))
123
addPathIfNotExists(env_dict, 'INCLUDE',
124
os.path.join(ph_path, 'include'))
125
addPathIfNotExists(env_dict, 'LIB',
126
os.path.join(ph_path, 'lib'))
127
addPathIfNotExists(env_dict, 'LIB',
128
os.path.join(ph_path, os.path.normpath('lib/vclib')))
130
env['PHARLAP_PATH'] = getPharLapPath()
131
env['PHARLAP_VERSION'] = str(getPharLapVersion())