File: filelist.py

package info (click to toggle)
spring 0.81.2.1%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 28,496 kB
  • ctags: 37,096
  • sloc: cpp: 238,659; ansic: 13,784; java: 12,175; awk: 3,428; python: 1,159; xml: 738; perl: 405; sh: 297; makefile: 267; pascal: 228; objc: 192
file content (245 lines) | stat: -rw-r--r-- 7,946 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
245
# Copyright (C) 2006  Tobi Vollebregt

import os, re

###############################################
### functions to make lists of source files ###
###############################################
import sys
sourceRootDir = ''
def setSourceRootDir(absPath):
	global sourceRootDir
	print("source root-dir: " + absPath)
	sourceRootDir = absPath
def getAbsDir(env, relPath):
	# This worked up to SCons 0.98
	#return SCons.Script.Dir(interfaceGeneratedJavaSrcDir).abspath
	path = relPath
	if (len(relPath) > 0 and relPath[0:1] == '#'):
		# replace '#' with source root
		#path = os.path.join(sourceRootDir, relPath.replace('#', ''))
		path = os.path.join(sourceRootDir, relPath[1:])
	return os.path.abspath(path)

def fix_path(path):
	pieces = path.split('/')
	newpath = None
	for p in pieces:
		if newpath:
			newpath = os.path.join(newpath, p)
		else:
			newpath = p
	return newpath


def list_directories(env, path, exclude_list = (), exclude_regexp = '^\.', recursively = True):
	path_stack = [path]
	#walk through dir tree
	exclude = re.compile(exclude_regexp)
	dirs = []
	while len(path_stack) > 0:
		path = path_stack.pop()
		files = os.listdir(path)
		for f in files:
			g = os.path.join(path, f)
			if os.path.exists(g) and not f in exclude_list and not exclude.search(f):
				if os.path.isdir(g):
					dirs += [g]
					if recursively:
						path_stack += [g]
	return dirs


def list_files_recursive(env, path, exclude_list = (), exclude_regexp = '^\.', exclude_dirs = False, path_relative = False, include_regexp = ''):
	rel_path_stack = ['']
	exclude = re.compile(exclude_regexp)
	include = re.compile(include_regexp)
	ffiles = []
	while len(rel_path_stack) > 0:
		rpath = rel_path_stack.pop()
		apath = os.path.join(path, rpath)
		files = os.listdir(apath)
		for f in files:
			rf = os.path.join(rpath, f)
			af = os.path.join(apath, f)
			if path_relative:
				wf = rf
			else:
				wf = af
			if os.path.exists(af) and not f in exclude_list and not exclude.search(f):
				if not (os.path.isdir(af) and exclude_dirs) and include.search(f):
					ffiles += [wf]
				if os.path.isdir(af):
					rel_path_stack += [rf]
	return ffiles


def get_source(env, path, exclude_list = (), exclude_regexp = '^\.', ignore_builddir = False):
	basepath = path
	path_stack = [path]
	#what does a source file look like?
	source = re.compile('\.cpp$|\.c$')
	#walk through dir tree
	exclude = re.compile(exclude_regexp)
	source_files = []
	while len(path_stack) > 0:
		path = path_stack.pop()
		files = os.listdir(path)
		for f in files:
			g = os.path.join(path, f)
			if os.path.exists(g) and not g in exclude_list and not exclude.search(f):
				if source.search(f)  and os.path.isfile(g):
					source_files += [g]
				# Exclude 'Test' too so one can dump unit testing code in 'Test' subdirectories
				# (Couldn't really use regexp for it since it'd exclude files like TestScript.cpp too)
				elif os.path.isdir(g) and f.lower() != 'test':
					path_stack += [g]
	if not ignore_builddir and env.has_key('builddir') and env['builddir']:
		source_files_2 = []
		for f in source_files:
			source_files_2.append([os.path.join(env['builddir'], f)])
		return source_files_2
	else:
		return source_files


