SConscript revision 2763
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 321530SN/Aimport os, os.path, re, sys 332655Sstever@eecs.umich.edufrom zipfile import PyZipFile 342655Sstever@eecs.umich.edu 352655Sstever@eecs.umich.edu# handy function for path joins 362655Sstever@eecs.umich.edudef join(*args): 372655Sstever@eecs.umich.edu return os.path.normpath(os.path.join(*args)) 381530SN/A 391530SN/AImport('env') 401530SN/A 412667Sstever@eecs.umich.edu# This SConscript is in charge of collecting .py files and generating 422667Sstever@eecs.umich.edu# a zip archive that is appended to the m5 binary. 431046SN/A 442655Sstever@eecs.umich.edu# List of files & directories to include in the zip file. To include 452655Sstever@eecs.umich.edu# a package, list only the root directory of the package, not any 462655Sstever@eecs.umich.edu# internal .py files (else they will get the path stripped off when 472655Sstever@eecs.umich.edu# they are imported into the zip file). 482655Sstever@eecs.umich.edupyzip_files = [] 491046SN/A 502655Sstever@eecs.umich.edu# List of additional files on which the zip archive depends, but which 512655Sstever@eecs.umich.edu# are not included in pyzip_files... i.e. individual .py files within 522655Sstever@eecs.umich.edu# a package. 532655Sstever@eecs.umich.edupyzip_dep_files = [] 541046SN/A 552655Sstever@eecs.umich.edu# Add the specified package to the zip archive. Adds the directory to 562655Sstever@eecs.umich.edu# pyzip_files and all included .py files to pyzip_dep_files. 572655Sstever@eecs.umich.edudef addPkg(pkgdir): 582667Sstever@eecs.umich.edu pyzip_files.append(pkgdir) 592655Sstever@eecs.umich.edu origdir = os.getcwd() 602655Sstever@eecs.umich.edu srcdir = join(Dir('.').srcnode().abspath, pkgdir) 612655Sstever@eecs.umich.edu os.chdir(srcdir) 622655Sstever@eecs.umich.edu for path, dirs, files in os.walk('.'): 632655Sstever@eecs.umich.edu for i,dir in enumerate(dirs): 642655Sstever@eecs.umich.edu if dir == 'SCCS': 652655Sstever@eecs.umich.edu del dirs[i] 662655Sstever@eecs.umich.edu break 671046SN/A 682655Sstever@eecs.umich.edu for f in files: 692655Sstever@eecs.umich.edu if f.endswith('.py'): 702667Sstever@eecs.umich.edu pyzip_dep_files.append(join(pkgdir, path, f)) 711046SN/A 722655Sstever@eecs.umich.edu os.chdir(origdir) 731046SN/A 742655Sstever@eecs.umich.edu# Generate Python file that contains a dict specifying the current 752655Sstever@eecs.umich.edu# build_env flags. 761439SN/Adef MakeDefinesPyFile(target, source, env): 771530SN/A f = file(str(target[0]), 'w') 782667Sstever@eecs.umich.edu print >>f, "m5_build_env = ", 791858SN/A print >>f, source[0] 801530SN/A f.close() 811439SN/A 821858SN/AoptionDict = dict([(opt, env[opt]) for opt in env.ExportOptions]) 832667Sstever@eecs.umich.eduenv.Command('m5/defines.py', Value(optionDict), MakeDefinesPyFile) 841858SN/A 852655Sstever@eecs.umich.edu# Now specify the packages & files for the zip archive. 862655Sstever@eecs.umich.eduaddPkg('m5') 872667Sstever@eecs.umich.edupyzip_files.append('m5/defines.py') 882655Sstever@eecs.umich.edupyzip_files.append(join(env['ROOT'], 'util/pbs/jobfile.py')) 892655Sstever@eecs.umich.edu 902763Sstever@eecs.umich.eduenv.Command(['swig/cc_main_wrap.cc', 'm5/cc_main.py'], 912763Sstever@eecs.umich.edu 'swig/cc_main.i', 922667Sstever@eecs.umich.edu '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} ' 932667Sstever@eecs.umich.edu '-o ${TARGETS[0]} $SOURCES') 942667Sstever@eecs.umich.edu 952763Sstever@eecs.umich.edupyzip_dep_files.append('m5/cc_main.py') 962667Sstever@eecs.umich.edu 972655Sstever@eecs.umich.edu# Action function to build the zip archive. Uses the PyZipFile module 982655Sstever@eecs.umich.edu# included in the standard Python library. 992655Sstever@eecs.umich.edudef buildPyZip(target, source, env): 1002655Sstever@eecs.umich.edu pzf = PyZipFile(str(target[0]), 'w') 1012655Sstever@eecs.umich.edu for s in source: 1022655Sstever@eecs.umich.edu pzf.writepy(str(s)) 1032655Sstever@eecs.umich.edu 1042655Sstever@eecs.umich.edu# Add the zip file target to the environment. 1052655Sstever@eecs.umich.eduenv.Command('m5py.zip', pyzip_files, buildPyZip) 1062655Sstever@eecs.umich.eduenv.Depends('m5py.zip', pyzip_dep_files) 107