1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
7 # Copyright (c) 2015 Google Inc.
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:
17 # The above copyright notice(s) and this permission notice shall be
18 # included in all copies or substantial portions of the Materials.
20 # THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 # MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
28 #-------------------------------------------------------------------------
38 sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "scripts"))
40 from build.common import *
41 from build.config import *
42 from build.build import *
45 def __init__ (self, name, dirName, binName):
47 self.dirName = dirName
48 self.binName = binName
50 VULKAN_MODULE = Module("dEQP-VK", "../external/vulkancts/modules/vulkan", "deqp-vk")
51 DEFAULT_BUILD_DIR = os.path.join(tempfile.gettempdir(), "spirv-binaries", "{targetName}-{buildType}")
52 DEFAULT_TARGET = "null"
53 DEFAULT_DST_DIR = os.path.join(DEQP_DIR, "external", "vulkancts", "data", "vulkan", "prebuilt")
55 def getBuildConfig (buildPathPtrn, targetName, buildType):
56 buildPath = buildPathPtrn.format(
57 targetName = targetName,
58 buildType = buildType)
60 return BuildConfig(buildPath, buildType, ["-DDEQP_TARGET=%s" % targetName])
62 def cleanDstDir (dstPath):
63 binFiles = [f for f in os.listdir(dstPath) if os.path.isfile(os.path.join(dstPath, f)) and fnmatch.fnmatch(f, "*.spirv")]
65 for binFile in binFiles:
66 print "Removing %s" % os.path.join(dstPath, binFile)
67 os.remove(os.path.join(dstPath, binFile))
69 def execBuildPrograms (buildCfg, generator, module, mode, dstPath):
70 workDir = os.path.join(buildCfg.getBuildDir(), "modules", module.dirName)
72 pushWorkingDir(workDir)
75 binPath = generator.getBinaryPath(buildCfg.getBuildType(), os.path.join(".", "vk-build-programs"))
76 execute([binPath, "--mode", mode, "--dst-path", dstPath])
81 parser = argparse.ArgumentParser(description = "Build SPIR-V programs",
82 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
83 parser.add_argument("-b",
86 default=DEFAULT_BUILD_DIR,
87 help="Temporary build directory")
88 parser.add_argument("-t",
93 parser.add_argument("-c",
96 default=DEFAULT_TARGET,
97 help="dEQP build target")
98 parser.add_argument("--mode",
101 help="Build mode (build or verify)")
102 parser.add_argument("-d",
105 default=DEFAULT_DST_DIR,
106 help="Destination path")
107 return parser.parse_args()
109 if __name__ == "__main__":
112 generator = ANY_GENERATOR
113 buildCfg = getBuildConfig(args.buildDir, args.targetName, args.buildType)
114 module = VULKAN_MODULE
116 build(buildCfg, generator, ["vk-build-programs"])
118 if args.mode == "build":
119 if os.path.exists(args.dstPath):
120 cleanDstDir(args.dstPath)
122 os.makedirs(args.dstPath)
124 execBuildPrograms(buildCfg, generator, module, args.mode, args.dstPath)