250ee56ac1008b09bca08015f446b5ac0c38f4be
[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
37 from glob import glob
38 from os import system
39 from os.path import basename, dirname, exists, isdir, isfile, join as joinpath
40
41 def mkdir(*args):
42 path = joinpath(*args)
43 os.mkdir(path)
44
45 def touch(*args):
46 path = joinpath(*args)
47 os.utime(path, None)
48
49 def rmtree(*args):
50 path = joinpath(*args)
51 for match in glob(path):
52 if isdir(match):
53 shutil.rmtree(match)
54 else:
55 os.unlink(match)
56
57 def remove(*args):
58 path = joinpath(*args)
59 for match in glob(path):
60 if not isdir(match):
61 os.unlink(match)
62
63 def movedir(srcdir, destdir, dir):
64 src = joinpath(srcdir, dir)
65 dest = joinpath(destdir, dir)
66
67 if not isdir(src):
68 raise AttributeError
69
70 os.makedirs(dirname(dest))
71 shutil.move(src, dest)
72
73 if not isdir('BitKeeper'):
74 sys.exit('Not in the top level of an m5 tree!')
75
76 usage = '%s <destdir> <release name>' % sys.argv[0]
77
78 if len(sys.argv) != 3:
79 sys.exit(usage)
80
81 destdir = sys.argv[1]
82 releasename = sys.argv[2]
83 release_dest = joinpath(destdir, 'release')
84 encumbered_dest = joinpath(destdir, 'encumbered')
85 release_dir = joinpath(release_dest, releasename)
86 encumbered_dir = joinpath(encumbered_dest, releasename)
87
88 if exists(destdir):
89 if not isdir(destdir):
90 raise AttributeError, '%s exists, but is not a directory' % destdir
91 else:
92 mkdir(destdir)
93
94 if exists(release_dest):
95 if not isdir(release_dest):
96 raise AttributeError, \
97 '%s exists, but is not a directory' % release_dest
98 rmtree(release_dest)
99
100 if exists(encumbered_dest):
101 if not isdir(encumbered_dest):
102 raise AttributeError, \
103 '%s exists, but is not a directory' % encumbered_dest
104 rmtree(encumbered_dest)
105
106 mkdir(release_dest)
107 mkdir(encumbered_dest)
108 mkdir(release_dir)
109 mkdir(encumbered_dir)
110
111 system('bk export -tplain -w -r+ %s' % release_dir)
112
113 # make sure scons doesn't try to run flex unnecessarily
114 touch(release_dir, 'src/encumbered/eio/exolex.cc')
115
116 # make sure scons doesn't try to rebuild the de.msg file since it
117 # might fail on non linux machines
118 touch(release_dir, 'ext/libelf/po/de.msg')
119
120 # get rid of non-shipping code
121 rmtree(release_dir, 'src/encumbered/dev')
122 rmtree(release_dir, 'src/cpu/ozone')
123 rmtree(release_dir, 'src/mem/cache/tags/split*.cc')
124 rmtree(release_dir, 'src/mem/cache/tags/split*.hh')
125 rmtree(release_dir, 'src/mem/cache/prefetch/ghb_*.cc')
126 rmtree(release_dir, 'src/mem/cache/prefetch/ghb_*.hh')
127 rmtree(release_dir, 'src/mem/cache/prefetch/stride_*.cc')
128 rmtree(release_dir, 'src/mem/cache/prefetch/stride_*.hh')
129 rmtree(release_dir, 'configs/fullsys')
130 rmtree(release_dir, 'configs/test')
131 rmtree(release_dir, 'configs/splash2')
132 rmtree(release_dir, 'tests/long/*/ref')
133 rmtree(release_dir, 'tests/old')
134 rmtree(release_dir, 'src/dev/i8*')
135
136 # get rid of some of private scripts
137 remove(release_dir, 'util/chgcopyright')
138 remove(release_dir, 'util/make_release.py')
139
140 def remove_sources(regex, subdir):
141 script = joinpath(release_dir, subdir, 'SConscript')
142 if isinstance(regex, str):
143 regex = re.compile(regex)
144 inscript = file(script, 'r').readlines()
145 outscript = file(script, 'w')
146 for line in inscript:
147 if regex.match(line):
148 continue
149
150 outscript.write(line)
151 outscript.close()
152
153 # fix up the SConscript to deal with files we've removed
154 remove_sources(r'.*split.*\.cc', 'src/mem/cache/tags')
155 remove_sources(r'.*(ghb|stride)_prefetcher\.cc', 'src/mem/cache/prefetch')
156 remove_sources(r'.*i8254xGBe.*', 'src/dev')
157
158 benches = [ 'bzip2', 'eon', 'gzip', 'mcf', 'parser', 'perlbmk',
159 'twolf', 'vortex' ]
160 for bench in benches:
161 rmtree(release_dir, 'tests', 'test-progs', bench)
162
163 movedir(release_dir, encumbered_dir, 'src/encumbered')
164 movedir(release_dir, encumbered_dir, 'tests/test-progs/anagram')
165 movedir(release_dir, encumbered_dir, 'tests/quick/20.eio-short')
166
167 def taritup(directory, destdir, filename):
168 basedir = dirname(directory)
169 tarball = joinpath(destdir, filename)
170 tardir = basename(directory)
171
172 system('cd %s; tar cfj %s %s' % (basedir, tarball, tardir))
173
174 taritup(release_dir, destdir, '%s.tar.bz2' % releasename)
175 taritup(encumbered_dir, destdir, '%s-encumbered.tar.bz2' % releasename)
176
177 print "release created in %s" % destdir
178 print "don't forget to tag the repository! The following command will do it:"
179 print "bk tag %s" % releasename