SConscript (2665:a124942bacb8) | SConscript (2667:fe64b8353b1c) |
---|---|
1# -*- mode:python -*- 2 3# Copyright (c) 2004-2005 The Regents of The University of Michigan 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: redistributions of source code must retain the above copyright --- 24 unchanged lines hidden (view full) --- 33from zipfile import PyZipFile 34 35# handy function for path joins 36def join(*args): 37 return os.path.normpath(os.path.join(*args)) 38 39Import('env') 40 | 1# -*- mode:python -*- 2 3# Copyright (c) 2004-2005 The Regents of The University of Michigan 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: redistributions of source code must retain the above copyright --- 24 unchanged lines hidden (view full) --- 33from zipfile import PyZipFile 34 35# handy function for path joins 36def join(*args): 37 return os.path.normpath(os.path.join(*args)) 38 39Import('env') 40 |
41# This SConscript is in charge of collecting .py files and generating a zip archive that is appended to the m5 binary. | 41# This SConscript is in charge of collecting .py files and generating 42# a zip archive that is appended to the m5 binary. |
42 | 43 |
43# Copy .py source files here (relative to src/python in the build 44# directory). 45pyzip_root = 'zip' 46 | |
47# List of files & directories to include in the zip file. To include 48# a package, list only the root directory of the package, not any 49# internal .py files (else they will get the path stripped off when 50# they are imported into the zip file). 51pyzip_files = [] 52 53# List of additional files on which the zip archive depends, but which 54# are not included in pyzip_files... i.e. individual .py files within 55# a package. 56pyzip_dep_files = [] 57 58# Add the specified package to the zip archive. Adds the directory to 59# pyzip_files and all included .py files to pyzip_dep_files. 60def addPkg(pkgdir): | 44# List of files & directories to include in the zip file. To include 45# a package, list only the root directory of the package, not any 46# internal .py files (else they will get the path stripped off when 47# they are imported into the zip file). 48pyzip_files = [] 49 50# List of additional files on which the zip archive depends, but which 51# are not included in pyzip_files... i.e. individual .py files within 52# a package. 53pyzip_dep_files = [] 54 55# Add the specified package to the zip archive. Adds the directory to 56# pyzip_files and all included .py files to pyzip_dep_files. 57def addPkg(pkgdir): |
61 pyzip_files.append(join(pyzip_root, pkgdir)) | 58 pyzip_files.append(pkgdir) |
62 origdir = os.getcwd() 63 srcdir = join(Dir('.').srcnode().abspath, pkgdir) 64 os.chdir(srcdir) 65 for path, dirs, files in os.walk('.'): 66 for i,dir in enumerate(dirs): 67 if dir == 'SCCS': 68 del dirs[i] 69 break 70 71 for f in files: 72 if f.endswith('.py'): | 59 origdir = os.getcwd() 60 srcdir = join(Dir('.').srcnode().abspath, pkgdir) 61 os.chdir(srcdir) 62 for path, dirs, files in os.walk('.'): 63 for i,dir in enumerate(dirs): 64 if dir == 'SCCS': 65 del dirs[i] 66 break 67 68 for f in files: 69 if f.endswith('.py'): |
73 source = join(pkgdir, path, f) 74 target = join(pyzip_root, source) 75 pyzip_dep_files.append(target) 76 env.CopyFile(target, source) | 70 pyzip_dep_files.append(join(pkgdir, path, f)) |
77 78 os.chdir(origdir) 79 80# Generate Python file that contains a dict specifying the current 81# build_env flags. 82def MakeDefinesPyFile(target, source, env): 83 f = file(str(target[0]), 'w') | 71 72 os.chdir(origdir) 73 74# Generate Python file that contains a dict specifying the current 75# build_env flags. 76def MakeDefinesPyFile(target, source, env): 77 f = file(str(target[0]), 'w') |
84 print >>f, "import __main__" 85 print >>f, "__main__.m5_build_env = ", | 78 print >>f, "m5_build_env = ", |
86 print >>f, source[0] 87 f.close() 88 89optionDict = dict([(opt, env[opt]) for opt in env.ExportOptions]) | 79 print >>f, source[0] 80 f.close() 81 82optionDict = dict([(opt, env[opt]) for opt in env.ExportOptions]) |
90env.Command('defines.py', Value(optionDict), MakeDefinesPyFile) | 83env.Command('m5/defines.py', Value(optionDict), MakeDefinesPyFile) |
91 92# Now specify the packages & files for the zip archive. 93addPkg('m5') | 84 85# Now specify the packages & files for the zip archive. 86addPkg('m5') |
94pyzip_files.append('defines.py') | 87pyzip_files.append('m5/defines.py') |
95pyzip_files.append(join(env['ROOT'], 'util/pbs/jobfile.py')) 96 | 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) | 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) |