~mwinter4/maus/ckov_0_9_3

« back to all changes in this revision

Viewing changes to third_party/scons-2.0.1/lib/scons-2.0.1/SCons/Tool/Perforce.py

  • Committer: tunnell
  • Date: 2010-09-30 13:56:05 UTC
  • Revision ID: tunnell@itchy-20100930135605-wxbkfgy75p0sndk3
add third party

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
 
12
#
 
13
# Permission is hereby granted, free of charge, to any person obtaining
 
14
# a copy of this software and associated documentation files (the
 
15
# "Software"), to deal in the Software without restriction, including
 
16
# without limitation the rights to use, copy, modify, merge, publish,
 
17
# distribute, sublicense, and/or sell copies of the Software, and to
 
18
# permit persons to whom the Software is furnished to do so, subject to
 
19
# the following conditions:
 
20
#
 
21
# The above copyright notice and this permission notice shall be included
 
22
# in all copies or substantial portions of the Software.
 
23
#
 
24
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
 
25
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 
26
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
27
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
28
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
29
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
30
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
31
 
 
32
__revision__ = "src/engine/SCons/Tool/Perforce.py 5134 2010/08/16 23:02:40 bdeegan"
 
33
 
 
34
import os
 
35
 
 
36
import SCons.Action
 
37
import SCons.Builder
 
38
import SCons.Node.FS
 
39
import SCons.Util
 
40
 
 
41
# This function should maybe be moved to SCons.Util?
 
42
from SCons.Tool.PharLapCommon import addPathIfNotExists
 
43
 
 
44
 
 
45
# Variables that we want to import from the base OS environment.
 
46
_import_env = [ 'P4PORT', 'P4CLIENT', 'P4USER', 'USER', 'USERNAME', 'P4PASSWD',
 
47
                'P4CHARSET', 'P4LANGUAGE', 'SystemRoot' ]
 
48
 
 
49
PerforceAction = SCons.Action.Action('$P4COM', '$P4COMSTR')
 
50
 
 
51
def generate(env):
 
52
    """Add a Builder factory function and construction variables for
 
53
    Perforce to an Environment."""
 
54
 
 
55
    def PerforceFactory(env=env):
 
56
        """ """
 
57
        import SCons.Warnings as W
 
58
        W.warn(W.DeprecatedSourceCodeWarning, """The Perforce() factory is deprecated and there is no replacement.""")
 
59
        return SCons.Builder.Builder(action = PerforceAction, env = env)
 
60
 
 
61
    #setattr(env, 'Perforce', PerforceFactory)
 
62
    env.Perforce = PerforceFactory
 
63
 
 
64
    env['P4']      = 'p4'
 
65
    env['P4FLAGS'] = SCons.Util.CLVar('')
 
66
    env['P4COM']   = '$P4 $P4FLAGS sync $TARGET'
 
67
    try:
 
68
        environ = env['ENV']
 
69
    except KeyError:
 
70
        environ = {}
 
71
        env['ENV'] = environ
 
72
 
 
73
    # Perforce seems to use the PWD environment variable rather than
 
74
    # calling getcwd() for itself, which is odd.  If no PWD variable
 
75
    # is present, p4 WILL call getcwd, but this seems to cause problems
 
76
    # with good ol' Windows's tilde-mangling for long file names.
 
77
    environ['PWD'] = env.Dir('#').get_abspath()
 
78
 
 
79
    for var in _import_env:
 
80
        v = os.environ.get(var)
 
81
        if v:
 
82
            environ[var] = v
 
83
 
 
84
    if SCons.Util.can_read_reg:
 
85
        # If we can read the registry, add the path to Perforce to our environment.
 
86
        try:
 
87
            k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
 
88
                                      'Software\\Perforce\\environment')
 
89
            val, tok = SCons.Util.RegQueryValueEx(k, 'P4INSTROOT')
 
90
            addPathIfNotExists(environ, 'PATH', val)
 
91
        except SCons.Util.RegError:
 
92
            # Can't detect where Perforce is, hope the user has it set in the
 
93
            # PATH.
 
94
            pass
 
95
 
 
96
def exists(env):
 
97
    return env.Detect('p4')
 
98
 
 
99
# Local Variables:
 
100
# tab-width:4
 
101
# indent-tabs-mode:nil
 
102
# End:
 
103
# vim: set expandtab tabstop=4 shiftwidth=4: