Hash :
904a4797
Author :
Date :
2022-02-15T10:58:07
Python3 upgrades Required to run run_code_generation.py on gLinux. Bug: angleproject:5707 Change-Id: Ifb416be6f89eb67faf43e7de66c6f9a92a5eb5e1 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3465514 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Cody Northrop <cnorthrop@google.com>
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
#!/usr/bin/python3
# Copyright 2019 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Code generation for:
# - src/tests/deqp_support/BUILD.gn
# - src/tests/deqp_data.gni
# NOTE: don't run this script directly. Run scripts/run_code_generation.py.
import errno
import os
import sys
import shutil
def initDataDirectories(dataDirectories):
dataDirectories.append(os.path.join("data", "gles2"))
dataDirectories.append(os.path.join("data", "gles3"))
dataDirectories.append(os.path.join("data", "gles31"))
dataDirectories.append(os.path.join("external", "graphicsfuzz", "data", "gles3"))
dataDirectories.append(os.path.join("external", "openglcts", "data", "gles3"))
def initPathReplacements(pathReplacements):
# The GraphicsFuzz data files need the 'external/graphicsfuzz/' prefix removed
pathToReplace = os.path.join("external", "graphicsfuzz", "") # Include trailing slash
pathReplacements[pathToReplace] = ""
# The KHR dEQP tests expect a root prefix of "gl_cts" for some reason.
pathToReplace = os.path.join("external", "openglcts", "") # Include trailing slash
pathReplacements[pathToReplace] = os.path.join("data", "gl_cts", "")
def createBuildGnFile(buildGnPath):
# Cleanup the old file
if os.path.exists(buildGnPath):
os.remove(buildGnPath)
# Make the new one
return open(buildGnPath, "w+")
def createGniFile(gniFilename):
# Cleanup the old file
if os.path.exists(gniFilename):
os.remove(gniFilename)
# Make the new one
return open(gniFilename, "w+")
def writeFileHeader(fileIn):
templateFileHeader = """# GENERATED FILE - DO NOT EDIT.
# Generated by: {script_name}
#
# Copyright 2019 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
fileHeader = templateFileHeader.format(script_name=os.path.basename(__file__))
fileIn.write(fileHeader)
def fixDestinationDirectory(pathReplacements, relativeDirectory):
for pathReplacement in pathReplacements:
if pathReplacement in relativeDirectory:
return relativeDirectory.replace(pathReplacement, pathReplacements[pathReplacement])
return relativeDirectory
def convertPathToVarName(path):
return path.replace(os.sep, "_")
def getCMakeLists(deqpSrcDir):
cmakeLists = []
for root, directories, filenames in os.walk(deqpSrcDir):
for filename in filenames:
relativeDirectory = os.path.relpath(root, deqpSrcDir)
if filename == "CMakeLists.txt":
cmakeLists.append(os.path.join(relativeDirectory, filename))
return cmakeLists
def main():
# List of directories containing data files
dataDirectories = []
# List of directories to exclude from the copy
excludedDirectories = [
".git",
]
# List of files to exclude from the copy
excludedFilenames = [
"LICENSE",
]
# Dictionary of parts of paths that need to be replaced
# Key: Part of path to be replaced
# Value: What to replace it with
pathReplacements = {}
# List of unique relative directories for the copy() command outputs
relativeDirectories = []
# VK-GL-CTS source directory
deqpSourceDirectory = os.path.join("..", "third_party", "VK-GL-CTS", "src")
# Tests Directory
testsDirectory = os.path.join("..", "src", "tests")
# dEQP Support Directory
deqpSupportDirectory = "deqp_support"
# BUILD.gn file to write to
buildGnFilename = "BUILD.gn"
# Path to BUILD.gn
buildGnPath = os.path.join(testsDirectory, deqpSupportDirectory, buildGnFilename)
# dEQP data GNI File to write to
dataGniFilename = os.path.join(testsDirectory, deqpSupportDirectory, "deqp_data_autogen.gni")
# run_code_generation.py parameters.
if len(sys.argv) > 1:
# All CMakeLists.txt in the dEQP source tree (at the time)
cmakeDirs = getCMakeLists(deqpSourceDirectory)
inputs = [os.path.join(deqpSourceDirectory, "%s" % dir) for dir in cmakeDirs]
outputs = [dataGniFilename, buildGnPath]
if sys.argv[1] == 'inputs':
print(','.join(inputs))
elif sys.argv[1] == 'outputs':
print(','.join(outputs))
else:
print('Invalid script parameters')
return 1
return 0
deqpSrcDir = os.path.abspath(os.path.join(sys.path[0], deqpSourceDirectory))
initDataDirectories(dataDirectories)
initPathReplacements(pathReplacements)
dataFiles = []
for dataDir in dataDirectories:
dataPath = os.path.join(deqpSrcDir, dataDir)
for root, directories, filenames in os.walk(dataPath):
for filename in filenames:
relativeDirectory = os.path.relpath(root, deqpSrcDir)
# Skip any excluded directories
if any(directory in relativeDirectory for directory in excludedDirectories):
continue
# Skip any excluded files
if any(excludedFilename in filename for excludedFilename in excludedFilenames):
continue
# Record the relative directories and full paths to each data file
if relativeDirectory not in relativeDirectories:
relativeDirectories.append(relativeDirectory)
dataFiles.append(os.path.join(relativeDirectory, filename))
dataFiles.sort()
relativeDirectories.sort(key=convertPathToVarName)
#
# BUILD.gn
#
buildGnFile = createBuildGnFile(buildGnPath)
writeFileHeader(buildGnFile)
# Definitions
buildGnFile.write("deqp_path = \"../../../third_party/VK-GL-CTS/src\"\n")
# Create the copy() commands
templateFilesToCopy = """ "$deqp_path/{dataFile}",
"""
templateCopyCommand = """
copy("vk_gl_cts_data_{relDir}") {{
sources = [
{filesToCopy}
]
outputs = [ "$root_gen_dir/vk_gl_cts_data/{destDir}/{{{{source_file_part}}}}" ]
}}
"""
for relativeDirectory in relativeDirectories:
filesToCopy = ""
for dataFile in dataFiles:
path, filename = os.path.split(dataFile)
if relativeDirectory == path:
filesToCopy += templateFilesToCopy.format(dataFile=dataFile.replace(os.sep, '/'))
copyCommand = ""
destDir = fixDestinationDirectory(pathReplacements, relativeDirectory)
copyCommand += templateCopyCommand.format(
relDir=convertPathToVarName(relativeDirectory),
filesToCopy=filesToCopy,
destDir=destDir.replace(os.sep, '/'))
buildGnFile.write(copyCommand)
#
# .gni
#
gniFile = createGniFile(dataGniFilename)
writeFileHeader(gniFile)
# Imports
templateImports = """import("deqp.gni")
"""
gniFile.write(templateImports)
# Write the lists of data file dependencies
templateDataFiles = """ "$root_gen_dir/vk_gl_cts_data/{dataFile}",
"""
templateDataFileDeps = """
{dataDepName} = [
{files}]
"""
for dataDirectory in dataDirectories:
files = ""
for dataFile in dataFiles:
if dataDirectory + os.sep in dataFile:
files += templateDataFiles.format(
dataFile=fixDestinationDirectory(pathReplacements, dataFile).replace(
os.sep, '/'))
dataDepName = "angle_deqp_" + convertPathToVarName(dataDirectory)
fileDeps = templateDataFileDeps.format(dataDepName=dataDepName, files=files)
gniFile.write(fileDeps)
templateCopyTarget = """ "{deqpSupportDirectory}:vk_gl_cts_data_{relDir}",
"""
templateCopyTargets = """
angle_deqp_data_copy_targets = [
{targets}]
"""
targets = ""
for relativeDirectory in relativeDirectories:
targets += templateCopyTarget.format(
deqpSupportDirectory=deqpSupportDirectory,
relDir=convertPathToVarName(relativeDirectory))
gniFile.write(templateCopyTargets.format(targets=targets))
if __name__ == '__main__':
sys.exit(main())