SConscript revision 2665
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 412655Sstever@eecs.umich.edu# This SConscript is in charge of collecting .py files and generating a zip archive that is appended to the m5 binary. 421046SN/A 432655Sstever@eecs.umich.edu# Copy .py source files here (relative to src/python in the build 442655Sstever@eecs.umich.edu# directory). 452655Sstever@eecs.umich.edupyzip_root = 'zip' 461046SN/A 472655Sstever@eecs.umich.edu# List of files & directories to include in the zip file. To include 482655Sstever@eecs.umich.edu# a package, list only the root directory of the package, not any 492655Sstever@eecs.umich.edu# internal .py files (else they will get the path stripped off when 502655Sstever@eecs.umich.edu# they are imported into the zip file). 512655Sstever@eecs.umich.edupyzip_files = [] 521046SN/A 532655Sstever@eecs.umich.edu# List of additional files on which the zip archive depends, but which 542655Sstever@eecs.umich.edu# are not included in pyzip_files... i.e. individual .py files within 552655Sstever@eecs.umich.edu# a package. 562655Sstever@eecs.umich.edupyzip_dep_files = [] 571046SN/A 582655Sstever@eecs.umich.edu# Add the specified package to the zip archive. Adds the directory to 592655Sstever@eecs.umich.edu# pyzip_files and all included .py files to pyzip_dep_files. 602655Sstever@eecs.umich.edudef addPkg(pkgdir): 612655Sstever@eecs.umich.edu pyzip_files.append(join(pyzip_root, pkgdir)) 622655Sstever@eecs.umich.edu origdir = os.getcwd() 632655Sstever@eecs.umich.edu srcdir = join(Dir('.').srcnode().abspath, pkgdir) 642655Sstever@eecs.umich.edu os.chdir(srcdir) 652655Sstever@eecs.umich.edu for path, dirs, files in os.walk('.'): 662655Sstever@eecs.umich.edu for i,dir in enumerate(dirs): 672655Sstever@eecs.umich.edu if dir == 'SCCS': 682655Sstever@eecs.umich.edu del dirs[i] 692655Sstever@eecs.umich.edu break 701046SN/A 712655Sstever@eecs.umich.edu for f in files: 722655Sstever@eecs.umich.edu if f.endswith('.py'): 732655Sstever@eecs.umich.edu source = join(pkgdir, path, f) 742655Sstever@eecs.umich.edu target = join(pyzip_root, source) 752655Sstever@eecs.umich.edu pyzip_dep_files.append(target) 762655Sstever@eecs.umich.edu env.CopyFile(target, source) 771046SN/A 782655Sstever@eecs.umich.edu os.chdir(origdir) 791046SN/A 802655Sstever@eecs.umich.edu# Generate Python file that contains a dict specifying the current 812655Sstever@eecs.umich.edu# build_env flags. 821439SN/Adef MakeDefinesPyFile(target, source, env): 831530SN/A f = file(str(target[0]), 'w') 841530SN/A print >>f, "import __main__" 851530SN/A print >>f, "__main__.m5_build_env = ", 861858SN/A print >>f, source[0] 871530SN/A f.close() 881439SN/A 891858SN/AoptionDict = dict([(opt, env[opt]) for opt in env.ExportOptions]) 901858SN/Aenv.Command('defines.py', Value(optionDict), MakeDefinesPyFile) 911858SN/A 922655Sstever@eecs.umich.edu# Now specify the packages & files for the zip archive. 932655Sstever@eecs.umich.eduaddPkg('m5') 942655Sstever@eecs.umich.edupyzip_files.append('defines.py') 952655Sstever@eecs.umich.edupyzip_files.append(join(env['ROOT'], 'util/pbs/jobfile.py')) 962655Sstever@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