Merge "Do not normalize binary path in xs::PosixTestProcess"
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / build_spirv_binaries.py
1 # -*- coding: utf-8 -*-
2
3 #-------------------------------------------------------------------------
4 # Vulkan CTS
5 # ----------
6 #
7 # Copyright (c) 2015 Google Inc.
8 #
9 # Permission is hereby granted, free of charge, to any person obtaining a
10 # copy of this software and/or associated documentation files (the
11 # "Materials"), to deal in the Materials without restriction, including
12 # without limitation the rights to use, copy, modify, merge, publish,
13 # distribute, sublicense, and/or sell copies of the Materials, and to
14 # permit persons to whom the Materials are furnished to do so, subject to
15 # the following conditions:
16 #
17 # The above copyright notice(s) and this permission notice shall be
18 # included in all copies or substantial portions of the Materials.
19 #
20 # The Materials are Confidential Information as defined by the
21 # Khronos Membership Agreement until designated non-confidential by
22 # Khronos, at which point this condition clause shall be removed.
23 #
24 # THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30 # MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
31 #
32 #-------------------------------------------------------------------------
33
34 import os
35 import sys
36 import string
37 import argparse
38 import tempfile
39 import shutil
40 import fnmatch
41
42 sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "scripts"))
43
44 from build.common import *
45 from build.config import *
46 from build.build import *
47
48 class Module:
49         def __init__ (self, name, dirName, binName):
50                 self.name               = name
51                 self.dirName    = dirName
52                 self.binName    = binName
53
54 VULKAN_MODULE           = Module("dEQP-VK", "../external/vulkancts/modules/vulkan", "deqp-vk")
55 DEFAULT_BUILD_DIR       = os.path.join(tempfile.gettempdir(), "spirv-binaries", "{targetName}-{buildType}")
56 DEFAULT_TARGET          = "null"
57 DEFAULT_DST_DIR         = os.path.join(DEQP_DIR, "external", "vulkancts", "data", "vulkan", "prebuilt")
58
59 def getBuildConfig (buildPathPtrn, targetName, buildType):
60         buildPath = buildPathPtrn.format(
61                 targetName      = targetName,
62                 buildType       = buildType)
63
64         return BuildConfig(buildPath, buildType, ["-DDEQP_TARGET=%s" % targetName])
65
66 def cleanDstDir (dstPath):
67         binFiles = [f for f in os.listdir(dstPath) if os.path.isfile(os.path.join(dstPath, f)) and fnmatch.fnmatch(f, "*.spirv")]
68
69         for binFile in binFiles:
70                 print "Removing %s" % os.path.join(dstPath, binFile)
71                 os.remove(os.path.join(dstPath, binFile))
72
73 def execBuildPrograms (buildCfg, generator, module, mode, dstPath):
74         workDir = os.path.join(buildCfg.getBuildDir(), "modules", module.dirName)
75
76         pushWorkingDir(workDir)
77
78         try:
79                 binPath = generator.getBinaryPath(buildCfg.getBuildType(), os.path.join(".", "vk-build-programs"))
80                 execute([binPath, "--mode", mode, "--dst-path", dstPath])
81         finally:
82                 popWorkingDir()
83
84 def parseArgs ():
85         parser = argparse.ArgumentParser(description = "Build SPIR-V programs",
86                                                                          formatter_class=argparse.ArgumentDefaultsHelpFormatter)
87         parser.add_argument("-b",
88                                                 "--build-dir",
89                                                 dest="buildDir",
90                                                 default=DEFAULT_BUILD_DIR,
91                                                 help="Temporary build directory")
92         parser.add_argument("-t",
93                                                 "--build-type",
94                                                 dest="buildType",
95                                                 default="Debug",
96                                                 help="Build type")
97         parser.add_argument("-c",
98                                                 "--deqp-target",
99                                                 dest="targetName",
100                                                 default=DEFAULT_TARGET,
101                                                 help="dEQP build target")
102         parser.add_argument("--mode",
103                                                 dest="mode",
104                                                 default="build",
105                                                 help="Build mode (build or verify)")
106         parser.add_argument("-d",
107                                                 "--dst-path",
108                                                 dest="dstPath",
109                                                 default=DEFAULT_DST_DIR,
110                                                 help="Destination path")
111         return parser.parse_args()
112
113 if __name__ == "__main__":
114         args = parseArgs()
115
116         generator       = ANY_GENERATOR
117         buildCfg        = getBuildConfig(args.buildDir, args.targetName, args.buildType)
118         module          = VULKAN_MODULE
119
120         build(buildCfg, generator, ["vk-build-programs"])
121
122         if args.mode == "build":
123                 if os.path.exists(args.dstPath):
124                         cleanDstDir(args.dstPath)
125                 else:
126                         os.makedirs(args.dstPath)
127
128         execBuildPrograms(buildCfg, generator, module, args.mode, args.dstPath)