]> git.saurik.com Git - wxWidgets.git/blame - build/tools/create-archive.py
Don't exclude tests from wxMSW-Setup.exe.
[wxWidgets.git] / build / tools / create-archive.py
CommitLineData
3b2c81c7
RD
1#!/usr/bin/env python
2
3import glob
4import optparse
5import os
6import platform
7import re
8import shutil
9import string
10import sys
11import tempfile
12import types
13import pdb
14
15## CONSTANTS
16
17scriptDir = os.path.join(sys.path[0])
18rootDir = os.path.abspath(os.path.join(scriptDir, "..", ".."))
19contribDir = os.path.join("contrib", "src")
20
21dirsToCopy = ["art", "build", "debian", "demos", "distrib/mac", "docs", "include", "interface", "lib",
22 "locale", "samples", "src", "tests", "utils"]
23
24dirsToIgnore = [".svn", "CVS"]
25excludeExtensions = [".rej", ".orig", ".mine", ".tmp"]
26
27option_dict = {
28 "compression" : ("gzip", "Compression to use. Values are: gzip, bzip, zip, all (default: gzip)"),
29 "docs" : ("html", "Doc formats to build. Comma separated. Values are: none, html (default: html)"),
30 "name" : ("wxWidgets", "Name given to the tarball created (default: wxWidgets)"),
31 "postfix" : ("", "String appended to the version to indicate a special release (default: none)"),
32 "wxpython" : (False, "Produce wxPython source tarball (name defaults to wxPython-src)")
33 }
34
35mswProjectFiles = [ ".vcproj", ".sln", ".dsp", ".dsw", ".vc", ".bat"]
36nativeLineEndingFiles = [".cpp", ".h", ".c", ".txt"]
37
38
39
40## PARSE OPTIONS
41
42usage="""usage: %prog [options] <output directory>\n
43Create a wxWidgets archive and store it in <output directory>.
44The output directory must be an absolute, existing path.
45Type %prog --help for options.
46"""
47
48parser = optparse.OptionParser(usage, version="%prog 1.0")
49
50for opt in option_dict:
51 default = option_dict[opt][0]
52
53 action = "store"
54 if type(default) == types.BooleanType:
55 action = "store_true"
56 parser.add_option("--" + opt, default=default, action=action, dest=opt, help=option_dict[opt][1])
57
58options, arguments = parser.parse_args()
59
60if len(arguments) < 1 or not os.path.exists(arguments[0]) or not os.path.isabs(arguments[0]):
61 parser.print_usage()
62 sys.exit(1)
63
64destDir = arguments[0]
65if not os.path.exists(destDir):
66 os.makedirs(destDir)
67
68wxVersion = None
69VERSION_FILE = os.path.join(rootDir, 'include/wx/version.h')
70
71
72## HELPER FUNCTIONS
73
74def makeDOSLineEndings(dir, extensions):
75 fileList = []
76 for root, subFolders, files in os.walk(dir):
77 for file in files:
78 if os.path.splitext(file)[1] in extensions:
79 os.system("unix2dos %s" % os.path.join(root, file))
80
81def getVersion(includeSubrelease=False):
82 """Returns wxWidgets version as a tuple: (major,minor,release)."""
83
84 wxVersion = None
85 major = None
86 minor = None
87 release = None
88 subrelease = None
89 if wxVersion == None:
90 f = open(VERSION_FILE, 'rt')
91 lines = f.readlines()
92 f.close()
93 major = minor = release = None
94 for l in lines:
95 if not l.startswith('#define'): continue
96 splitline = l.strip().split()
97 if splitline[0] != '#define': continue
98 if len(splitline) < 3: continue
99 name = splitline[1]
100 value = splitline[2]
101 if value == None: continue
102 if name == 'wxMAJOR_VERSION': major = int(value)
103 if name == 'wxMINOR_VERSION': minor = int(value)
104 if name == 'wxRELEASE_NUMBER': release = int(value)
105 if name == 'wxSUBRELEASE_NUMBER': subrelease = int(value)
106 if major != None and minor != None and release != None:
107 if not includeSubrelease or subrelease != None:
108 break
109
110 if includeSubrelease:
111 wxVersion = (major, minor, release, subrelease)
112 else:
113 wxVersion = (major, minor, release)
114 return wxVersion
115
116def allFilesRecursive(dir):
117 fileList = []
118 for root, subFolders, files in os.walk(dir):
119 shouldCopy = True
120 for ignoreDir in dirsToIgnore:
121 if ignoreDir in root:
122 shouldCopy = False
123
124 if shouldCopy:
125 for file in files:
126 path = os.path.join(root,file)
127 for exclude in excludeExtensions:
128 if not os.path.splitext(file)[1] in excludeExtensions:
129 fileList.append(os.path.join(root,file))
130 return fileList
131
132
133## MAKE THE RELEASE!
134
135str_version = "" ##"%d.%d.%d" % getVersion()
136archive_name = options.name
137
138if options.wxpython:
139 dirsToCopy.append("wxPython")
140 archive_name = "wxPython-src"
141## str_version = "%d.%d.%d.%d" % getVersion(includeSubrelease=True)
142 options.docs = "none"
143
144if options.postfix != "":
145 str_version += "-" + options.postfix
146
147full_name = archive_name ## + "-" + str_version
148
149copyDir = tempfile.mkdtemp()
150wxCopyDir = os.path.join(copyDir, full_name)
151
152os.makedirs(wxCopyDir)
153
154os.chdir(rootDir)
155fileList = []
156rootFiles = glob.glob("*")
157for afile in rootFiles:
158 if os.path.isfile(os.path.abspath(afile)):
159 fileList.append(afile)
160
161for dir in dirsToCopy:
162 print "Determining files to copy from %s..." % dir
163 fileList.extend(allFilesRecursive(dir))
164
165print "Copying files to the temporary folder %s..." % copyDir
166for afile in fileList:
167 destFile = os.path.join(wxCopyDir, afile)
168 dirName = os.path.dirname(destFile)
169 if not os.path.exists(dirName):
170 os.makedirs(dirName)
171 shutil.copy(os.path.join(rootDir, afile), destFile)
172
173# copy include/wx/msw/setup0.h -> include/wx/msw/setup.h
174mswSetup0 = os.path.join(wxCopyDir, "include","wx","msw","setup0.h")
175shutil.copy(mswSetup0, mswSetup0.replace("setup0.h", "setup.h")),
ee915a64
VS
176
177# compile gettext catalogs
178print "Compiling gettext catalogs..."
179os.system("make -C %s/locale allmo" % wxCopyDir)
3b2c81c7
RD
180
181all = options.compression == "all"
182
183# make sure they have the DOS line endings everywhere
184##print "Setting MSW Project files to use DOS line endings..."
185##makeDOSLineEndings(wxCopyDir, mswProjectFiles)
186
187if all or options.compression == "gzip":
188 print "Creating gzip archive..."
189 os.chdir(copyDir)
190 os.system("tar -czvf %s/%s.tar.gz %s" % (destDir, full_name, "*"))
191 os.chdir(rootDir)
192
193if all or options.compression == "bzip":
194 print "Creating bzip archive..."
195 os.chdir(copyDir)
196 os.system("tar -cjvf %s/%s.tar.bz2 %s" % (destDir, full_name, "*"))
197 os.chdir(rootDir)
198
199if all or options.compression == "zip":
200 os.chdir(copyDir)
201 print "Setting DOS line endings on source and text files..."
202 ## makeDOSLineEndings(copyDir, nativeLineEndingFiles)
203 print "Creating zip archive..."
204 os.system("zip -9 -r %s/%s.zip %s" % (destDir, full_name, "*"))
205 os.chdir(rootDir)
206
207shutil.rmtree(copyDir)
208
209
210# build any docs packages:
211doc_formats = string.split(options.docs, ",")
212doxy_dir = "docs/doxygen"
9670c0a8 213output_dir = os.path.join(rootDir,"docs/doxygen/out")
3b2c81c7
RD
214if not os.path.exists(output_dir):
215 os.makedirs(output_dir)
216
217for format in doc_formats:
218 if not format == "none":
219 os.chdir(doxy_dir)
220 if platform.system() == "Windows":
221 print "Windows platform"
222 os.system("regen.bat %s" % format)
223 else:
224 os.system("regen.sh %s" % format)
225
226 os.chdir(output_dir)
227
228 if format == "html":
229 src = format
230 docs_full_name = "%s-%s" % (full_name, format.upper())
231 files_to_zip = "*"
232 else:
233 src = "wx.%s" % format
234 docs_full_name = "%s.%s" % (full_name, format.upper())
235 files_to_zip = docs_full_name
236
237 os.rename(src, docs_full_name)
238 os.system("zip -9 -r %s/%s.zip %s" % (destDir, docs_full_name, files_to_zip))
239 os.chdir(rootDir)
240
241os.chdir(rootDir)
242if os.path.exists(output_dir):
243 shutil.rmtree(output_dir)