File: makeVCXProjPython3.py

package info (click to toggle)
tulip 4.6.0dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 139,284 kB
  • ctags: 35,942
  • sloc: cpp: 289,758; ansic: 27,264; python: 1,256; sh: 923; yacc: 522; xml: 337; makefile: 258; php: 66; lex: 55
file content (244 lines) | stat: -rw-r--r-- 7,830 bytes parent folder | download
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
#!/usr/bin/env python
# Make VCXProj
#
# May 2010
# Markus Chimani, markus.chimani@cs.tu-dortmund.de
# Carsten Gutwenger, carsten.gutwenger@cs.tu-dortmund.de
#########################################################


import os, sys, fnmatch, configparser

class stuff:
	def __init__(self, ttag, tpath, tpats, tcommand, tfilter):
		self.tag, self.path, self.pats, self.command, self.filter = ttag, tpath, tpats, tcommand, tfilter

def bailout(msg):
	print(msg)
	print('Please use the original makeVCXProj.config as a template')
	sys.exit()
	
def loadConfig(sect, key, noError = False ):
	if config.has_option(sect, key):
		v = config.get(sect, key)
		print(('   [', sect, ']', key, '=', v))
		return v
	else:
		if noError:
			return None		
		else:
			bailout('Option "' + key + '" in section "' + sect + '" is missing')

#########################################################
# LOAD CONFIGURATION

config = configparser.ConfigParser()

makecfg = 'makeVCXProj.config'
for x in sys.argv[1:]:
    if x[:7] == "config=":
        makecfg = x[7:]

print(('Loading ' + makecfg + '...'))

try:
	config.readfp( open(makecfg))
except IOError:
	bailout(makecfg + ' not found')

if not config.has_section('GENERAL'):
	bailout('Section "GENERAL" is missing')
if not config.has_section('COIN'):
	bailout('Section "COIN" is missing')

#########################################################
# CONFIGS

# Filenames
filename_vcxproj =  loadConfig('GENERAL', 'projectFile')
filename_template = loadConfig('GENERAL', 'templateFile')
filename_vcxfilters =  loadConfig('GENERAL', 'projectFiltersFile')
filename_template_filters = loadConfig('GENERAL', 'templateFiltersFile')
addIncludes = ''
addDefines = ''
addLibs = ''
addLibPathsDebugWin32 = ''
addLibPathsReleaseWin32 = ''
addLibPathsDebugX64 = ''
addLibPathsReleaseX64 = ''

useOwnLpSolver = loadConfig('GENERAL', 'useOwnLpSolver', 'false').startswith('t')
if useOwnLpSolver:
	addDefines += 'OGDF_OWN_LPSOLVER;'
	
useCoin = loadConfig('COIN', 'useCoin').startswith('t')
if useCoin:
	coinIncl = loadConfig('COIN', 'coinIncl')
	coinLib = loadConfig('COIN', 'coinLib')
	solver_name = loadConfig('COIN', 'solver_name')
	solver_incl = loadConfig('COIN', 'solver_incl')

	addDefines += 'USE_COIN;'+solver_name+';'
	addIncludes += coinIncl+';'
	if solver_incl.strip() != '':
		addIncludes += solver_incl+';'
	addLibs += 'libCoinUtils.lib libOsi.lib '
	addLibs += 'libClp.lib libOsiClp.lib '
	addLibPathsDebugWin32 += coinLib+'/win32/Debug;'
	addLibPathsReleaseWin32 += coinLib+'/win32/Release;'
	addLibPathsDebugX64 += coinLib+'/x64/Debug;'
	addLibPathsReleaseX64 += coinLib+'/x64/Release;'

addDefines = addDefines[:-1]
addIncludes = addIncludes[:-1]
addLibs = addLibs[:-1]
addLibPathsDebugWin32 = addLibPathsDebugWin32[:-1]
addLibPathsReleaseWin32 = addLibPathsReleaseWin32[:-1]
addLibPathsDebugX64 = addLibPathsDebugX64[:-1]
addLibPathsReleaseX64 = addLibPathsReleaseX64[:-1]
defineTag = '<<DEFINETAG>>'
includeTag = '<<INCLUDETAG>>'
libTag = '<<LIBTAG>>'
libPathsTagDebugWin32 = '<<LIBPATHSDEBUGWIN32TAG>>'
libPathsTagReleaseWin32 = '<<LIBPATHSRELEASEWIN32TAG>>'
libPathsTagDebugX64 = '<<LIBPATHSDEBUGX64TAG>>'
libPathsTagReleaseX64 = '<<LIBPATHSRELEASEX64TAG>>'
filtersTag = '<<FTAG>>'

