SConscript revision 3871:a6ef81a18107
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 4955SN/A# All rights reserved. 5955SN/A# 6955SN/A# Redistribution and use in source and binary forms, with or without 7955SN/A# modification, are permitted provided that the following conditions are 8955SN/A# met: redistributions of source code must retain the above copyright 9955SN/A# notice, this list of conditions and the following disclaimer; 10955SN/A# redistributions in binary form must reproduce the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer in the 12955SN/A# documentation and/or other materials provided with the distribution; 13955SN/A# neither the name of the copyright holders nor the names of its 14955SN/A# contributors may be used to endorse or promote products derived from 15955SN/A# this software without specific prior written permission. 16955SN/A# 17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 294762Snate@binkert.org# Authors: Steve Reinhardt 30955SN/A# Nathan Binkert 314762Snate@binkert.org 32955SN/Aimport os, os.path, re, sys 33955SN/Afrom zipfile import PyZipFile 344202Sbinkertn@umich.edu 354382Sbinkertn@umich.edu# handy function for path joins 365341Sstever@gmail.comdef join(*args): 374762Snate@binkert.org return os.path.normpath(os.path.join(*args)) 384762Snate@binkert.org 394762Snate@binkert.orgImport('env') 40955SN/A 414381Sbinkertn@umich.edu# This SConscript is in charge of collecting .py files and generating 424381Sbinkertn@umich.edu# a zip archive that is appended to the m5 binary. 43955SN/A 44955SN/A# List of files & directories to include in the zip file. To include 45955SN/A# a package, list only the root directory of the package, not any 464202Sbinkertn@umich.edu# internal .py files (else they will get the path stripped off when 47955SN/A# they are imported into the zip file). 484382Sbinkertn@umich.edupyzip_files = [] 494382Sbinkertn@umich.edu 504382Sbinkertn@umich.edu# List of additional files on which the zip archive depends, but which 514762Snate@binkert.org# are not included in pyzip_files... i.e. individual .py files within 524762Snate@binkert.org# a package. 534762Snate@binkert.orgpyzip_dep_files = [] 544762Snate@binkert.org 554762Snate@binkert.org# Add the specified package to the zip archive. Adds the directory to 564762Snate@binkert.org# pyzip_files and all included .py files to pyzip_dep_files. 574762Snate@binkert.orgdef addPkg(pkgdir): 584762Snate@binkert.org pyzip_files.append(pkgdir) 594762Snate@binkert.org origdir = os.getcwd() 604762Snate@binkert.org srcdir = join(Dir('.').srcnode().abspath, pkgdir) 614762Snate@binkert.org os.chdir(srcdir) 624762Snate@binkert.org for path, dirs, files in os.walk('.'): 634762Snate@binkert.org for i,dir in enumerate(dirs): 644762Snate@binkert.org if dir == 'SCCS': 654762Snate@binkert.org del dirs[i] 664762Snate@binkert.org break 674762Snate@binkert.org 684762Snate@binkert.org for f in files: 694762Snate@binkert.org if f.endswith('.py'): 704762Snate@binkert.org pyzip_dep_files.append(join(pkgdir, path, f)) 714762Snate@binkert.org 724762Snate@binkert.org os.chdir(origdir) 734762Snate@binkert.org 744762Snate@binkert.org# Generate Python file that contains a dict specifying the current 754762Snate@binkert.org# build_env flags. 764762Snate@binkert.orgdef MakeDefinesPyFile(target, source, env): 774762Snate@binkert.org f = file(str(target[0]), 'w') 784762Snate@binkert.org print >>f, "m5_build_env = ", source[0] 794762Snate@binkert.org f.close() 804762Snate@binkert.org 814762Snate@binkert.orgoptionDict = dict([(opt, env[opt]) for opt in env.ExportOptions]) 824762Snate@binkert.orgenv.Command('m5/defines.py', Value(optionDict), MakeDefinesPyFile) 834762Snate@binkert.org 844382Sbinkertn@umich.edudef MakeInfoPyFile(target, source, env): 854762Snate@binkert.org f = file(str(target[0]), 'w') 864382Sbinkertn@umich.edu for src in source: 874762Snate@binkert.org data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 884381Sbinkertn@umich.edu print >>f, "%s = %s" % (src, repr(data)) 894762Snate@binkert.org f.close() 904762Snate@binkert.org 914762Snate@binkert.orgenv.Command('m5/info.py', 924762Snate@binkert.org [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ], 934762Snate@binkert.org MakeInfoPyFile) 944762Snate@binkert.org 954762Snate@binkert.org# Now specify the packages & files for the zip archive. 964762Snate@binkert.orgaddPkg('m5') 974762Snate@binkert.orgpyzip_files.append('m5/defines.py') 984762Snate@binkert.orgpyzip_files.append('m5/info.py') 994762Snate@binkert.orgpyzip_files.append(join(env['ROOT'], 'util/pbs/jobfile.py')) 1004762Snate@binkert.org 1014762Snate@binkert.orgdef swig_it(basename): 1024762Snate@binkert.org env.Command(['swig/%s_wrap.cc' % basename, 'm5/internal/%s.py' % basename], 1034762Snate@binkert.org 'swig/%s.i' % basename, 1044762Snate@binkert.org '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} ' 1054762Snate@binkert.org '-o ${TARGETS[0]} $SOURCES') 1064762Snate@binkert.org pyzip_dep_files.append('m5/internal/%s.py' % basename) 1074762Snate@binkert.org 1084762Snate@binkert.orgswig_it('main') 1094762Snate@binkert.orgswig_it('debug') 1104762Snate@binkert.orgswig_it('event') 1114762Snate@binkert.org 1124762Snate@binkert.org# Action function to build the zip archive. Uses the PyZipFile module 1134762Snate@binkert.org# included in the standard Python library. 1144762Snate@binkert.orgdef buildPyZip(target, source, env): 1154762Snate@binkert.org pzf = PyZipFile(str(target[0]), 'w') 1164762Snate@binkert.org for s in source: 1174762Snate@binkert.org pzf.writepy(str(s)) 1184762Snate@binkert.org 1194762Snate@binkert.org# Add the zip file target to the environment. 1204762Snate@binkert.orgenv.Command('m5py.zip', pyzip_files, buildPyZip) 1214762Snate@binkert.orgenv.Depends('m5py.zip', pyzip_dep_files) 1224762Snate@binkert.org