def get_spring_source(env):
	exclude1 = [
		'rts/build',
		'rts/lib/crashrpt', # unused
		'rts/lib/libhpi',
		'rts/lib/streflop', # compiled separately, as a static lib
		'rts/lib/oscpack',  # compiled separately, as a static lib
		'rts/System/Platform/BackgroundReader.cpp',
		'rts/System/Platform/Mac', # Mac build uses XCode
		'rts/System/FileSystem/DataDirLocater.cpp', # see SConstruct
	]
	# we may be called before we were configured (e.g. when cleaning)
	if env.has_key('platform'):
		if env['platform'] == 'windows':
			exclude1 += [
				'rts/System/Platform/Linux',
				'rts/Rendering/GL/GLXPBuffer.cpp']
				#'rts/System/Platform/Win/DxSound.cpp']
		else:
			exclude1 += [
				'rts/Rendering/GL/WinPBuffer.cpp', # why not in `System/Win/'?
				'rts/lib/minizip/iowin32.c',
				'rts/System/Platform/Win',
				'rts/System/wavread.cpp']
		if env['disable_avi']: exclude1 += ['rts/System/Platform/Win/AVIGenerator.cpp']

	# for Windows we must add the backslash equivalents
	exclude = []
	for f in exclude1:
		exclude += [f]
		exclude += [f.replace('/','\\')]

	source = get_source(env, 'rts', exclude_list = exclude)
	return source



################################################################################
### AI
################################################################################

# lists source files common for all AI Interfaces and Skirmish AIs
def get_shared_AI_source(env):
	result = []
	if env.has_key('builddir') and env['builddir']:
		result += [os.path.join(env['builddir'], 'rts/Game/GameVersion.cpp')]
	return result

# lists source files common for all AI Interfaces
def get_shared_AIInterface_sources(env):
	result = get_shared_AI_source(env)
	return result

# lists source files common for all Skirmish AIs
def get_shared_AILib_sources(env):
	result = get_shared_AI_source(env)
	return result

# list the LegacyCPP source files (used by some Skirmish AI libraries)
def get_shared_AILib_legacyCPP_sources(env):
	result = []

	if (env.has_key('builddir') and env['builddir']):
		result += [os.path.join(env['builddir'], 'rts/System/float3.cpp')]
		result += [os.path.join(env['builddir'], 'rts/Sim/Misc/DamageArray.cpp')]
		result += get_shared_wrapper_source(env, 'LegacyCpp', prefix = 'AI')

	return result

# list the C and C++ source files of a Wrapper
def get_shared_wrapper_source(env, wrapperDir, prefix = ''):
	result = []

	if (env.has_key('builddir') and env['builddir']):
		fullWrapperDir = os.path.join('Wrappers', wrapperDir)
		files = list_files_recursive(env, fullWrapperDir, exclude_dirs = True, path_relative = True, include_regexp="\.(c|cpp)$")
		for f in files:
			result += [os.path.join(env['builddir'], prefix, fullWrapperDir, f)]
			#result += [os.path.join(env['builddir'], 'Wrappers/LegacyCpp/AI.cpp')]

	return result

# list the creg source files (used by some native SkirmishAI libraries)
def get_shared_AILib_creg_sources(env):
	result = []
	cwdPrev = os.getcwd()

	if (env.has_key('builddir') and env['builddir']):
		os.chdir('..')
		result += get_source(env, 'rts/System/creg', ignore_builddir=False)
		os.chdir(cwdPrev)

	return result

# list the sources of Spring's custom Lua lib (used by some native SkirmishAI libraries)
def get_shared_AILib_lua_sources(env):
	result = []
	cwdPrev = os.getcwd()

	if (env.has_key('builddir') and env['builddir']):
		os.chdir('..')
		result += get_source(env, "rts/lib/lua/src", ignore_builddir=False)
		os.chdir(cwdPrev)

	return result



# lists source directories for AI Interfaces or Skirmish AIs
def list_AIs(env, path, exclude_list = (), exclude_regexp = '^\.', include_interfaces = None):
	exclude = re.compile(exclude_regexp)
	files = os.listdir(path)
	result = []
	for f in files:
		g = os.path.join(path, f)
		if (path == 'Skirmish'):
			infoFile = os.path.join(g, 'data', 'AIInfo.lua')
		else:
			infoFile = os.path.join(g, 'data', 'InterfaceInfo.lua')
		if os.path.exists(g) and not f in exclude_list and not exclude.search(f):
			if os.path.isdir(g) and os.path.exists(infoFile):
				if include_interfaces == None:
					result += [f]
				else:
					# only list AIs whichs info lua file sais that it uses one of the include interfaces
					for i in include_interfaces:
						searchStr = "'" + i + "', -- AI Interface name"
						if (searchStr in open(infoFile).read()):
							result += [f]
							break;
	return result

# lists source directories for AI Interfaces
def list_AIInterfaces(env, exclude_list = (), exclude_regexp = '^\.'):
	return list_AIs(env, 'Interfaces', exclude_list, exclude_regexp)

# lists source directories for Skirmish AIs
def list_skirmishAIs(env, exclude_list = (), exclude_regexp = '^\.', include_interfaces = None):
	return list_AIs(env, 'Skirmish', exclude_list, exclude_regexp, include_interfaces)