3 # Copyright (c) 2004-2005 The Regents of The University of Michigan
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met: redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer;
10 # redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution;
13 # neither the name of the copyright holders nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 import os, os.path, re, sys
30 from zipfile import PyZipFile
32 # handy function for path joins
34 return os.path.normpath(os.path.join(*args))
38 # This SConscript is in charge of collecting .py files and generating a zip archive that is appended to the m5 binary.
40 # Copy .py source files here (relative to src/python in the build
44 # List of files & directories to include in the zip file. To include
45 # a package, list only the root directory of the package, not any
46 # internal .py files (else they will get the path stripped off when
47 # they are imported into the zip file).
50 # List of additional files on which the zip archive depends, but which
51 # are not included in pyzip_files... i.e. individual .py files within
55 # Add the specified package to the zip archive. Adds the directory to
56 # pyzip_files and all included .py files to pyzip_dep_files.
58 pyzip_files.append(join(pyzip_root, pkgdir))
60 srcdir = join(Dir('.').srcnode().abspath, pkgdir)
62 for path, dirs, files in os.walk('.'):
63 for i,dir in enumerate(dirs):
70 source = join(pkgdir, path, f)
71 target = join(pyzip_root, source)
72 pyzip_dep_files.append(target)
73 env.CopyFile(target, source)
77 # Generate Python file that contains a dict specifying the current
79 def MakeDefinesPyFile(target, source, env):
80 f = file(str(target[0]), 'w')
81 print >>f, "import __main__"
82 print >>f, "__main__.m5_build_env = ",
86 optionDict = dict([(opt, env[opt]) for opt in env.ExportOptions])
87 env.Command('defines.py', Value(optionDict), MakeDefinesPyFile)
89 # Now specify the packages & files for the zip archive.
91 pyzip_files.append('defines.py')
92 pyzip_files.append(join(env['ROOT'], 'util/pbs/jobfile.py'))
94 # Action function to build the zip archive. Uses the PyZipFile module
95 # included in the standard Python library.
96 def buildPyZip(target, source, env):
97 pzf = PyZipFile(str(target[0]), 'w')
101 # Add the zip file target to the environment.
102 env.Command('m5py.zip', pyzip_files, buildPyZip)
103 env.Depends('m5py.zip', pyzip_dep_files)