SConscript revision 4053
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') 782889Sbinkertn@umich.edu print >>f, "m5_build_env = ", source[0] 791530SN/A f.close() 801439SN/A 811858SN/AoptionDict = dict([(opt, env[opt]) for opt in env.ExportOptions]) 822667Sstever@eecs.umich.eduenv.Command('m5/defines.py', Value(optionDict), MakeDefinesPyFile) 831858SN/A 842889Sbinkertn@umich.edudef MakeInfoPyFile(target, source, env): 852889Sbinkertn@umich.edu f = file(str(target[0]), 'w') 862889Sbinkertn@umich.edu for src in source: 872889Sbinkertn@umich.edu data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 882889Sbinkertn@umich.edu print >>f, "%s = %s" % (src, repr(data)) 892889Sbinkertn@umich.edu f.close() 902889Sbinkertn@umich.edu 912889Sbinkertn@umich.eduenv.Command('m5/info.py', 922889Sbinkertn@umich.edu [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ], 932889Sbinkertn@umich.edu MakeInfoPyFile) 942889Sbinkertn@umich.edu 952655Sstever@eecs.umich.edu# Now specify the packages & files for the zip archive. 962655Sstever@eecs.umich.eduaddPkg('m5') 972667Sstever@eecs.umich.edupyzip_files.append('m5/defines.py') 982889Sbinkertn@umich.edupyzip_files.append('m5/info.py') 992655Sstever@eecs.umich.edupyzip_files.append(join(env['ROOT'], 'util/pbs/jobfile.py')) 1004053Sbinkertn@umich.edupyzip_files.append(join(env['ROOT'], 'src/base/traceflags.py')) 1012655Sstever@eecs.umich.edu 1023869Sbinkertn@umich.edudef swig_it(basename): 1033869Sbinkertn@umich.edu env.Command(['swig/%s_wrap.cc' % basename, 'm5/internal/%s.py' % basename], 1043869Sbinkertn@umich.edu 'swig/%s.i' % basename, 1053869Sbinkertn@umich.edu '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} ' 1063869Sbinkertn@umich.edu '-o ${TARGETS[0]} $SOURCES') 1073869Sbinkertn@umich.edu pyzip_dep_files.append('m5/internal/%s.py' % basename) 1083645Sbinkertn@umich.edu 1093869Sbinkertn@umich.eduswig_it('main') 1103869Sbinkertn@umich.eduswig_it('debug') 1113871Sbinkertn@umich.eduswig_it('event') 1124045Sbinkertn@umich.eduswig_it('random') 1134042Sbinkertn@umich.eduswig_it('trace') 1142667Sstever@eecs.umich.edu 1152655Sstever@eecs.umich.edu# Action function to build the zip archive. Uses the PyZipFile module 1162655Sstever@eecs.umich.edu# included in the standard Python library. 1172655Sstever@eecs.umich.edudef buildPyZip(target, source, env): 1182655Sstever@eecs.umich.edu pzf = PyZipFile(str(target[0]), 'w') 1192655Sstever@eecs.umich.edu for s in source: 1202655Sstever@eecs.umich.edu pzf.writepy(str(s)) 1212655Sstever@eecs.umich.edu 1222655Sstever@eecs.umich.edu# Add the zip file target to the environment. 1232655Sstever@eecs.umich.eduenv.Command('m5py.zip', pyzip_files, buildPyZip) 1242655Sstever@eecs.umich.eduenv.Depends('m5py.zip', pyzip_dep_files) 125