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