OLD | NEW |
(Empty) | |
| 1 """SCons.Tool.PharLapCommon |
| 2 |
| 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. |
| 6 |
| 7 """ |
| 8 |
| 9 # |
| 10 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The S
Cons Foundation |
| 11 # |
| 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: |
| 19 # |
| 20 # The above copyright notice and this permission notice shall be included |
| 21 # in all copies or substantial portions of the Software. |
| 22 # |
| 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. |
| 30 # |
| 31 |
| 32 __revision__ = "src/engine/SCons/Tool/PharLapCommon.py 5134 2010/08/16 23:02:40
bdeegan" |
| 33 |
| 34 import os |
| 35 import os.path |
| 36 import SCons.Errors |
| 37 import SCons.Util |
| 38 import re |
| 39 |
| 40 def getPharLapPath(): |
| 41 """Reads the registry to find the installed path of the Phar Lap ETS |
| 42 development kit. |
| 43 |
| 44 Raises UserError if no installed version of Phar Lap can |
| 45 be found.""" |
| 46 |
| 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') |
| 53 |
| 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] |
| 61 |
| 62 return os.path.normpath(val) |
| 63 except SCons.Util.RegError: |
| 64 raise SCons.Errors.UserError("Cannot find Phar Lap ETS path in the regis
try. Is it installed properly?") |
| 65 |
| 66 REGEX_ETS_VER = re.compile(r'#define\s+ETS_VER\s+([0-9]+)') |
| 67 |
| 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. |
| 75 |
| 76 Raises UserError if no installed version of Phar Lap can |
| 77 be found.""" |
| 78 |
| 79 include_path = os.path.join(getPharLapPath(), os.path.normpath("include/embk
ern.h")) |
| 80 if not os.path.exists(include_path): |
| 81 raise SCons.Errors.UserError("Cannot find embkern.h in ETS include direc
tory.\nIs Phar Lap ETS installed properly?") |
| 82 mo = REGEX_ETS_VER.search(open(include_path, 'r').read()) |
| 83 if mo: |
| 84 return int(mo.group(1)) |
| 85 # Default return for Phar Lap 9.1 |
| 86 return 910 |
| 87 |
| 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.""" |
| 95 try: |
| 96 is_list = 1 |
| 97 paths = env_dict[key] |
| 98 if not SCons.Util.is_List(env_dict[key]): |
| 99 paths = paths.split(sep) |
| 100 is_list = 0 |
| 101 if os.path.normcase(path) not in list(map(os.path.normcase, paths)): |
| 102 paths = [ path ] + paths |
| 103 if is_list: |
| 104 env_dict[key] = paths |
| 105 else: |
| 106 env_dict[key] = sep.join(paths) |
| 107 except KeyError: |
| 108 env_dict[key] = path |
| 109 |
| 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() |
| 114 |
| 115 try: |
| 116 env_dict = env['ENV'] |
| 117 except KeyError: |
| 118 env_dict = {} |
| 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'))) |
| 128 |
| 129 env['PHARLAP_PATH'] = getPharLapPath() |
| 130 env['PHARLAP_VERSION'] = str(getPharLapVersion()) |
| 131 |
| 132 |
| 133 # Local Variables: |
| 134 # tab-width:4 |
| 135 # indent-tabs-mode:nil |
| 136 # End: |
| 137 # vim: set expandtab tabstop=4 shiftwidth=4: |
OLD | NEW |