Merge zizzer.eecs.umich.edu:/bk/newmem
[gem5.git] / util / make_release.py
1 #!/usr/bin/env python
2 # Copyright (c) 2006-2007 The Regents of The University of Michigan
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met: redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer;
9 # redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution;
12 # neither the name of the copyright holders nor the names of its
13 # contributors may be used to endorse or promote products derived from
14 # this software without specific prior written permission.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #
28 # Authors: Ali Saidi
29 # Steve Reinhardt
30 # Nathan Binkert
31
32 import os
33 import re
34 import shutil
35 import sys
36 import time
37
38 from glob import glob
39 from os import system
40 from os.path import basename, dirname, exists, isdir, isfile, join as joinpath
41
42 def mkdir(*args):
43 path = joinpath(*args)
44 os.mkdir(path)
45
46 def touch(*args, **kwargs):
47 when = kwargs.get('when', None)
48 path = joinpath(*args)
49 os.utime(path, when)
50
51 def rmtree(*args):
52 path = joinpath(*args)
53 for match in glob(path):
54 if isdir(match):
55 shutil.rmtree(match)
56 else:
57 os.unlink(match)
58
59 def remove(*args):
60 path = joinpath(*args)
61 for match in glob(path):
62 if not isdir(match):
63 os.unlink(match)
64
65 def movedir(srcdir, destdir, dir):
66 src = joinpath(srcdir, dir)
67 dest = joinpath(destdir, dir)
68
69 if not isdir(src):
70 raise AttributeError
71
72 os.makedirs(dirname(dest))
73 shutil.move(src, dest)
74
75 if not isdir('BitKeeper'):
76 sys.exit('Not in the top level of an m5 tree!')
77
78 usage = '%s <destdir> <release name>' % sys.argv[0]
79
80 if len(sys.argv) != 3:
81 sys.exit(usage)
82
83 destdir = sys.argv[1]
84 releasename = sys.argv[2]
85 release_dest = joinpath(destdir, 'release')
86 encumbered_dest = joinpath(destdir, 'encumbered')
87 release_dir = joinpath(release_dest, releasename)
88 encumbered_dir = joinpath(encumbered_dest, releasename)
89
90 if exists(destdir):
91 if not isdir(destdir):
92 raise AttributeError, '%s exists, but is not a directory' % destdir
93 else:
94 mkdir(destdir)
95
96 if exists(release_dest):
97 if not isdir(release_dest):
98 raise AttributeError, \
99 '%s exists, but is not a directory' % release_dest
100 rmtree(release_dest)
101
102 if exists(encumbered_dest):
103 if not isdir(encumbered_dest):
104 raise AttributeError, \
105 '%s exists, but is not a directory' % encumbered_dest
106 rmtree(encumbered_dest)
107
108 mkdir(release_dest)
109 mkdir(encumbered_dest)
110 mkdir(release_dir)
111 mkdir(encumbered_dir)
112
113 system('bk export -tplain -w -r+ %s' % release_dir)
114
115
116 # move the time forward on some files by a couple of minutes so we can
117 # avoid building things unnecessarily
118 when = int(time.time()) + 120
119
120 # make sure scons doesn't try to run flex unnecessarily
121 touch(release_dir, 'src/encumbered/eio/exolex.cc', when=(when, when))
122
123 # make sure libelf doesn't try to rebuild the de.msg file since it
124 # might fail on non linux machines
125 touch(release_dir, 'ext/libelf/po/de.msg', when=(when, when))
126
127 # get rid of non-shipping code
128 rmtree(release_dir, 'src/encumbered/dev')
129 rmtree(release_dir, 'src/cpu/ozone')
130 rmtree(release_dir, 'src/mem/cache/tags/split*.cc')
131 rmtree(release_dir, 'src/mem/cache/tags/split*.hh')
132 rmtree(release_dir, 'src/mem/cache/prefetch/ghb_*.cc')
133 rmtree(release_dir, 'src/mem/cache/prefetch/ghb_*.hh')
134 rmtree(release_dir, 'src/mem/cache/prefetch/stride_*.cc')
135 rmtree(release_dir, 'src/mem/cache/prefetch/stride_*.hh')
136 rmtree(release_dir, 'configs/fullsys')
137 rmtree(release_dir, 'configs/test')
138 rmtree(release_dir, 'configs/splash2')
139 rmtree(release_dir, 'tests/long/*/ref')
140 rmtree(release_dir, 'tests/old')
141 rmtree(release_dir, 'src/dev/i8*')
142
143 # get rid of some of private scripts
144 remove(release_dir, 'util/chgcopyright')
145 remove(release_dir, 'util/make_release.py')
146
147 def remove_sources(regex, subdir):
148 script = joinpath(release_dir, subdir, 'SConscript')
149 if isinstance(regex, str):
150 regex = re.compile(regex)
151 inscript = file(script, 'r').readlines()
152 outscript = file(script, 'w')
153 for line in inscript:
154 if regex.match(line):
155 continue
156
157 outscript.write(line)
158 outscript.close()
159
160 # fix up the SConscript to deal with files we've removed
161 remove_sources(r'.*split.*\.cc', 'src/mem/cache/tags')
162 remove_sources(r'.*(ghb|stride)_prefetcher\.cc', 'src/mem/cache/prefetch')
163 remove_sources(r'.*i8254xGBe.*', 'src/dev')
164
165 benches = [ 'bzip2', 'eon', 'gzip', 'mcf', 'parser', 'perlbmk',
166 'twolf', 'vortex' ]
167 for bench in benches:
168 rmtree(release_dir, 'tests', 'test-progs', bench)
169
170 movedir(release_dir, encumbered_dir, 'src/encumbered')
171 movedir(release_dir, encumbered_dir, 'tests/test-progs/anagram')
172 movedir(release_dir, encumbered_dir, 'tests/quick/20.eio-short')
173
174 def taritup(directory, destdir, filename):
175 basedir = dirname(directory)
176 tarball = joinpath(destdir, filename)
177 tardir = basename(directory)
178
179 system('cd %s; tar cfj %s %s' % (basedir, tarball, tardir))
180
181 taritup(release_dir, destdir, '%s.tar.bz2' % releasename)
182 taritup(encumbered_dir, destdir, '%s-encumbered.tar.bz2' % releasename)
183
184 print "release created in %s" % destdir
185 print "don't forget to tag the repository! The following command will do it:"
186 print "bk tag %s" % releasename