Toplevel directory cleanup
[senf.git] / tools / scons-1.2.0 / engine / SCons / Tool / Perforce.py
1 """SCons.Tool.Perforce.py
2
3 Tool-specific initialization for Perforce Source Code Management system.
4
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()
7 selection method.
8
9 """
10
11 #
12 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
13 #
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:
21 #
22 # The above copyright notice and this permission notice shall be included
23 # in all copies or substantial portions of the Software.
24 #
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.
32 #
33
34 __revision__ = "src/engine/SCons/Tool/Perforce.py 3842 2008/12/20 22:59:52 scons"
35
36 import os
37
38 import SCons.Action
39 import SCons.Builder
40 import SCons.Node.FS
41 import SCons.Util
42
43 # This function should maybe be moved to SCons.Util?
44 from SCons.Tool.PharLapCommon import addPathIfNotExists
45
46
47
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' ]
51
52 PerforceAction = SCons.Action.Action('$P4COM', '$P4COMSTR')
53
54 def generate(env):
55     """Add a Builder factory function and construction variables for
56     Perforce to an Environment."""
57
58     def PerforceFactory(env=env):
59         """ """
60         return SCons.Builder.Builder(action = PerforceAction, env = env)
61
62     #setattr(env, 'Perforce', PerforceFactory)
63     env.Perforce = PerforceFactory
64
65     env['P4']      = 'p4'
66     env['P4FLAGS'] = SCons.Util.CLVar('')
67     env['P4COM']   = '$P4 $P4FLAGS sync $TARGET'
68     try:
69         environ = env['ENV']
70     except KeyError:
71         environ = {}
72         env['ENV'] = environ
73
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()
79
80     for var in _import_env:
81         v = os.environ.get(var)
82         if v:
83             environ[var] = v
84
85     if SCons.Util.can_read_reg:
86         # If we can read the registry, add the path to Perforce to our environment.
87         try:
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
94             # PATH.
95             pass
96
97 def exists(env):
98     return env.Detect('p4')