• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------
4# drawElements Quality Program utilities
5# --------------------------------------
6#
7# Copyright 2017 The Android Open Source Project
8#
9# Licensed under the Apache License, Version 2.0 (the "License");
10# you may not use this file except in compliance with the License.
11# You may obtain a copy of the License at
12#
13#      http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS,
17# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18# See the License for the specific language governing permissions and
19# limitations under the License.
20#
21#-------------------------------------------------------------------------
22
23import os
24import posixpath
25from fnmatch import fnmatch
26
27from build.common import DEQP_DIR, writeFile
28
29SRC_ROOTS = [
30	"execserver",
31	"executor",
32	"external/vulkancts",
33	"framework/common",
34	"framework/delibs",
35	"framework/egl",
36	"framework/opengl",
37	"framework/platform/android",
38	"framework/qphelper",
39	"framework/randomshaders",
40	"framework/referencerenderer",
41	"modules",
42]
43
44INCLUDE_PATTERNS = [
45	"*.cpp",
46	"*.c",
47]
48
49EXCLUDE_PATTERNS = [
50	"execserver/xsWin32TestProcess.cpp",
51	"external/vulkancts/modules/vulkan/vktBuildPrograms.cpp",
52	"framework/delibs/dethread/standalone_test.c",
53	"framework/randomshaders/rsgTest.cpp",
54	"executor/tools/*",
55	"execserver/tools/*",
56	"external/vulkancts/framework/vulkan/vkRenderDocUtil.cpp",
57]
58
59TEMPLATE = """
60// WARNING: This is auto-generated file. Do not modify, since changes will
61// be lost! Modify scripts/gen_android_bp.py instead.
62
63cc_defaults {
64    name: "libdeqp_gen",
65
66    srcs: [
67{SRC_FILES}    ],
68    local_include_dirs: [
69{INCLUDES}    ],
70}
71
72"""[1:-1]
73
74def matchesAny (filename, patterns):
75	for ptrn in patterns:
76		if fnmatch(filename, ptrn):
77			return True
78	return False
79
80def isSourceFile (filename):
81	return matchesAny(filename, INCLUDE_PATTERNS) and not matchesAny(filename, EXCLUDE_PATTERNS)
82
83def toPortablePath (nativePath):
84	# os.path is so convenient...
85	head, tail	= os.path.split(nativePath)
86	components	= [tail]
87
88	while head != None and head != '':
89		head, tail = os.path.split(head)
90		components.append(tail)
91
92	components.reverse()
93
94	portablePath = ""
95	for component in components:
96		portablePath = posixpath.join(portablePath, component)
97
98	return portablePath
99
100def getSourceFiles ():
101	sources = []
102
103	for srcRoot in SRC_ROOTS:
104		baseDir = os.path.join(DEQP_DIR, srcRoot)
105		for root, dirs, files in os.walk(baseDir):
106			for file in files:
107				absPath			= os.path.join(root, file)
108				nativeRelPath	= os.path.relpath(absPath, DEQP_DIR)
109				portablePath	= toPortablePath(nativeRelPath)
110
111				if isSourceFile(portablePath):
112					sources.append(portablePath)
113
114	sources.sort()
115
116	return sources
117
118def getSourceDirs (sourceFiles):
119	seenDirs	= set()
120	sourceDirs	= []
121
122	for sourceFile in sourceFiles:
123		sourceDir = posixpath.dirname(sourceFile)
124
125		if not sourceDir in seenDirs:
126			sourceDirs.append(sourceDir)
127			seenDirs.add(sourceDir)
128
129	return sourceDirs
130
131def genBpStringList (items):
132	src = ""
133
134	for item in items:
135		src += "       \"%s\",\n" % item
136
137	return src
138
139def genAndroidBp (sourceDirs, sourceFiles):
140	src = TEMPLATE
141	src = src.replace("{INCLUDES}", genBpStringList(sourceDirs))
142	src = src.replace("{SRC_FILES}", genBpStringList(sourceFiles))
143
144	return src
145
146if __name__ == "__main__":
147	sourceFiles		= getSourceFiles()
148	sourceDirs		= getSourceDirs(sourceFiles)
149	androidBpText	= genAndroidBp(sourceDirs, sourceFiles)
150
151	writeFile(os.path.join(DEQP_DIR, "AndroidGen.bp"), androidBpText)
152