# Params are: 
# - Tag in template-File
# - Directory to start search & subfilters from
# - File Patterns
cppStuff = stuff( '<<CPPTAG>>', 'src', [ '*.c', '*.cpp' ], 'ClCompile', 'Source Files' )
hStuff = stuff( '<<HTAG>>', 'ogdf', [ '*.h' ], 'ClInclude', 'Header Files' )
hLegacyStuff = stuff( '<<HLEGACYTAG>>', 'ogdf_legacy', [ '*.h' ], 'ClInclude', 'Header Files Legacy' )

includeStuff = stuff

stuff = [ cppStuff, hStuff, hLegacyStuff ]


#########################################################
#########################################################
## only code below...

# just the def. nothing happens yet
def Walk( curdir, pats, command ):
	names = os.listdir( curdir)
	names.sort()
	
	for name in names:
		if name.startswith('.') or name.startswith('_') or (name=='legacy' and not includeLegacyCode):
			continue

		outpath = curdir + '\\' + name
		fullname = os.path.normpath(outpath)
		
		if os.path.isdir(fullname) and not os.path.islink(fullname):
			Walk( outpath, pats, command)
		else:
			for pat in pats:
				if fnmatch.fnmatch(name, pat):
					vcxproj.write('    <' + command + ' Include="' + outpath + '" />\n')

def WalkFilterFiles( curdir, pats, command, filter ):
	names = os.listdir( curdir)
	names.sort()
	
	for name in names:
		if name.startswith('.') or name.startswith('_') or (name=='legacy' and not includeLegacyCode):
			continue

		outpath = curdir + '\\' + name
		fullname = os.path.normpath(outpath)
		
		if os.path.isdir(fullname) and not os.path.islink(fullname):
			WalkFilterFiles( outpath, pats, command, filter + '\\' + name )
		else:
			for pat in pats:
				if fnmatch.fnmatch(name, pat):
					vcxfilters.write('    <' + command + ' Include="' + outpath + '">\n')
					vcxfilters.write('      <Filter>' + filter + '</Filter>\n')
					vcxfilters.write('    </' + command + '>\n')

def WalkFilters( curdir, filter ):
	names = os.listdir( curdir)
	names.sort()
	
	for name in names:
		if name.startswith('.') or name.startswith('_') or (name=='legacy' and not includeLegacyCode):
			continue

		outpath = curdir + '\\' + name
		fullname = os.path.normpath(outpath)
		
		if os.path.isdir(fullname) and not os.path.islink(fullname):
			filtername = filter + '\\' + name
			vcxfilters.write('    <Filter Include="' + filtername + '">\n')
			vcxfilters.write('    </Filter>\n')
			WalkFilters( outpath, filtername )


##########################################
## Main below...

print('Generating VCXProj...')

includeLegacyCode = 0;
if len(sys.argv)>1 and sys.argv[1]=='legacy':
	includeLegacyCode = 1
	print('(including legacy code)')

vcxproj = open(filename_vcxproj,'w')
template = open(filename_template)

check = 0
for line in template:
	if check < len(stuff) and line.find(stuff[check].tag) > -1:
		if (stuff[check].tag!='<<HLEGACYTAG>>' or includeLegacyCode):
			Walk(stuff[check].path, stuff[check].pats, stuff[check].command)
		check = check + 1
	elif line.find(defineTag) > -1:
		vcxproj.write(line.replace(defineTag,addDefines,1))
	elif line.find(includeTag) > -1:
		vcxproj.write(line.replace(includeTag,addIncludes,1))
	elif line.find(libTag) > -1:
		vcxproj.write(line.replace(libTag,addLibs,1))
	elif line.find(libPathsTagDebugWin32) > -1:
		vcxproj.write(line.replace(libPathsTagDebugWin32,addLibPathsDebugWin32,1))
	elif line.find(libPathsTagReleaseWin32) > -1:
		vcxproj.write(line.replace(libPathsTagReleaseWin32,addLibPathsReleaseWin32,1))
	elif line.find(libPathsTagDebugX64) > -1:
		vcxproj.write(line.replace(libPathsTagDebugX64,addLibPathsDebugX64,1))
	elif line.find(libPathsTagReleaseX64) > -1:
		vcxproj.write(line.replace(libPathsTagReleaseX64,addLibPathsReleaseX64,1))
	else:
		vcxproj.write(line)

template.close()
vcxproj.close()

# Creation of filters file...

vcxfilters = open(filename_vcxfilters,'w')
template_filters = open(filename_template_filters)

check = 0
for line in template_filters:
	if check < len(stuff) and line.find(stuff[check].tag) > -1:
		if (stuff[check].tag!='<<HLEGACYTAG>>' or includeLegacyCode):
			WalkFilterFiles(stuff[check].path, stuff[check].pats, stuff[check].command, stuff[check].filter)
		check = check + 1
	elif line.find(filtersTag) > -1:
		for s in stuff:
			if (s.tag!='<<HLEGACYTAG>>' or includeLegacyCode):
				WalkFilters(s.path, s.filter)
	else:
		vcxfilters.write(line)


template_filters.close()
vcxfilters.close()

		 
print('VCXProj generated')