annotate site_scons/site_tools/cpython/__init__.py @ 16:927f2cf75357

Changed build system from SCons to WAF. * WAF is an old fork of SCons that is now for all intents and purposes a different build system. * Unlike SCons which requires a system install of the scons library to work, the entire WAF library is self-contained in a single 'waf' Python script provided with PARPG. * Build instructions are a little different from SCons - execute the local 'waf' script with the arguments 'configure install'. * To make a local install for testing, add the '--destdir=<directory>' option to make all files install under <directory> as a fake root (e.g. '--destdir=dev_install' would make WAF install all files under the 'dev_install' directory in the PARPG source). * Added a waf_paths.py WAF tool to set GNU-compatible installation path variables (i.e. PREFIX, EXEC_PREFIX, LIBDIR, etc.). These variables should be initialized to sane defaults on Windows, where GNU standards don't usually apply.
author M. George Hansen <technopolitica@gmail.com>
date Thu, 09 Jun 2011 21:35:19 -1000
parents 4706e0194af3
children
rev   line source
11
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
1 """SCons.Tool.cpython
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
2
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
3 Tool-specific initialization for Python binary builder.
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
4
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
5 There normally shouldn't be any need to import this module directly.
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
6 It will usually be imported through the generic SCons.Tool.Tool()
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
7 selection method.
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
8
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
9 """
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
10
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
11 #
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
12 # Copyright (c) 2001-7,2010 The SCons Foundation
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
13 #
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
14 # Permission is hereby granted, free of charge, to any person obtaining
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
15 # a copy of this software and associated documentation files (the
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
16 # "Software"), to deal in the Software without restriction, including
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
17 # without limitation the rights to use, copy, modify, merge, publish,
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
18 # distribute, sublicense, and/or sell copies of the Software, and to
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
19 # permit persons to whom the Software is furnished to do so, subject to
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
20 # the following conditions:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
21 #
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
22 # The above copyright notice and this permission notice shall be included
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
23 # in all copies or substantial portions of the Software.
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
24 #
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
26 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
27 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
28 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
29 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
30 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
31 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
32 #
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
33
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
34 __revision__ = "src/engine/SCons/Tool/python.py 3263 2008/07/31 13:50:51 MatiGruca"
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
35
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
36 import os
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
37 try:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
38 import py_compile
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
39 except ImportError:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
40 raise SCons.Errors.InternalError, "Couldn't import py_compile module"
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
41 try:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
42 import compileall
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
43 except ImportError:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
44 raise SCons.Errors.InternalError, "Couldn't import compileall module"
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
45 import glob
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
46
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
47 import SCons.Action
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
48 import SCons.Builder
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
49 import SCons.Errors
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
50 import SCons.Node
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
51 from SCons.Tool.install import installFunc, add_targets_to_INSTALLED_FILES
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
52 from SCons.Tool.install import copyFunc
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
53
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
54 ##########################################################################
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
55 # Create Python builder
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
56 def createPythonBuilder(env):
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
57 """
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
58 This is a utility function that creates the InstallPython
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
59 Builder in an Environment if it's not there already.
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
60
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
61 If it's there already, we return the existing one.
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
62
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
63 This builder is based on Install/InstallAs methods. It makes use
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
64 of those builder's functions: installFunc(), and
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
65 add_targets_to_INSTALLED_FILES()).
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
66 """
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
67
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
68 try:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
69 InstallPythonBuilder = env['BUILDERS']['InstallPython']
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
70 except KeyError:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
71 installpython_action = SCons.Action.Action(installFunc, '$PYTHON_PYCOMSTR')
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
72 InstallPythonBuilder = SCons.Builder.Builder(
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
73 action=installpython_action,
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
74 src_suffix='$PYTHON_SUFFIX',
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
75 target_factory=env.fs.Entry,
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
76 source_factory=env.fs.Entry,
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
77 multi=1,
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
78 emitter=[add_targets_to_INSTALLED_FILES],
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
79 name='InstallPythonBuilder'
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
80 )
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
81
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
82 return InstallPythonBuilder
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
83
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
84 def InstallPython(env, target=None, source=None):
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
85 """
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
86 InstallPython creates .pyc or .pyo files for .py source files
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
87 and adds them to the list of targets along with the source files.
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
88 They are later copied to the destination (target) directory.
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
89
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
90 InstallPython takes a target (destination) directory as its first
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
91 argument and a list of source files/directories as a second argument.
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
92
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
93 InstallPython returns the list of target files to copy to the
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
94 target directory.
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
95 """
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
96 try:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
97 target_nodes = env.arg2nodes(target, env.fs.Dir)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
98 except TypeError:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
99 raise SCons.Errors.UserError, "Target `%s' of Install() is a file, but should be a directory. Perhaps you have the InstallPython() arguments backwards?" % str(dir)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
100
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
101 source_nodes = env.arg2nodes(source, env.fs.Entry)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
102 targets = []
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
103
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
104 # import `compileall` module only if there is a dir in sources list
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
105 dir_in_sources = any(entry.isdir() for entry in sources)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
106
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
107 compile_py = env['PYTHON_COMPILE']
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
108 optimize = env['PYTHON_OPTIMIZE']
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
109 if optimize:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
110 PYTHON_TARGETSUFFIX = 'o'
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
111 else:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
112 PYTHON_TARGETSUFFIX = 'c'
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
113
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
114 for target_node in target_nodes:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
115 for source_node in source_nodes:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
116 # add *.py and *.pyc files from a directory to tgt list
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
117 if source_node.isdir() and compile_py:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
118 compileall.compile_dir(str(source_node), maxlevels=0, quiet=True)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
119 glob_path = os.path.join(source_node.path, '*.py')
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
120 py_and_pycs = glob.glob(glob_path) + glob.glob(glob_path + 'c')
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
121 for file_name in py_and_pycs:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
122 target = env.Entry('.'+os.sep+filename, dnode)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
123 targets.extend(apply(PythonInstallBuilder, (env, target, filename), kw))
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
124 # add *.py and *.pyo files from a directory to tgt list
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
125 elif isinstance(src, SCons.Node.FS.Dir):
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
126 to_compile = []
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
127 py_files = glob.glob(src.path + os.sep + '*.py')
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
128 for py_file in py_files:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
129 to_compile.append(py_file)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
130 target_path = '.' + os.sep + py_file
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
131
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
132 # add '.py' file to tgt list
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
133 py_src = env.fs.Entry(py_file)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
134 py_tgt = env.fs.Entry(target_path, dnode)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
135 tgt.extend(apply(PIB, (env, py_tgt, py_src), kw))
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
136
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
137 # add '.pyo' file to tgt list
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
138 pyo_src = env.fs.Entry(py_file + CPYTHON_TARGETSUFFIX)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
139 pyo_tgt = env.fs.Entry(target_path + CPYTHON_TARGETSUFFIX, dnode)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
140 tgt.extend(apply(PIB, (env, pyo_tgt, pyo_src), kw))
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
141 act = SCons.Action.CommandAction('@$CPYTHON_PYCOM %s' % (' '.join(to_compile)))
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
142 act([], [], env)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
143 # add single '.py' and '.pyc' or '.pyo' file to tgt list
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
144 else:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
145 # add '.py' file to tgt list
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
146 target = env.fs.Entry('.'+os.sep+src.path, dnode)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
147 tgt.extend(apply(PIB, (env, target, src), kw))
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
148
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
149 # .pyc or .pyo source and target files
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
150 pyco_src = env.fs.Entry(src.path + CPYTHON_TARGETSUFFIX)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
151 pyco_tgt = env.fs.Entry(target.path + CPYTHON_TARGETSUFFIX)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
152
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
153 if compile_pyc:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
154 py_compile.compile(src.path)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
155 else:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
156 act = SCons.Action.CommandAction('@$CPYTHON_PYCOM %s' % (src.path))
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
157 act([], [], env)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
158
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
159 # add '.pyc' or '.pyo' file to tgt list
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
160 tgt.extend(apply(PIB, (env, pyco_tgt, pyco_src), kw))
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
161
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
162 return tgt
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
163
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
164 def generate(env):
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
165 try:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
166 env['INSTALL']
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
167 except KeyError:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
168 env['INSTALL'] = copyFunc
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
169
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
170 global InstallPythonBuilder
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
171 InstallPythonBuilder = createPythonBuilder(env)
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
172
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
173 env['PYTHON_OPTIMIZE'] = False # generate '.pyc' files by default
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
174 env['PYTHON_OPTIMIZE_FLAGS'] = '-O'
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
175 env['PYTHON_COMPILE_CMD'] = "-m py_compile $SOURCES"
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
176 env['PYTHON_PYCOM'] = '$PYTHON ${PYTHON_OPTIMIZE_FLAGS if ' \
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
177 'PYTHON_OPTIMIZE} $CPYTHON_COMPILE_CMD'
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
178 env['PYTHON_PYCOMSTR'] = 'Install file: "$SOURCE" as "$TARGET"'
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
179 env['PYTHON_SUFFIX'] = '.py' # extension for Python source files
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
180
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
181 try:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
182 env.Append(BUILDERS={'InstallPython': InstallPythonBuilder})
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
183 except AttributeError:
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
184 # Looks like we use a pre-0.98 version of SCons...
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
185 from SCons.Script.SConscript import SConsEnvironment
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
186 SConsEnvironment.InstallPython = InstallPythonBuilder
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
187
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
188 def exists(env):
4706e0194af3 Various improvements to the build process including support for self-contained builds.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
189 return 1