Vulkan-Docs/scripts/spec_tools/main.py

255 lines
9.2 KiB
Python
Raw Normal View History

Change log for February 3, 2019 Vulkan 1.1.99 spec update: * Update release number to 99. Public Issues: * Add missing pname:pMemoryHostPointerProperties description to flink:vkGetMemoryHostPointerPropertiesEXT.txt (public pull request 896). * Minor markup fixes (public pull request 900). * Minor update to `khronos.css` and markup fixes (originally proposed in public pull request 901, but done via an internal MR). Internal Issues: * Document restrictions on image queries for Y'CbCr formats in the <<features-formats-requiring-sampler-ycbcr-conversion>> table as well as for slink:sname:VkImageFormatProperties and slink:VkImageCreateInfo (internal issue 1361). * Correct type of the code:FragSizeEXT built-in in the <<interfaces-builtin-variables, Built-In Variables>> section (internal issue 1526). * Clean up math in the <<textures, Image Operations>> chapter by refactoring, using better naming conventions, updating diagrams to use the correct orientation, etc. (internal merge request 2968). * Fix minor typos for slink:VkImageCreateInfo and slink:VkImageStencilUsageCreateInfoEXT. * Add missing documentation for tlink:VkResolveModeFlagsKHR. * Fix extension dependency of pname:scalarBlockLayout in the <<features-features-requirements, Feature Requirements>> section. * Fix indexing math for shader binding table calculations in the <<shader-binding-table-indexing-rules, Indexing Rules>> section, and use spelling "`any-hit`" consistently. * Reconcile valid usage statement and text for sampled image layouts in slink:VkWriteDescriptorSet (https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/551). * Make SPIR-V code:OpConvertUToPtr and code:OpConvertPtrToU operations require a 64-bit integer for physical storage buffer pointers in the <<spirvenv-module-validation, Validation Rules within a Module>> section. * Update to KaTeX 10.0. New Extensions: * `VK_EXT_filter_cubic` * `VK_NV_dedicated_allocation_image_aliasing`
2019-02-04 09:26:23 +00:00
"""Provides a re-usable command-line interface to a MacroChecker."""
# Copyright (c) 2018-2019 Collabora, Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author(s): Ryan Pavlik <ryan.pavlik@collabora.com>
import argparse
import logging
import re
from pathlib import Path
from .shared import MessageId
def checkerMain(default_enabled_messages, make_macro_checker,
all_docs, available_messages=None):
"""Perform the bulk of the work for a command-line interface to a MacroChecker.
Arguments:
default_enabled_messages -- The MessageId values that should be enabled by default.
make_macro_checker -- A function that can be called with a set of enabled MessageId to create a
properly-configured MacroChecker.
all_docs -- A list of all spec documentation files.
available_messages -- a list of all MessageId values that can be generated for this project.
Defaults to every value. (e.g. some projects don't have MessageId.LEGACY)
"""
enabled_messages = set(default_enabled_messages)
if not available_messages:
available_messages = list(MessageId)
disable_args = []
enable_args = []
parser = argparse.ArgumentParser()
Change log for April 16, 2019 Vulkan 1.1.107 spec update: * Update release number to 107. Public Issues: * Fix revision date for the `<<VK_AMD_gpu_shader_half_float>>` appendix (public issue 617). * Make <<synchronization-pipeline-barriers-subpass-self-dependencies, subpass self-dependencies>> less restrictive (public issue 777). * Fix the `<<VK_EXT_full_screen_exclusive>>` dependency on `<<VK_KHR_win32_surface>>` in `vk.xml` (public pull request 849). * Remove single-page (`apispec.html`) refpage sub-targets from the Makefile `allman` target and the build instructions. The target is still present in the Makefile, but we have not been actively maintaining the single-page document and do not promise it will work. The full Specification and the individual API reference pages are what we support and publish at present (public issue 949). Internal Issues: * De-duplicate common valid usage statements shared by multiple commands or structures by using asciidoctor includes and dynamically assigning part of the valid usage ID based on which command or structure they're being applied to (internal issue 779). * Add reference pages for constructs not part of the formal API, such as platform calling convention macros, and script changes supporting them This required suppressing some check_spec_links warning classes in order to pass CI, until a more sophisticated fix can be done (internal issue 888). * Change math notation for the elink:VkPrimitiveTopology descriptions to use short forms `v` and `p` instead of `vertex` and `primitive`, increasing legibility (internal issue 1611). * Rewrite generated file includes relative to a globally specified path, fixing some issues with refpage generation (internal issue 1630). * Update contributor list for `<<VK_EXT_calibrated_timestamps>>`. * Fix use of pathlin in `scripts/generator.py` so the script will work on Windows under Python 3.5 (internal merge request 3107). * Add missing conditionals around the <<descriptorsets-accelerationstructure, Acceleration Structure>> section (internal merge request 3108). * More script synchronization with OpenXR spec repository (internal merge request 3109). * Mark the `<<VK_AMD_gpu_shader_half_float>>` and `<<VK_AMD_gpu_shader_int16>>` extensions as deprecated in `vk.xml` and the corresponding extension appendices (internal merge request 3112). New Extensions: * `<<VK_EXT_headless_surface>>`
2019-04-16 12:19:43 +00:00
parser.add_argument(
"--scriptlocation",
help="Append the script location generated a message to the output.",
action="store_true")
Change log for February 3, 2019 Vulkan 1.1.99 spec update: * Update release number to 99. Public Issues: * Add missing pname:pMemoryHostPointerProperties description to flink:vkGetMemoryHostPointerPropertiesEXT.txt (public pull request 896). * Minor markup fixes (public pull request 900). * Minor update to `khronos.css` and markup fixes (originally proposed in public pull request 901, but done via an internal MR). Internal Issues: * Document restrictions on image queries for Y'CbCr formats in the <<features-formats-requiring-sampler-ycbcr-conversion>> table as well as for slink:sname:VkImageFormatProperties and slink:VkImageCreateInfo (internal issue 1361). * Correct type of the code:FragSizeEXT built-in in the <<interfaces-builtin-variables, Built-In Variables>> section (internal issue 1526). * Clean up math in the <<textures, Image Operations>> chapter by refactoring, using better naming conventions, updating diagrams to use the correct orientation, etc. (internal merge request 2968). * Fix minor typos for slink:VkImageCreateInfo and slink:VkImageStencilUsageCreateInfoEXT. * Add missing documentation for tlink:VkResolveModeFlagsKHR. * Fix extension dependency of pname:scalarBlockLayout in the <<features-features-requirements, Feature Requirements>> section. * Fix indexing math for shader binding table calculations in the <<shader-binding-table-indexing-rules, Indexing Rules>> section, and use spelling "`any-hit`" consistently. * Reconcile valid usage statement and text for sampled image layouts in slink:VkWriteDescriptorSet (https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/551). * Make SPIR-V code:OpConvertUToPtr and code:OpConvertPtrToU operations require a 64-bit integer for physical storage buffer pointers in the <<spirvenv-module-validation, Validation Rules within a Module>> section. * Update to KaTeX 10.0. New Extensions: * `VK_EXT_filter_cubic` * `VK_NV_dedicated_allocation_image_aliasing`
2019-02-04 09:26:23 +00:00
parser.add_argument(
"--verbose",
"-v",
help="Output 'info'-level development logging messages.",
action="store_true")
parser.add_argument(
"--debug",
"-d",
help="Output 'debug'-level development logging messages (more verbose than -v).",
action="store_true")
parser.add_argument(
"-Werror",
"--warning_error",
help="Make warnings act as errors, exiting with non-zero error code",
action="store_true")
parser.add_argument(
"--include_warn",
help="List all expected but unseen include files, not just those that are referenced.",
action='store_true')
parser.add_argument(
"-Wmissing_refpages",
help="List all entities with expected but unseen ref page blocks. NOT included in -Wall!",
action='store_true')
parser.add_argument(
"--include_error",
help="Make expected but unseen include files cause exiting with non-zero error code",
action='store_true')
parser.add_argument(
"--broken_error",
help="Make missing include/anchor for linked-to entities cause exiting with non-zero error code. Weaker version of --include_error.",
action='store_true')
parser.add_argument(
"--dump_entities",
help="Just dump the parsed entity data to entities.json and exit.",
action='store_true')
parser.add_argument(
"--html",
help="Output messages to the named HTML file instead of stdout.")
parser.add_argument(
"file",
help="Only check the indicated file(s). By default, all chapters and extensions are checked.",
nargs="*")
parser.add_argument(
"--ignore_count",
type=int,
help="Ignore up to the given number of errors without exiting with a non-zero error code.")
parser.add_argument("-Wall",
help="Enable all warning categories.",
action='store_true')
for message_id in MessageId:
enable_arg = message_id.enable_arg()
enable_args.append((message_id, enable_arg))
disable_arg = message_id.disable_arg()
disable_args.append((message_id, disable_arg))
if message_id in enabled_messages:
parser.add_argument('-' + disable_arg, action="store_true",
help="Disable message category {}: {}".format(str(message_id), message_id.desc()))
# Don't show the enable flag in help since it's enabled by default
parser.add_argument('-' + enable_arg, action="store_true",
help=argparse.SUPPRESS)
else:
parser.add_argument('-' + enable_arg, action="store_true",
help="Enable message category {}: {}".format(str(message_id), message_id.desc()))
# Don't show the disable flag in help since it's disabled by
# default
parser.add_argument('-' + disable_arg, action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args()
arg_dict = vars(args)
for message_id, arg in enable_args:
if args.Wall or (arg in arg_dict and arg_dict[arg]):
enabled_messages.add(message_id)
for message_id, arg in disable_args:
if arg in arg_dict and arg_dict[arg]:
enabled_messages.discard(message_id)
if args.verbose:
logging.basicConfig(level='INFO')
if args.debug:
logging.basicConfig(level='DEBUG')
checker = make_macro_checker(enabled_messages)
if args.dump_entities:
with open('entities.json', 'w', encoding='utf-8') as f:
f.write(checker.getEntityJson())
exit(0)
if args.file:
Change log for April 16, 2019 Vulkan 1.1.107 spec update: * Update release number to 107. Public Issues: * Fix revision date for the `<<VK_AMD_gpu_shader_half_float>>` appendix (public issue 617). * Make <<synchronization-pipeline-barriers-subpass-self-dependencies, subpass self-dependencies>> less restrictive (public issue 777). * Fix the `<<VK_EXT_full_screen_exclusive>>` dependency on `<<VK_KHR_win32_surface>>` in `vk.xml` (public pull request 849). * Remove single-page (`apispec.html`) refpage sub-targets from the Makefile `allman` target and the build instructions. The target is still present in the Makefile, but we have not been actively maintaining the single-page document and do not promise it will work. The full Specification and the individual API reference pages are what we support and publish at present (public issue 949). Internal Issues: * De-duplicate common valid usage statements shared by multiple commands or structures by using asciidoctor includes and dynamically assigning part of the valid usage ID based on which command or structure they're being applied to (internal issue 779). * Add reference pages for constructs not part of the formal API, such as platform calling convention macros, and script changes supporting them This required suppressing some check_spec_links warning classes in order to pass CI, until a more sophisticated fix can be done (internal issue 888). * Change math notation for the elink:VkPrimitiveTopology descriptions to use short forms `v` and `p` instead of `vertex` and `primitive`, increasing legibility (internal issue 1611). * Rewrite generated file includes relative to a globally specified path, fixing some issues with refpage generation (internal issue 1630). * Update contributor list for `<<VK_EXT_calibrated_timestamps>>`. * Fix use of pathlin in `scripts/generator.py` so the script will work on Windows under Python 3.5 (internal merge request 3107). * Add missing conditionals around the <<descriptorsets-accelerationstructure, Acceleration Structure>> section (internal merge request 3108). * More script synchronization with OpenXR spec repository (internal merge request 3109). * Mark the `<<VK_AMD_gpu_shader_half_float>>` and `<<VK_AMD_gpu_shader_int16>>` extensions as deprecated in `vk.xml` and the corresponding extension appendices (internal merge request 3112). New Extensions: * `<<VK_EXT_headless_surface>>`
2019-04-16 12:19:43 +00:00
files = (str(Path(f).resolve()) for f in args.file)
Change log for February 3, 2019 Vulkan 1.1.99 spec update: * Update release number to 99. Public Issues: * Add missing pname:pMemoryHostPointerProperties description to flink:vkGetMemoryHostPointerPropertiesEXT.txt (public pull request 896). * Minor markup fixes (public pull request 900). * Minor update to `khronos.css` and markup fixes (originally proposed in public pull request 901, but done via an internal MR). Internal Issues: * Document restrictions on image queries for Y'CbCr formats in the <<features-formats-requiring-sampler-ycbcr-conversion>> table as well as for slink:sname:VkImageFormatProperties and slink:VkImageCreateInfo (internal issue 1361). * Correct type of the code:FragSizeEXT built-in in the <<interfaces-builtin-variables, Built-In Variables>> section (internal issue 1526). * Clean up math in the <<textures, Image Operations>> chapter by refactoring, using better naming conventions, updating diagrams to use the correct orientation, etc. (internal merge request 2968). * Fix minor typos for slink:VkImageCreateInfo and slink:VkImageStencilUsageCreateInfoEXT. * Add missing documentation for tlink:VkResolveModeFlagsKHR. * Fix extension dependency of pname:scalarBlockLayout in the <<features-features-requirements, Feature Requirements>> section. * Fix indexing math for shader binding table calculations in the <<shader-binding-table-indexing-rules, Indexing Rules>> section, and use spelling "`any-hit`" consistently. * Reconcile valid usage statement and text for sampled image layouts in slink:VkWriteDescriptorSet (https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/551). * Make SPIR-V code:OpConvertUToPtr and code:OpConvertPtrToU operations require a 64-bit integer for physical storage buffer pointers in the <<spirvenv-module-validation, Validation Rules within a Module>> section. * Update to KaTeX 10.0. New Extensions: * `VK_EXT_filter_cubic` * `VK_NV_dedicated_allocation_image_aliasing`
2019-02-04 09:26:23 +00:00
else:
files = all_docs
for fn in files:
checker.processFile(fn)
if args.html:
from .html_printer import HTMLPrinter
printer = HTMLPrinter(args.html)
else:
from .console_printer import ConsolePrinter
printer = ConsolePrinter()
Change log for April 16, 2019 Vulkan 1.1.107 spec update: * Update release number to 107. Public Issues: * Fix revision date for the `<<VK_AMD_gpu_shader_half_float>>` appendix (public issue 617). * Make <<synchronization-pipeline-barriers-subpass-self-dependencies, subpass self-dependencies>> less restrictive (public issue 777). * Fix the `<<VK_EXT_full_screen_exclusive>>` dependency on `<<VK_KHR_win32_surface>>` in `vk.xml` (public pull request 849). * Remove single-page (`apispec.html`) refpage sub-targets from the Makefile `allman` target and the build instructions. The target is still present in the Makefile, but we have not been actively maintaining the single-page document and do not promise it will work. The full Specification and the individual API reference pages are what we support and publish at present (public issue 949). Internal Issues: * De-duplicate common valid usage statements shared by multiple commands or structures by using asciidoctor includes and dynamically assigning part of the valid usage ID based on which command or structure they're being applied to (internal issue 779). * Add reference pages for constructs not part of the formal API, such as platform calling convention macros, and script changes supporting them This required suppressing some check_spec_links warning classes in order to pass CI, until a more sophisticated fix can be done (internal issue 888). * Change math notation for the elink:VkPrimitiveTopology descriptions to use short forms `v` and `p` instead of `vertex` and `primitive`, increasing legibility (internal issue 1611). * Rewrite generated file includes relative to a globally specified path, fixing some issues with refpage generation (internal issue 1630). * Update contributor list for `<<VK_EXT_calibrated_timestamps>>`. * Fix use of pathlin in `scripts/generator.py` so the script will work on Windows under Python 3.5 (internal merge request 3107). * Add missing conditionals around the <<descriptorsets-accelerationstructure, Acceleration Structure>> section (internal merge request 3108). * More script synchronization with OpenXR spec repository (internal merge request 3109). * Mark the `<<VK_AMD_gpu_shader_half_float>>` and `<<VK_AMD_gpu_shader_int16>>` extensions as deprecated in `vk.xml` and the corresponding extension appendices (internal merge request 3112). New Extensions: * `<<VK_EXT_headless_surface>>`
2019-04-16 12:19:43 +00:00
if args.scriptlocation:
printer.show_script_location = True
Change log for February 3, 2019 Vulkan 1.1.99 spec update: * Update release number to 99. Public Issues: * Add missing pname:pMemoryHostPointerProperties description to flink:vkGetMemoryHostPointerPropertiesEXT.txt (public pull request 896). * Minor markup fixes (public pull request 900). * Minor update to `khronos.css` and markup fixes (originally proposed in public pull request 901, but done via an internal MR). Internal Issues: * Document restrictions on image queries for Y'CbCr formats in the <<features-formats-requiring-sampler-ycbcr-conversion>> table as well as for slink:sname:VkImageFormatProperties and slink:VkImageCreateInfo (internal issue 1361). * Correct type of the code:FragSizeEXT built-in in the <<interfaces-builtin-variables, Built-In Variables>> section (internal issue 1526). * Clean up math in the <<textures, Image Operations>> chapter by refactoring, using better naming conventions, updating diagrams to use the correct orientation, etc. (internal merge request 2968). * Fix minor typos for slink:VkImageCreateInfo and slink:VkImageStencilUsageCreateInfoEXT. * Add missing documentation for tlink:VkResolveModeFlagsKHR. * Fix extension dependency of pname:scalarBlockLayout in the <<features-features-requirements, Feature Requirements>> section. * Fix indexing math for shader binding table calculations in the <<shader-binding-table-indexing-rules, Indexing Rules>> section, and use spelling "`any-hit`" consistently. * Reconcile valid usage statement and text for sampled image layouts in slink:VkWriteDescriptorSet (https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/551). * Make SPIR-V code:OpConvertUToPtr and code:OpConvertPtrToU operations require a 64-bit integer for physical storage buffer pointers in the <<spirvenv-module-validation, Validation Rules within a Module>> section. * Update to KaTeX 10.0. New Extensions: * `VK_EXT_filter_cubic` * `VK_NV_dedicated_allocation_image_aliasing`
2019-02-04 09:26:23 +00:00
if args.file:
printer.output("Only checked specified files.")
for f in args.file:
printer.output(f)
else:
printer.output("Checked all chapters and extensions.")
if args.warning_error:
numErrors = checker.numDiagnostics()
else:
numErrors = checker.numErrors()
check_includes = args.include_warn
check_broken = not args.file
if args.file and check_includes:
print('Note: forcing --include_warn off because only checking supplied files.')
check_includes = False
printer.outputResults(checker, broken_links=(not args.file),
missing_includes=check_includes)
if check_broken:
numErrors += len(checker.getBrokenLinks())
if args.file and args.include_error:
print('Note: forcing --include_error off because only checking supplied files.')
args.include_error = False
if args.include_error:
numErrors += len(checker.getMissingUnreferencedApiIncludes())
check_missing_refpages = args.Wmissing_refpages
if args.file and check_missing_refpages:
print('Note: forcing -Wmissing_refpages off because only checking supplied files.')
check_missing_refpages = False
if check_missing_refpages:
missing = checker.getMissingRefPages()
if missing:
printer.output("Expected, but did not find, ref page blocks for the following {} entities: {}".format(
len(missing),
', '.join(missing)
))
if args.warning_error:
numErrors += len(missing)
printer.close()
if args.broken_error and not args.file:
numErrors += len(checker.getBrokenLinks())
if checker.hasFixes():
fixFn = 'applyfixes.sh'
print('Saving shell script to apply fixes as {}'.format(fixFn))
with open(fixFn, 'w', encoding='utf-8') as f:
f.write('#!/bin/sh -e\n')
for fileChecker in checker.files:
wroteComment = False
for msg in fileChecker.messages:
if msg.fix is not None:
if not wroteComment:
f.write('\n# {}\n'.format(fileChecker.filename))
wroteComment = True
search, replace = msg.fix
f.write(
r"sed -i -r 's~\b{}\b~{}~g' {}".format(
re.escape(search),
replace,
fileChecker.filename))
f.write('\n')
print('Total number of errors with this run: {}'.format(numErrors))
if args.ignore_count:
if numErrors > args.ignore_count:
# Exit with non-zero error code so that we "fail" CI, etc.
print('Exceeded specified limit of {}, so exiting with error'.format(
args.ignore_count))
exit(1)
else:
print('At or below specified limit of {}, so exiting with success'.format(
args.ignore_count))
exit(0)
if numErrors:
# Exit with non-zero error code so that we "fail" CI, etc.
print('Exiting with error')
exit(1)
else:
print('Exiting with success')
exit(0)