xref: /aosp_15_r20/external/deqp/scripts/gen_android_bp.py (revision 35238bce31c2a825756842865a792f8cf7f89930)
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 ctsbuild.common import DEQP_DIR, writeFile, which, execute
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    "external/vulkancts/modules/vulkan/vktTestPackageEntrySC.cpp",
59    "external/vulkancts/modules/vulkan/sc/*",
60    "external/vulkancts/vkscserver/*",
61    "external/vulkancts/vkscpc/*",
62    "external/vulkancts/framework/vulkan/generated/vulkansc/*",
63    "external/vulkancts/modules/vulkan/video/*",
64]
65
66# These are include folders where there are no source c/cpp files
67EXTRA_INCLUDE_DIRS = [
68    # This only has headers, so is not caught with INCLUDE_PATTERNS
69    "external/vulkancts/framework/vulkan/generated/vulkan",
70]
71
72TEMPLATE = """
73// WARNING: This is auto-generated file. Do not modify, since changes will
74// be lost! Modify scripts/gen_android_bp.py instead.
75
76cc_defaults {
77    name: "libdeqp_gen",
78
79    srcs: [
80{SRC_FILES}    ],
81    local_include_dirs: [
82{INCLUDES}    ],
83}
84
85"""[1:-1]
86
87def matchesAny (filename, patterns):
88    for ptrn in patterns:
89        if fnmatch(filename, ptrn):
90            return True
91    return False
92
93def isSourceFile (filename):
94    return matchesAny(filename, INCLUDE_PATTERNS) and not matchesAny(filename, EXCLUDE_PATTERNS)
95
96def toPortablePath (nativePath):
97    # os.path is so convenient...
98    head, tail = os.path.split(nativePath)
99    components = [tail]
100
101    while head != None and head != '':
102        head, tail = os.path.split(head)
103        components.append(tail)
104
105    components.reverse()
106
107    portablePath = ""
108    for component in components:
109        portablePath = posixpath.join(portablePath, component)
110
111    return portablePath
112
113def getSourceFiles ():
114    sources = []
115
116    for srcRoot in SRC_ROOTS:
117        baseDir = os.path.join(DEQP_DIR, srcRoot)
118        for root, dirs, files in os.walk(baseDir):
119            for file in files:
120                absPath = os.path.join(root, file)
121                nativeRelPath = os.path.relpath(absPath, DEQP_DIR)
122                portablePath = toPortablePath(nativeRelPath)
123
124                if isSourceFile(portablePath):
125                    sources.append(portablePath)
126
127    sources.sort()
128
129    return sources
130
131def getSourceDirs (sourceFiles):
132    seenDirs = set()
133    sourceDirs = []
134
135    for sourceFile in sourceFiles:
136        sourceDir = posixpath.dirname(sourceFile)
137
138        if not sourceDir in seenDirs:
139            sourceDirs.append(sourceDir)
140            seenDirs.add(sourceDir)
141
142    sourceDirs.extend(EXTRA_INCLUDE_DIRS)
143    sourceDirs.sort()
144
145    return sourceDirs
146
147def genBpStringList (items):
148    src = ""
149
150    for item in items:
151        src += "        \"%s\",\n" % item
152
153    return src
154
155def genAndroidBp (sourceDirs, sourceFiles):
156    src = TEMPLATE
157    src = src.replace("{INCLUDES}", genBpStringList(sourceDirs))
158    src = src.replace("{SRC_FILES}", genBpStringList(sourceFiles))
159
160    return src
161
162if __name__ == "__main__":
163    sourceFiles = getSourceFiles()
164    sourceDirs = getSourceDirs(sourceFiles)
165    androidBpText = genAndroidBp(sourceDirs, sourceFiles)
166
167    bpFilename = os.path.join(DEQP_DIR, "AndroidGen.bp")
168    writeFile(bpFilename, androidBpText)
169
170    # Format the generated file
171    if which("bpfmt") != None:
172        execute(["bpfmt", "-w", bpFilename])
173    else:
174        print("Warning: Could not find bpfmt, file won't be formatted.")
175