layers: Make DescriptorSetLayout robust for CTS
[platform/upstream/Vulkan-LoaderAndValidationLayers.git] / scripts / source_line_info.py
1 #!/usr/bin/env python3
2 #
3 # Copyright (c) 2015-2016 The Khronos Group Inc.
4 # Copyright (c) 2015-2016 Valve Corporation
5 # Copyright (c) 2015-2016 LunarG, Inc.
6 # Copyright (c) 2015-2016 Google Inc.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #     http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20 # Author: Tobin Ehlis <tobin@lunarg.com>
21
22 from inspect import currentframe, getframeinfo
23
24 # This is a wrapper class for inspect module that returns a formatted line
25 #  with details of the source file and line number of python code who called
26 #  into this class. The result can them be added to codegen to simplify
27 #  debug as it shows where code was generated from.
28 class sourcelineinfo():
29     def __init__(self):
30         self.general_prefix = "// CODEGEN : "
31         self.file_prefix = "file "
32         self.line_prefix = "line #"
33         self.enabled = True
34
35     def get(self):
36         if self.enabled:
37             frameinfo = getframeinfo(currentframe().f_back)
38             return "%s%s%s %s%s" % (self.general_prefix, self.file_prefix, frameinfo.filename, self.line_prefix, frameinfo.lineno)
39         return ""