1 """SCons.Tool.Perforce.py
3 Tool-specific initialization for Perforce Source Code Management system.
5 There normally shouldn't be any need to import this module directly.
6 It will usually be imported through the generic SCons.Tool.Tool()
12 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
14 # Permission is hereby granted, free of charge, to any person obtaining
15 # a copy of this software and associated documentation files (the
16 # "Software"), to deal in the Software without restriction, including
17 # without limitation the rights to use, copy, modify, merge, publish,
18 # distribute, sublicense, and/or sell copies of the Software, and to
19 # permit persons to whom the Software is furnished to do so, subject to
20 # the following conditions:
22 # The above copyright notice and this permission notice shall be included
23 # in all copies or substantial portions of the Software.
25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
26 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
27 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 __revision__ = "src/engine/SCons/Tool/Perforce.py 3842 2008/12/20 22:59:52 scons"
43 # This function should maybe be moved to SCons.Util?
44 from SCons.Tool.PharLapCommon import addPathIfNotExists
48 # Variables that we want to import from the base OS environment.
49 _import_env = [ 'P4PORT', 'P4CLIENT', 'P4USER', 'USER', 'USERNAME', 'P4PASSWD',
50 'P4CHARSET', 'P4LANGUAGE', 'SYSTEMROOT' ]
52 PerforceAction = SCons.Action.Action('$P4COM', '$P4COMSTR')
55 """Add a Builder factory function and construction variables for
56 Perforce to an Environment."""
58 def PerforceFactory(env=env):
60 return SCons.Builder.Builder(action = PerforceAction, env = env)
62 #setattr(env, 'Perforce', PerforceFactory)
63 env.Perforce = PerforceFactory
66 env['P4FLAGS'] = SCons.Util.CLVar('')
67 env['P4COM'] = '$P4 $P4FLAGS sync $TARGET'
74 # Perforce seems to use the PWD environment variable rather than
75 # calling getcwd() for itself, which is odd. If no PWD variable
76 # is present, p4 WILL call getcwd, but this seems to cause problems
77 # with good ol' Windows's tilde-mangling for long file names.
78 environ['PWD'] = env.Dir('#').get_abspath()
80 for var in _import_env:
81 v = os.environ.get(var)
85 if SCons.Util.can_read_reg:
86 # If we can read the registry, add the path to Perforce to our environment.
88 k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
89 'Software\\Perforce\\environment')
90 val, tok = SCons.Util.RegQueryValueEx(k, 'P4INSTROOT')
91 addPathIfNotExists(environ, 'PATH', val)
92 except SCons.Util.RegError:
93 # Can't detect where Perforce is, hope the user has it set in the
98 return env.Detect('p4')