SConscript revision 2763:c3741c707d53
12155SN/A# -*- mode:python -*-
22155SN/A
32155SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan
42155SN/A# All rights reserved.
52155SN/A#
62155SN/A# Redistribution and use in source and binary forms, with or without
72155SN/A# modification, are permitted provided that the following conditions are
82155SN/A# met: redistributions of source code must retain the above copyright
92155SN/A# notice, this list of conditions and the following disclaimer;
102155SN/A# redistributions in binary form must reproduce the above copyright
112155SN/A# notice, this list of conditions and the following disclaimer in the
122155SN/A# documentation and/or other materials provided with the distribution;
132155SN/A# neither the name of the copyright holders nor the names of its
142155SN/A# contributors may be used to endorse or promote products derived from
152155SN/A# this software without specific prior written permission.
162155SN/A#
172155SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182155SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192155SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202155SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212155SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222155SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232155SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242155SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252155SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262155SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272155SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu#
292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
302155SN/A#          Nathan Binkert
314202Sbinkertn@umich.edu
322155SN/Aimport os, os.path, re, sys
332178SN/Afrom zipfile import PyZipFile
342178SN/A
352178SN/A# handy function for path joins
362178SN/Adef join(*args):
372178SN/A    return os.path.normpath(os.path.join(*args))
382178SN/A
392178SN/AImport('env')
402178SN/A
412178SN/A# This SConscript is in charge of collecting .py files and generating
422178SN/A# a zip archive that is appended to the m5 binary.
432178SN/A
442178SN/A# List of files & directories to include in the zip file.  To include
452155SN/A# a package, list only the root directory of the package, not any
462178SN/A# internal .py files (else they will get the path stripped off when
472155SN/A# they are imported into the zip file).
482155SN/Apyzip_files = []
492178SN/A
502155SN/A# List of additional files on which the zip archive depends, but which
512155SN/A# are not included in pyzip_files... i.e. individual .py files within
522623SN/A# a package.
533918Ssaidi@eecs.umich.edupyzip_dep_files = []
542623SN/A
552623SN/A# Add the specified package to the zip archive.  Adds the directory to
563918Ssaidi@eecs.umich.edu# pyzip_files and all included .py files to pyzip_dep_files.
572155SN/Adef addPkg(pkgdir):
582155SN/A    pyzip_files.append(pkgdir)
592292SN/A    origdir = os.getcwd()
603918Ssaidi@eecs.umich.edu    srcdir = join(Dir('.').srcnode().abspath, pkgdir)
612292SN/A    os.chdir(srcdir)
622292SN/A    for path, dirs, files in os.walk('.'):
632292SN/A        for i,dir in enumerate(dirs):
643918Ssaidi@eecs.umich.edu            if dir == 'SCCS':
652292SN/A                del dirs[i]
662292SN/A                break
672766Sktlim@umich.edu
682766Sktlim@umich.edu        for f in files:
692766Sktlim@umich.edu            if f.endswith('.py'):
702921Sktlim@umich.edu                pyzip_dep_files.append(join(pkgdir, path, f))
712921Sktlim@umich.edu
722766Sktlim@umich.edu    os.chdir(origdir)
732766Sktlim@umich.edu
742766Sktlim@umich.edu# Generate Python file that contains a dict specifying the current
754762Snate@binkert.org# build_env flags.
762155SN/Adef MakeDefinesPyFile(target, source, env):
772155SN/A    f = file(str(target[0]), 'w')
782155SN/A    print >>f, "m5_build_env = ",
792155SN/A    print >>f, source[0]
802155SN/A    f.close()
812155SN/A
822766Sktlim@umich.eduoptionDict = dict([(opt, env[opt]) for opt in env.ExportOptions])
832155SN/Aenv.Command('m5/defines.py', Value(optionDict), MakeDefinesPyFile)
842623SN/A
852155SN/A# Now specify the packages & files for the zip archive.
862155SN/AaddPkg('m5')
872155SN/Apyzip_files.append('m5/defines.py')
882155SN/Apyzip_files.append(join(env['ROOT'], 'util/pbs/jobfile.py'))
892178SN/A
902178SN/Aenv.Command(['swig/cc_main_wrap.cc', 'm5/cc_main.py'],
912178SN/A            'swig/cc_main.i',
922766Sktlim@umich.edu            '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
932178SN/A            '-o ${TARGETS[0]} $SOURCES')
942178SN/A
952178SN/Apyzip_dep_files.append('m5/cc_main.py')
962178SN/A
972766Sktlim@umich.edu# Action function to build the zip archive.  Uses the PyZipFile module
982766Sktlim@umich.edu# included in the standard Python library.
992766Sktlim@umich.edudef buildPyZip(target, source, env):
1002788Sktlim@umich.edu    pzf = PyZipFile(str(target[0]), 'w')
1012178SN/A    for s in source:
1022733Sktlim@umich.edu        pzf.writepy(str(s))
1032733Sktlim@umich.edu
1042817Sksewell@umich.edu# Add the zip file target to the environment.
1052733Sktlim@umich.eduenv.Command('m5py.zip', pyzip_files, buildPyZip)
1064486Sbinkertn@umich.eduenv.Depends('m5py.zip', pyzip_dep_files)
1074486Sbinkertn@umich.edu