forked from boostorg/release-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MakeBoostDistro.py
executable file
·198 lines (169 loc) · 6.03 KB
/
MakeBoostDistro.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
#!/usr/bin/python
#
# Prepare a boost checkout for release
# 1) Copy all the files at the root level to the dest folder ($DEST)
# 2) Copy all the "special" folders to the dest folder ($DEST)
# 3) copy all the files from $SOURCE/libs to $DEST/libs
# 4a) For each subproject, copy everything except "include" into $DEST/libs
# 4b) For each subproject, copy the contents of the "includes" folder into $DEST/boost
#
# Usage: %0 source dest
import os, sys
import shutil
import stat
IgnoreFiles = shutil.ignore_patterns(
'[.]*',
'[.]gitattributes',
'[.]gitignore',
'[.]gitmodules',
'[.]travis[.]yml',
'appveyor[.]yml',
'circle[.]yml')
def IgnoreFile(src, name):
return len(IgnoreFiles(src, [name])) > 0
## from <http://stackoverflow.com/questions/1868714/how-do-i-copy-an-entire-directory-of-files-into-an-existing-directory-using-pyth>
def MergeTree(src, dst, symlinks = False):
if not os.path.exists(dst):
os.makedirs(dst)
shutil.copystat(src, dst)
lst = os.listdir(src)
excl = IgnoreFiles(src, lst)
lst = [x for x in lst if x not in excl]
for item in lst:
s = os.path.join(src, item)
d = os.path.join(dst, item)
if symlinks and os.path.islink(s):
if os.path.lexists(d):
os.remove(d)
os.symlink(os.readlink(s), d)
try:
st = os.lstat(s)
mode = stat.S_IMODE(st.st_mode)
os.lchmod(d, mode)
except:
pass # lchmod not available
elif os.path.isdir(s):
MergeTree(s, d, symlinks)
else:
if os.path.exists(d):
print "## Overwriting file %s with %s" % (d, s)
shutil.copy2(s, d)
def CopyFile (s, d, f):
if os.path.isfile(os.path.join(s,f)) and not IgnoreFile(s, f):
shutil.copy2(os.path.join(s,f), os.path.join(d,f))
def CopyDir (s, d, dd):
if os.path.isdir(os.path.join(s,dd)) and not IgnoreFile(s, dd):
shutil.copytree(os.path.join(s,dd), os.path.join(d,dd), symlinks=False, ignore=IgnoreFiles)
def MergeIf(s, d, dd):
# if dd == 'detail':
# print "MergeIf %s -> %s" % (os.path.join(s, dd), os.path.join(d, dd))
if os.path.exists(os.path.join(s, dd)):
MergeTree(os.path.join(s, dd), os.path.join(d, dd), symlinks=False)
def CopyInclude(src, dst):
for item in os.listdir(src):
if IgnoreFile(src, item):
continue
if item == 'pending':
continue
if item == 'detail':
continue
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s):
MergeTree(s, d, symlinks=False)
else:
if os.path.exists(d):
print "## Overwriting file %s with %s" % (d, s)
CopyFile(src, dst, item)
def CopySubProject(src, dst, headers, p):
# First, everything except the "include" directory
Source = os.path.join(src,p)
Dest = os.path.join(dst,p)
# print "CopySubProject %p" % p
os.makedirs(Dest)
for item in os.listdir(Source):
if os.path.isfile(os.path.join(Source, item)):
CopyFile(Source, Dest, item)
elif item != "include":
CopyDir(Source, Dest, item)
#shutil.copytree(Source, Dest, symlinks=False, ignore=shutil.ignore_patterns('\.*', "include"))
# Now the includes
Source = os.path.join(src, "%s/include/boost" % p)
CopyInclude(Source, headers)
# MergeTree(Source, Dest, symlinks=False, ignore=shutil.ignore_patterns('\.*', 'detail', 'pending'))
MergeIf(Source, headers, 'detail')
MergeIf(Source, headers, 'pending')
def CopyNestedProject(src, dst, headers, p):
# First, everything except the "include" directory
Source = os.path.join(src,p[1])
Dest = os.path.join(dst,p[1])
os.makedirs(Dest)
for item in os.listdir(Source):
if os.path.isfile(os.path.join(Source, item)):
CopyFile(Source, Dest, item)
elif item != "include":
CopyDir(Source, Dest, item)
# shutil.copytree(Source, Dest, symlinks=False, ignore=shutil.ignore_patterns('\.*', "include"))
Source = os.path.join(src, "%s/include/boost" % (p[1]))
# Dest = os.path.join(headers, p)
# print "Installing headers from %s to %s" % (Source, headers)
CopyInclude(Source, headers)
# # MergeTree(Source, Dest, symlinks=False, ignore=shutil.ignore_patterns('\.*', 'detail', 'pending'))
# MergeIf(Source, headers, 'detail')
# MergeIf(Source, headers, 'pending')
BoostHeaders = "boost"
BoostLibs = "libs"
BoostSpecialFolders = [ "doc", "more", "status", "tools" ]
SourceRoot = sys.argv[1]
DestRoot = sys.argv[2]
print "Source = %s" % SourceRoot
print "Dest = %s" % DestRoot
if not os.path.exists(SourceRoot):
print "## Error: %s does not exist" % SourceRoot
exit(1)
if not os.path.exists(DestRoot):
print "Creating destination directory %s" % DestRoot
os.makedirs(DestRoot)
DestHeaders = os.path.join(DestRoot, BoostHeaders)
DestLibs = os.path.join(DestRoot, BoostLibs)
os.makedirs(DestHeaders)
os.makedirs(DestLibs)
## Step 1
for f in os.listdir(SourceRoot):
CopyFile(SourceRoot, DestRoot, f)
## Step 2
for d in BoostSpecialFolders:
CopyDir(SourceRoot, DestRoot, d)
## Step 3
SourceLibs = os.path.join(SourceRoot, BoostLibs)
for f in os.listdir(SourceLibs):
CopyFile(SourceLibs, DestLibs, f)
## Step 4
BoostSubProjects = set()
for f in os.listdir(SourceLibs):
if os.path.isdir(os.path.join(SourceLibs,f)):
if os.path.isfile(os.path.join(SourceLibs,f,"meta","libraries.json")):
BoostSubProjects.add(f)
elif os.path.isdir(os.path.join(SourceLibs,f,"include")):
BoostSubProjects.add(f)
elif os.path.isfile(os.path.join(SourceLibs,f,"sublibs")):
for s in os.listdir(os.path.join(SourceLibs,f)):
if os.path.isdir(os.path.join(SourceLibs,f,s)):
if os.path.isfile(os.path.join(SourceLibs,f,s,"meta","libraries.json")):
BoostSubProjects.add((f,s))
elif os.path.isdir(os.path.join(SourceLibs,f,s,"include")):
BoostSubProjects.add((f,s))
for p in BoostSubProjects:
if isinstance(p, basestring):
CopySubProject(SourceLibs, DestLibs, DestHeaders, p)
else:
NestedSource = os.path.join(SourceRoot,"libs",p[0])
NestedDest = os.path.join(DestRoot,"libs",p[0])
NestedHeaders = os.path.join(DestRoot,"boost")
if not os.path.exists(NestedDest):
os.makedirs(NestedDest)
if not os.path.exists(NestedHeaders):
os.makedirs(NestedHeaders)
for f in os.listdir(NestedSource):
CopyFile(NestedSource, NestedDest, f)
CopyNestedProject(NestedSource, NestedDest, NestedHeaders, p)