SConscript revision 4045
111265Sandreas.sandberg@arm.com# -*- mode:python -*- 211265Sandreas.sandberg@arm.com 311265Sandreas.sandberg@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 411265Sandreas.sandberg@arm.com# All rights reserved. 511265Sandreas.sandberg@arm.com# 611265Sandreas.sandberg@arm.com# Redistribution and use in source and binary forms, with or without 711265Sandreas.sandberg@arm.com# modification, are permitted provided that the following conditions are 811265Sandreas.sandberg@arm.com# met: redistributions of source code must retain the above copyright 911265Sandreas.sandberg@arm.com# notice, this list of conditions and the following disclaimer; 1011265Sandreas.sandberg@arm.com# redistributions in binary form must reproduce the above copyright 1111265Sandreas.sandberg@arm.com# notice, this list of conditions and the following disclaimer in the 1211265Sandreas.sandberg@arm.com# documentation and/or other materials provided with the distribution; 1311265Sandreas.sandberg@arm.com# neither the name of the copyright holders nor the names of its 1411265Sandreas.sandberg@arm.com# contributors may be used to endorse or promote products derived from 1511265Sandreas.sandberg@arm.com# this software without specific prior written permission. 1611265Sandreas.sandberg@arm.com# 1711265Sandreas.sandberg@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1811265Sandreas.sandberg@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1911265Sandreas.sandberg@arm.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2011265Sandreas.sandberg@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2111265Sandreas.sandberg@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2211265Sandreas.sandberg@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2311265Sandreas.sandberg@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2411265Sandreas.sandberg@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2511265Sandreas.sandberg@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2611265Sandreas.sandberg@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2711265Sandreas.sandberg@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2811265Sandreas.sandberg@arm.com# 2911265Sandreas.sandberg@arm.com# Authors: Steve Reinhardt 3011265Sandreas.sandberg@arm.com# Nathan Binkert 3111265Sandreas.sandberg@arm.com 3211265Sandreas.sandberg@arm.comimport os, os.path, re, sys 3311265Sandreas.sandberg@arm.comfrom zipfile import PyZipFile 3411265Sandreas.sandberg@arm.com 3511265Sandreas.sandberg@arm.com# handy function for path joins 3611265Sandreas.sandberg@arm.comdef join(*args): 3711265Sandreas.sandberg@arm.com return os.path.normpath(os.path.join(*args)) 3811265Sandreas.sandberg@arm.com 3911265Sandreas.sandberg@arm.comImport('env') 4011265Sandreas.sandberg@arm.com 4111265Sandreas.sandberg@arm.com# This SConscript is in charge of collecting .py files and generating 4211265Sandreas.sandberg@arm.com# a zip archive that is appended to the m5 binary. 4311265Sandreas.sandberg@arm.com 4411265Sandreas.sandberg@arm.com# List of files & directories to include in the zip file. To include 4511265Sandreas.sandberg@arm.com# a package, list only the root directory of the package, not any 4611265Sandreas.sandberg@arm.com# internal .py files (else they will get the path stripped off when 47# they are imported into the zip file). 48pyzip_files = [] 49 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 52# a package. 53pyzip_dep_files = [] 54 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. 57def addPkg(pkgdir): 58 pyzip_files.append(pkgdir) 59 origdir = os.getcwd() 60 srcdir = join(Dir('.').srcnode().abspath, pkgdir) 61 os.chdir(srcdir) 62 for path, dirs, files in os.walk('.'): 63 for i,dir in enumerate(dirs): 64 if dir == 'SCCS': 65 del dirs[i] 66 break 67 68 for f in files: 69 if f.endswith('.py'): 70 pyzip_dep_files.append(join(pkgdir, path, f)) 71 72 os.chdir(origdir) 73 74# Generate Python file that contains a dict specifying the current 75# build_env flags. 76def MakeDefinesPyFile(target, source, env): 77 f = file(str(target[0]), 'w') 78 print >>f, "m5_build_env = ", source[0] 79 f.close() 80 81optionDict = dict([(opt, env[opt]) for opt in env.ExportOptions]) 82env.Command('m5/defines.py', Value(optionDict), MakeDefinesPyFile) 83 84def MakeInfoPyFile(target, source, env): 85 f = file(str(target[0]), 'w') 86 for src in source: 87 data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 88 print >>f, "%s = %s" % (src, repr(data)) 89 f.close() 90 91env.Command('m5/info.py', 92 [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ], 93 MakeInfoPyFile) 94 95# Now specify the packages & files for the zip archive. 96addPkg('m5') 97pyzip_files.append('m5/defines.py') 98pyzip_files.append('m5/info.py') 99pyzip_files.append(join(env['ROOT'], 'util/pbs/jobfile.py')) 100 101def swig_it(basename): 102 env.Command(['swig/%s_wrap.cc' % basename, 'm5/internal/%s.py' % basename], 103 'swig/%s.i' % basename, 104 '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} ' 105 '-o ${TARGETS[0]} $SOURCES') 106 pyzip_dep_files.append('m5/internal/%s.py' % basename) 107 108swig_it('main') 109swig_it('debug') 110swig_it('event') 111swig_it('random') 112swig_it('trace') 113 114# Action function to build the zip archive. Uses the PyZipFile module 115# included in the standard Python library. 116def buildPyZip(target, source, env): 117 pzf = PyZipFile(str(target[0]), 'w') 118 for s in source: 119 pzf.writepy(str(s)) 120 121# Add the zip file target to the environment. 122env.Command('m5py.zip', pyzip_files, buildPyZip) 123env.Depends('m5py.zip', pyzip_dep_files) 124