]> git.saurik.com Git - wxWidgets.git/blame - build/tools/create-archive.py
2.9.2-rc1 in file
[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")),
176
177all = options.compression == "all"
178
179# make sure they have the DOS line endings everywhere
180##print "Setting MSW Project files to use DOS line endings..."
181##makeDOSLineEndings(wxCopyDir, mswProjectFiles)
182
183if all or options.compression == "gzip":
184 print "Creating gzip archive..."
185 os.chdir(copyDir)
186 os.system("tar -czvf %s/%s.tar.gz %s" % (destDir, full_name, "*"))
187 os.chdir(rootDir)
188
189if all or options.compression == "bzip":
190 print "Creating bzip archive..."
191 os.chdir(copyDir)
192 os.system("tar -cjvf %s/%s.tar.bz2 %s" % (destDir, full_name, "*"))
193 os.chdir(rootDir)
194
195if all or options.compression == "zip":
196 os.chdir(copyDir)
197 print "Setting DOS line endings on source and text files..."
198 ## makeDOSLineEndings(copyDir, nativeLineEndingFiles)
199 print "Creating zip archive..."
200 os.system("zip -9 -r %s/%s.zip %s" % (destDir, full_name, "*"))
201 os.chdir(rootDir)
202
203shutil.rmtree(copyDir)
204
205
206# build any docs packages:
207doc_formats = string.split(options.docs, ",")
208doxy_dir = "docs/doxygen"
9670c0a8 209output_dir = os.path.join(rootDir,"docs/doxygen/out")
3b2c81c7
RD
210if not os.path.exists(output_dir):
211 os.makedirs(output_dir)
212
213for format in doc_formats:
214 if not format == "none":
215 os.chdir(doxy_dir)
216 if platform.system() == "Windows":
217 print "Windows platform"
218 os.system("regen.bat %s" % format)
219 else:
220 os.system("regen.sh %s" % format)
221
222 os.chdir(output_dir)
223
224 if format == "html":
225 src = format
226 docs_full_name = "%s-%s" % (full_name, format.upper())
227 files_to_zip = "*"
228 else:
229 src = "wx.%s" % format
230 docs_full_name = "%s.%s" % (full_name, format.upper())
231 files_to_zip = docs_full_name
232
233 os.rename(src, docs_full_name)
234 os.system("zip -9 -r %s/%s.zip %s" % (destDir, docs_full_name, files_to_zip))
235 os.chdir(rootDir)
236
237os.chdir(rootDir)
238if os.path.exists(output_dir):
239 shutil.rmtree(output_dir)