• 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	"framework/xexml",
42	"modules",
43]
44
45INCLUDE_PATTERNS = [
46	"*.cpp",
47	"*.c",
48]
49
50EXCLUDE_PATTERNS = [
51	"execserver/xsWin32TestProcess.cpp",
52	"external/vulkancts/modules/vulkan/vktBuildPrograms.cpp",
53	"framework/delibs/dethread/standalone_test.c",
54	"framework/randomshaders/rsgTest.cpp",
55	"executor/tools/*",
56	"execserver/tools/*",
57	"external/vulkancts/framework/vulkan/vkRenderDocUtil.cpp",
58]
59
60TEMPLATE = """
61// WARNING: This is auto-generated file. Do not modify, since changes will
62// be lost! Modify scripts/gen_android_bp.py instead.
63
64cc_defaults {
65    name: "libdeqp_gen",
66
67    srcs: [
68{SRC_FILES}    ],
69    local_include_dirs: [
70{INCLUDES}    ],
71}
72
73"""[1:-1]
74
75def matchesAny (filename, patterns):
76	for ptrn in patterns:
77		if fnmatch(filename, ptrn):
78			return True
79	return False
80
81def isSourceFile (filename):
82	return matchesAny(filename, INCLUDE_PATTERNS) and not matchesAny(filename, EXCLUDE_PATTERNS)
83
84def toPortablePath (nativePath):
85	# os.path is so convenient...
86	head, tail	= os.path.split(nativePath)
87	components	= [tail]
88
89	while head != None and head != '':
90		head, tail = os.path.split(head)
91		components.append(tail)
92
93	components.reverse()
94
95	portablePath = ""
96	for component in components:
97		portablePath = posixpath.join(portablePath, component)
98
99	return portablePath
100
101def getSourceFiles ():
102	sources = []
103
104	for srcRoot in SRC_ROOTS:
105		baseDir = os.path.join(DEQP_DIR, srcRoot)
106		for root, dirs, files in os.walk(baseDir):
107			for file in files:
108				absPath			= os.path.join(root, file)
109				nativeRelPath	= os.path.relpath(absPath, DEQP_DIR)
110				portablePath	= toPortablePath(nativeRelPath)
111
112				if isSourceFile(portablePath):
113					sources.append(portablePath)
114
115	sources.sort()
116
117	return sources
118
119def getSourceDirs (sourceFiles):
120	seenDirs	= set()
121	sourceDirs	= []
122
123	for sourceFile in sourceFiles:
124		sourceDir = posixpath.dirname(sourceFile)
125
126		if not sourceDir in seenDirs:
127			sourceDirs.append(sourceDir)
128			seenDirs.add(sourceDir)
129
130	return sourceDirs
131
132def genBpStringList (items):
133	src = ""
134
135	for item in items:
136		src += "       \"%s\",\n" % item
137
138	return src
139
140def genAndroidBp (sourceDirs, sourceFiles):
141	src = TEMPLATE
142	src = src.replace("{INCLUDES}", genBpStringList(sourceDirs))
143	src = src.replace("{SRC_FILES}", genBpStringList(sourceFiles))
144
145	return src
146
147if __name__ == "__main__":
148	sourceFiles		= getSourceFiles()
149	sourceDirs		= getSourceDirs(sourceFiles)
150	androidBpText	= genAndroidBp(sourceDirs, sourceFiles)
151
152	writeFile(os.path.join(DEQP_DIR, "AndroidGen.bp"), androidBpText)
153