SConscript revision 4042
11046SN/A# -*- mode:python -*- 21046SN/A 31762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 41046SN/A# All rights reserved. 51046SN/A# 61046SN/A# Redistribution and use in source and binary forms, with or without 71046SN/A# modification, are permitted provided that the following conditions are 81046SN/A# met: redistributions of source code must retain the above copyright 91046SN/A# notice, this list of conditions and the following disclaimer; 101046SN/A# redistributions in binary form must reproduce the above copyright 111046SN/A# notice, this list of conditions and the following disclaimer in the 121046SN/A# documentation and/or other materials provided with the distribution; 131046SN/A# neither the name of the copyright holders nor the names of its 141046SN/A# contributors may be used to endorse or promote products derived from 151046SN/A# this software without specific prior written permission. 161046SN/A# 171046SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 181046SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 191046SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 201046SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 211046SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 221046SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 231046SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 241046SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 251046SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 261046SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 271046SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 302665Ssaidi@eecs.umich.edu# Nathan Binkert 311046SN/A 324202Sbinkertn@umich.eduimport os, os.path, re, sys 331530SN/Afrom zipfile import PyZipFile 345522Snate@binkert.org 354382Sbinkertn@umich.edu# handy function for path joins 364382Sbinkertn@umich.edudef join(*args): 375471Snate@binkert.org return os.path.normpath(os.path.join(*args)) 385801Snate@binkert.org 395801Snate@binkert.orgImport('env') 404382Sbinkertn@umich.edu 414382Sbinkertn@umich.edu# This SConscript is in charge of collecting .py files and generating 425470Snate@binkert.org# a zip archive that is appended to the m5 binary. 434382Sbinkertn@umich.edu 444382Sbinkertn@umich.edu# List of files & directories to include in the zip file. To include 454762Snate@binkert.org# a package, list only the root directory of the package, not any 464382Sbinkertn@umich.edu# internal .py files (else they will get the path stripped off when 475799Snate@binkert.org# they are imported into the zip file). 487674Snate@binkert.orgpyzip_files = [] 498295Snate@binkert.org 505467Snate@binkert.org# List of additional files on which the zip archive depends, but which 515467Snate@binkert.org# are not included in pyzip_files... i.e. individual .py files within 526502Snate@binkert.org# a package. 536654Snate@binkert.orgpyzip_dep_files = [] 548999Suri.wiener@arm.com 556501Snate@binkert.org# Add the specified package to the zip archive. Adds the directory to 565467Snate@binkert.org# pyzip_files and all included .py files to pyzip_dep_files. 575467Snate@binkert.orgdef addPkg(pkgdir): 586500Snate@binkert.org pyzip_files.append(pkgdir) 596654Snate@binkert.org origdir = os.getcwd() 607503Snate@binkert.org srcdir = join(Dir('.').srcnode().abspath, pkgdir) 617816Ssteve.reinhardt@amd.com os.chdir(srcdir) 6211988Sandreas.sandberg@arm.com for path, dirs, files in os.walk('.'): 6312469Sglenn.bergmans@arm.com for i,dir in enumerate(dirs): 642667Sstever@eecs.umich.edu if dir == 'SCCS': 654382Sbinkertn@umich.edu del dirs[i] 667677Snate@binkert.org break 6712468Sglenn.bergmans@arm.com 6812468Sglenn.bergmans@arm.com for f in files: 6912468Sglenn.bergmans@arm.com if f.endswith('.py'): 7011988Sandreas.sandberg@arm.com pyzip_dep_files.append(join(pkgdir, path, f)) 7112302Sgabeblack@google.com 7212302Sgabeblack@google.com os.chdir(origdir) 7312302Sgabeblack@google.com 7412302Sgabeblack@google.com# Generate Python file that contains a dict specifying the current 7512302Sgabeblack@google.com# 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('trace') 112 113# Action function to build the zip archive. Uses the PyZipFile module 114# included in the standard Python library. 115def buildPyZip(target, source, env): 116 pzf = PyZipFile(str(target[0]), 'w') 117 for s in source: 118 pzf.writepy(str(s)) 119 120# Add the zip file target to the environment. 121env.Command('m5py.zip', pyzip_files, buildPyZip) 122env.Depends('m5py.zip', pyzip_dep_files) 123