SConscript revision 2667
16184SN/A# -*- mode:python -*-
26184SN/A
36184SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan
46184SN/A# All rights reserved.
56184SN/A#
66184SN/A# Redistribution and use in source and binary forms, with or without
76184SN/A# modification, are permitted provided that the following conditions are
86184SN/A# met: redistributions of source code must retain the above copyright
96184SN/A# notice, this list of conditions and the following disclaimer;
106184SN/A# redistributions in binary form must reproduce the above copyright
116184SN/A# notice, this list of conditions and the following disclaimer in the
126184SN/A# documentation and/or other materials provided with the distribution;
136184SN/A# neither the name of the copyright holders nor the names of its
146184SN/A# contributors may be used to endorse or promote products derived from
156184SN/A# this software without specific prior written permission.
166184SN/A#
176184SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186184SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196184SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206184SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216184SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226184SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236184SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246184SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256184SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266184SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276184SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286184SN/A#
296184SN/A# Authors: Steve Reinhardt
306184SN/A#          Nathan Binkert
316226Snate@binkert.org
326184SN/Aimport os, os.path, re, sys
336184SN/Afrom zipfile import PyZipFile
346184SN/A
356184SN/A# handy function for path joins
366184SN/Adef join(*args):
376184SN/A    return os.path.normpath(os.path.join(*args))
387720Sgblack@eecs.umich.edu
396184SN/AImport('env')
406184SN/A
416184SN/A# This SConscript is in charge of collecting .py files and generating
426184SN/A# a zip archive that is appended to the m5 binary.
436184SN/A
446184SN/A# List of files & directories to include in the zip file.  To include
456184SN/A# a package, list only the root directory of the package, not any
466227Snate@binkert.org# internal .py files (else they will get the path stripped off when
477720Sgblack@eecs.umich.edu# they are imported into the zip file).
486184SN/Apyzip_files = []
496184SN/A
506184SN/A# List of additional files on which the zip archive depends, but which
517720Sgblack@eecs.umich.edu# are not included in pyzip_files... i.e. individual .py files within
526184SN/A# a package.
536184SN/Apyzip_dep_files = []
546184SN/A
556184SN/A# Add the specified package to the zip archive.  Adds the directory to
566184SN/A# pyzip_files and all included .py files to pyzip_dep_files.
576184SN/Adef addPkg(pkgdir):
586184SN/A    pyzip_files.append(pkgdir)
596184SN/A    origdir = os.getcwd()
606184SN/A    srcdir = join(Dir('.').srcnode().abspath, pkgdir)
616184SN/A    os.chdir(srcdir)
626184SN/A    for path, dirs, files in os.walk('.'):
636184SN/A        for i,dir in enumerate(dirs):
646184SN/A            if dir == 'SCCS':
656184SN/A                del dirs[i]
666184SN/A                break
676184SN/A
686184SN/A        for f in files:
696184SN/A            if f.endswith('.py'):
706184SN/A                pyzip_dep_files.append(join(pkgdir, path, f))
716184SN/A
726184SN/A    os.chdir(origdir)
736184SN/A
747720Sgblack@eecs.umich.edu# Generate Python file that contains a dict specifying the current
756184SN/A# build_env flags.
766184SN/Adef MakeDefinesPyFile(target, source, env):
776184SN/A    f = file(str(target[0]), 'w')
787720Sgblack@eecs.umich.edu    print >>f, "m5_build_env = ",
796184SN/A    print >>f, source[0]
80    f.close()
81
82optionDict = dict([(opt, env[opt]) for opt in env.ExportOptions])
83env.Command('m5/defines.py', Value(optionDict), MakeDefinesPyFile)
84
85# Now specify the packages & files for the zip archive.
86addPkg('m5')
87pyzip_files.append('m5/defines.py')
88pyzip_files.append(join(env['ROOT'], 'util/pbs/jobfile.py'))
89
90env.Command(['swig/main_wrap.cc', 'm5/main.py'],
91            'swig/main.i',
92            '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
93            '-o ${TARGETS[0]} $SOURCES')
94
95pyzip_dep_files.append('m5/main.py')
96
97# Action function to build the zip archive.  Uses the PyZipFile module
98# included in the standard Python library.
99def buildPyZip(target, source, env):
100    pzf = PyZipFile(str(target[0]), 'w')
101    for s in source:
102        pzf.writepy(str(s))
103
104# Add the zip file target to the environment.
105env.Command('m5py.zip', pyzip_files, buildPyZip)
106env.Depends('m5py.zip', pyzip_dep_files)
107