-
Notifications
You must be signed in to change notification settings - Fork 7
/
make_distributions.py
executable file
·273 lines (222 loc) · 12.1 KB
/
make_distributions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/usr/bin/env python3
# script for generating distribution tarballs
import sys, os, shutil, optparse, tarfile, subprocess
import markdown
sys.path.append(os.getcwd())
import distribution_manifest as dm
# where to copy binary (or source) tarballs when completed (specialized for
# Linux virtual machines on MacBook Pro and local web-site directory for Mac
# versions)
# LINUX_DEST = local folder within Linux VM
LINUX_DEST = "/vagrant/transfer/"
MAC_DEST = "/Users/erwin/Documents/Working/web_site_new/resources/imfit/"
MAC_DEST_BIN = "/Users/erwin/Documents/Working/web_site_new/resources/imfit/binaries/"
MAC_CHANGELOG_MD = "CHANGELOG.md"
MAC_CHANGELOG_DEST = "/Users/erwin/Documents/Working/web_site_new/resources/imfit/CHANGELOG.html"
VERSION_STRING = "1.9.0"
os_type = os.uname()[0] # "Darwin", "Linux", etc.
os_machine_type = os.uname()[4] # "x86-64", etc.
# basic scons command (specifies static linking, etc.)
scons_string = "scons --static"
scons_string_mac = "scons --mac-distribution"
SOURCE_TARFILE = "imfit-%s-source.tar.gz" % VERSION_STRING
if (os_type == "Darwin"): # OK, we're compiling on Mac OS X
if os_machine_type == "x86_64":
BINARY_TARFILE = "imfit-%s-macos-x86-64.tar.gz" % VERSION_STRING
else:
BINARY_TARFILE = "imfit-%s-macos-arm64.tar.gz" % VERSION_STRING
scons_string += " --clang-openmp"
SOURCE_COPY_DEST_DIR = MAC_DEST
BINARY_COPY_DEST_DIR = MAC_DEST_BIN
else:
# assume it's Linux
if os_machine_type == "x86_64":
BINARY_TARFILE = "imfit-%s-linux-64.tar.gz" % VERSION_STRING
else:
BINARY_TARFILE = "imfit-%s-linux-32.tar.gz" % VERSION_STRING
BINARY_COPY_DEST_DIR = LINUX_DEST
SOURCE_COPY_DEST_DIR = LINUX_DEST
# Create dictionaries holding subdirectory names and lists of associated files
documentationFileDict = {"dir": "docs", "file_list": dm.documentation_files.split()}
extrasFileDict = {"dir": "extras", "file_list": dm.extras_files.split()}
coreFileDict = {"dir": "core", "file_list": dm.source_files_core.split()}
solversFileDict = {"dir": "solvers", "file_list": dm.source_files_solvers.split()}
mcmcFileDict = {"dir": "cdream", "file_list": dm.source_files_mcmc.split()}
funcObjFileDict = {"dir": "function_objects", "file_list": dm.source_files_funcobj.split()}
exampleFileDict = {"dir": "examples", "file_list": dm.example_files.split()}
pythonFileDict = {"dir": "python", "file_list": dm.python_files.split()}
testFileDict_imfit = {"dir": "tests/imfit_reference", "file_list": dm.test_files_imfit.split()}
testFileDict_mcmc = {"dir": "tests/imfit-mcmc_reference", "file_list": dm.test_files_mcmc.split()}
testFileDict_makeimage = {"dir": "tests/makeimage_reference", "file_list": dm.test_files_makeimage.split()}
testFileDict = {"dir": "tests", "file_list": dm.test_files.split()}
# Lists of files:
binary_only_file_list = dm.binary_only_files.split()
misc_required_files_list = dm.misc_required_files.split()
testing_scripts_list = dm.testing_scripts.split()
python_files_for_binary_dist_list = dm.python_files_for_binary_dist.split()
documentation_file_list = [ documentationFileDict["dir"] + "/" + fname for fname in documentationFileDict["file_list"] ]
extras_file_list = [ extrasFileDict["dir"] + "/" + fname for fname in extrasFileDict["file_list"] ]
example_file_list = [ exampleFileDict["dir"] + "/" + fname for fname in exampleFileDict["file_list"] ]
python_file_list = [ pythonFileDict["dir"] + "/" + fname for fname in pythonFileDict["file_list"] ]
test_file_imfit_list = [ testFileDict_imfit["dir"] + "/" + fname for fname in testFileDict_imfit["file_list"] ]
test_file_mcmc_list = [ testFileDict_mcmc["dir"] + "/" + fname for fname in testFileDict_mcmc["file_list"] ]
test_file_makeimage_list = [ testFileDict_makeimage["dir"] + "/" + fname for fname in testFileDict_makeimage["file_list"] ]
test_file_list = [ testFileDict["dir"] + "/" + fname for fname in testFileDict["file_list"] ]
solvers_file_list_cpp = [ solversFileDict["dir"] + "/" + fname + ".cpp" for fname in solversFileDict["file_list"] ]
solvers_file_list_h = [ solversFileDict["dir"] + "/" + fname + ".h" for fname in solversFileDict["file_list"] ]
solvers_file_list = solvers_file_list_h + solvers_file_list_cpp
mcmc_file_list_cpp = [ mcmcFileDict["dir"] + "/" + fname + ".cpp" for fname in mcmcFileDict["file_list"] ]
mcmc_file_list_h = [ mcmcFileDict["dir"] + "/" + fname + ".h" for fname in dm.source_header_files_mcmc.split() ]
mcmc_file_list = mcmc_file_list_h + mcmc_file_list_cpp
core_file_list_cpp = [ coreFileDict["dir"] + "/" + fname + ".cpp" for fname in coreFileDict["file_list"] ]
core_file_list_h = [ coreFileDict["dir"] + "/" + fname + ".h" for fname in dm.source_header_files_core.split() ]
core_file_list = core_file_list_h + core_file_list_cpp
funcobj_file_list_cpp = [ funcObjFileDict["dir"] + "/" + fname + ".cpp" for fname in funcObjFileDict["file_list"] ]
funcobj_file_list_h = [ funcObjFileDict["dir"] + "/" + fname + ".h" for fname in funcObjFileDict["file_list"] ]
funcobj_file_list = funcobj_file_list_h + funcobj_file_list_cpp
allFileLists = [binary_only_file_list, misc_required_files_list, documentation_file_list, extras_file_list,
example_file_list, python_file_list, testing_scripts_list, test_file_imfit_list,
test_file_mcmc_list, test_file_makeimage_list, test_file_list, solvers_file_list,
mcmc_file_list, core_file_list, funcobj_file_list]
allFileLists_source = [misc_required_files_list, documentation_file_list, extras_file_list,
example_file_list, python_file_list, testing_scripts_list, test_file_imfit_list,
test_file_mcmc_list, test_file_makeimage_list, test_file_list, solvers_file_list,
mcmc_file_list, core_file_list, funcobj_file_list]
subdirs_list = ["docs", "extras", "examples", "python", "tests", "tests/osx", "tests/linux",
"tests/imfit_reference", "tests/imfit-mcmc_reference", "tests/makeimage_reference",
"tests/mcmc_data", "function_objects", "solvers", "cdream", "cdream/include",
"cdream/include/rng", "core"]
def TrimSConstruct( ):
lines = open("SConstruct").readlines()
nLines = len(lines)
for i in range(nLines):
if lines[i].startswith("# *** Other programs"):
lastLineNumber = i
outf = open("SConstruct_export", 'w')
for line in lines[0:lastLineNumber]:
outf.write(line)
outf.close()
def MakeDistributionDir( mode="binary" ):
distDir = "imfit-%s/" % VERSION_STRING
# create distribution subdirectories, if needed
if not os.path.exists(distDir):
os.mkdir(distDir)
for subdir in subdirs_list:
if not os.path.exists(distDir + subdir):
os.mkdir(distDir + subdir)
# copy files to distribution subdirectory
if (mode == "binary"):
fileLists = allFileLists
else:
fileLists = allFileLists_source
for fileList in fileLists:
print(fileList)
for fname in fileList:
print("%s -> %s" % (fname, distDir + fname))
shutil.copy(fname, distDir + fname)
# copy misc. files requring renaming
# copy trimmed version of SConstruct
TrimSConstruct()
shutil.copy("SConstruct_export", distDir + "SConstruct")
# def MakeOldMacBinaries( ):
# """This is for making 64-bit binaries for Mac OS X 10.6 or 10.7.
# """
#
# print(" Calling SCons to generate 64-bit imfit binary for Mac OS 10.6/10.7...")
# subprocess.check_output("scons -c", shell=True)
# subprocess.check_output(scons_string_oldmac + " imfit", shell=True)
# print(" Calling SCons to generate 64-bit makeimage binary for Mac OS 10.6/10.7...")
# subprocess.check_output(scons_string_oldmac + " makeimage", shell=True)
# def MakeBinaries( mode=None ):
# # Generate appropriate binaries
# print("MakeBinaries: mode = %s" % mode)
# if (mode == "Darwin") or (mode == "Linux"):
# # Mac OS 10.8 or newer, or Linux
# if (mode is "Darwin"):
# # use "--allstatic" to force static linking of GCC libraries (esp. libgomp)
# scons_string_final = scons_string_mac
# else:
# scons_string_final = scons_string
# print(" Calling SCons to generate imfit binary...")
# subprocess.check_output(scons_string_final + " imfit", shell=True)
# print(" Calling SCons to generate makeimage binary...")
# subprocess.check_output(scons_string_final + " makeimage", shell=True)
# print(" Calling SCons to generate imfit-mcmc binary...")
# subprocess.check_output(scons_string_final + " imfit-mcmc", shell=True)
# else: # mode = "oldmac"
# # Mac OS 10.6 or 10.7
# MakeOldMacBinaries()
def MakeBinaries( target="mac" ):
if target == "mac":
scons_string_final = scons_string_mac
else: # Linux
scons_string_final = scons_string
print(" Calling SCons to generate imfit binary...")
subprocess.check_output(scons_string_final + " imfit", shell=True)
print(" Calling SCons to generate makeimage binary...")
subprocess.check_output(scons_string_final + " makeimage", shell=True)
print(" Calling SCons to generate imfit-mcmc binary...")
subprocess.check_output(scons_string_final + " imfit-mcmc", shell=True)
def MakeBinaryDist( ):
distDir = "imfit-%s/" % VERSION_STRING
final_file_list = binary_only_file_list + misc_required_files_list + \
python_files_for_binary_dist_list + documentation_file_list + \
extras_file_list + example_file_list
binaryTarfile = BINARY_TARFILE
print("Generating tar file %s..." % binaryTarfile)
tar = tarfile.open(binaryTarfile, 'w|gz')
for fname in final_file_list:
tar.add(distDir + fname)
tar.close()
print("Copying gzipped tar file %s to %s..." % (binaryTarfile, BINARY_COPY_DEST_DIR))
shutil.copy(binaryTarfile, BINARY_COPY_DEST_DIR)
def MakeSourceDist( ):
distDir = "imfit-%s/" % VERSION_STRING
final_file_list = example_file_list + misc_required_files_list + documentation_file_list
final_file_list += extras_file_list
final_file_list += funcobj_file_list
final_file_list += solvers_file_list
final_file_list += mcmc_file_list
final_file_list += core_file_list
final_file_list += python_file_list
final_file_list += testing_scripts_list
final_file_list += test_file_imfit_list
final_file_list += test_file_mcmc_list
final_file_list += test_file_makeimage_list
final_file_list += test_file_list
final_file_list.append("SConstruct")
tar = tarfile.open(SOURCE_TARFILE, 'w|gz')
for fname in final_file_list:
tar.add(distDir + fname)
tar.close()
print("Copying gzipped tar file %s to %s..." % (SOURCE_TARFILE, SOURCE_COPY_DEST_DIR))
shutil.copy(SOURCE_TARFILE, SOURCE_COPY_DEST_DIR)
print("Generating HTML version of CHANGELOG.md and copying to %s..." % (MAC_CHANGELOG_DEST))
markdown.markdownFromFile(input=MAC_CHANGELOG_MD, output=MAC_CHANGELOG_DEST)
def main(argv):
usageString = "%prog [options]\n"
parser = optparse.OptionParser(usage=usageString, version="%prog ")
parser.add_option("--source-only", action="store_false", dest="binaryDist", default=True,
help="generate *only* the source distribution tarball")
parser.add_option("--binary-only", action="store_false", dest="sourceDist", default=True,
help="generate *only* the binary-only distribution tarball")
(options, args) = parser.parse_args(argv)
print("\nMaking distribution directory and copying files into it...")
if options.binaryDist is True:
if (os_type == "Darwin"):
print("\nGenerating binary-only Mac distribution (%s)..." % BINARY_TARFILE)
MakeBinaries("mac")
MakeDistributionDir(mode="binary")
MakeBinaryDist()
else:
print("\nGenerating binary-only Linux distribution (%s)..." % BINARY_TARFILE)
MakeBinaries("Linux")
MakeDistributionDir(mode="binary")
MakeBinaryDist()
if options.sourceDist is True:
print("\nGenerating source distribution (%s)..." % SOURCE_TARFILE)
MakeDistributionDir(mode="source")
MakeSourceDist()
print("Done!\n")
if __name__ == "__main__":
main(sys.argv)