Skip to content

Commit

Permalink
Add ci action to automate running autogen
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-lunarg committed Feb 16, 2022
1 parent d299f78 commit b87fcf2
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:

- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -y xorg-dev

- name: CMake Configure
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/run_autogen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without
# limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Copyright © 2022 Charles Giessen ([email protected])
#

# The purpose of this script is to automatically run the autogen code every week and submit a PR to include the changes

on:
schedule:
- cron: '0 0 * * 2'
workflow_dispatch:

jobs:
test_schedule:
name: Test schedule
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Run dispatch generator
run: echo "python script/generate_dispatch.py --auto"
python script/generate_dispatch.py --auto

- name: Diff source to see if anything changed
id: git-diff
run: echo "::set-output name=git-diff::$(git diff --quiet HEAD~1 HEAD -- apps/api/src || echo true)"

- name: pull-request
uses: repo-sync/pull-request@v2
if: ${{ steps.git-diff.outputs.git-diff == 'true' }}
with:
destination_branch: "develop"
github_token: ${{ secrets.GITHUB_TOKEN }}
pr_title: "[auto] Update repo to latest Vulkan-Headers"
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ add_library(vk-bootstrap-vulkan-headers INTERFACE)
set(VK_BOOTSTRAP_VULKAN_HEADER_DIR "" CACHE STRING "Specify the location of the Vulkan-Headers include directory.")
mark_as_advanced(VK_BOOTSTRAP_VULKAN_HEADER_DIR)

include(gen/CurrentBuildVulkanVersion.cmake)

if(NOT "${VK_BOOTSTRAP_VULKAN_HEADER_DIR}" STREQUAL "")
target_include_directories(vk-bootstrap-vulkan-headers INTERFACE $<BUILD_INTERFACE:${VK_BOOTSTRAP_VULKAN_HEADER_DIR}>)
else ()
Expand All @@ -18,7 +20,7 @@ else ()
FetchContent_Declare(
VulkanHeaders
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Headers
GIT_TAG v1.3.204
GIT_TAG ${VK_BOOTSTRAP_SOURCE_HEADER_VERSION_GIT_TAG}
)
FetchContent_MakeAvailable(VulkanHeaders)
target_link_libraries(vk-bootstrap-vulkan-headers INTERFACE Vulkan::Headers)
Expand Down
2 changes: 2 additions & 0 deletions gen/CurrentBuildVulkanVersion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(VK_BOOTSTRAP_SOURCE_HEADER_VERSION 1.3.205)
set(VK_BOOTSTRAP_SOURCE_HEADER_VERSION_GIT_TAG v1.3.205)
49 changes: 45 additions & 4 deletions script/generate_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
# https://github.com/martinblech/xmltodict
# User will be prompted to install if not detected

# Command Line Arguments
# [--auto] Don't ask for input from the command line

# Exclusions
exclusions = [
'vkGetDeviceProcAddr',
Expand All @@ -42,25 +45,31 @@

# Check for/install xmltodict
import sys
import os
import subprocess
import pkg_resources
import copy
import codecs
import re
from string import Template

installed = {pkg.key for pkg in pkg_resources.working_set}
xmltodict_missing = {'xmltodict'} - installed

# Install xmltodict
if xmltodict_missing:
val = input("xmltodict is required to run this script. Would you like to install? (y/n): ")
if '--auto' not in sys.argv:
val = input("xmltodict is required to run this script. Would you like to install? (y/n): ")
else:
val = "y"
if(val.lower() == "y"):
try:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'xmltodict'])
except subprocess.CalledProcessError as error:
print("Failed to install xmltodict due to error:")
print(error)
input("Press Enter to continue...")
if '--auto' not in sys.argv:
input("Press Enter to continue...")
sys.exit()
else:
sys.exit()
Expand All @@ -74,7 +83,8 @@
except urllib.error.URLError as error:
print("Failed to download vk.xml due to error:")
print(error.reason)
input("Press Enter to continue...")
if '-q' not in sys.argv:
input("Press Enter to continue...")
sys.exit()
vk_xml_raw = response.read()

Expand Down Expand Up @@ -308,10 +318,41 @@
body += '};\n\n'
body += '} // namespace vkb'

# find the version used to generate the code
for type_node in types_node:
if 'name' in type_node and type_node['name'] == 'VK_HEADER_VERSION_COMPLETE':
complete_header_version = type_node["#text"]
if 'name' in type_node and type_node['name'] == 'VK_HEADER_VERSION':
vk_header_version = type_node['#text']
find_number_fields = re.compile('[0-9]+')
version_fields = find_number_fields.findall(complete_header_version)
header_version_field = find_number_fields.findall(vk_header_version)[0]
version_tag = f'{version_fields[1]}.{version_fields[2]}.{header_version_field}'

header = license + info + body

header_file = codecs.open("../src/VkBootstrapDispatch.h", "w", "utf-8")
path_to_src = os.path.join('src')
if not os.path.exists(path_to_src):
path_to_src = os.path.join('..', 'src')
if not os.path.exists(path_to_src):
print("Couldn't find source folder. Is the current directory wrong?")
sys.exit()

header_file = codecs.open(os.path.join(path_to_src,"VkBootstrapDispatch.h"), "w", "utf-8")
header_file.write(header)
header_file.close()

path_to_gen = os.path.join('gen')
if not os.path.exists(path_to_gen):
path_to_gen = os.path.join('..', 'gen')
if not os.path.exists(path_to_gen):
print("Couldn't find gen folder. Is the current directory wrong?")
sys.exit()

# Generate a CMake file that contains the header version used.
cmake_version_file = codecs.open(os.path.join(path_to_gen,"CurrentBuildVulkanVersion.cmake"), "w", "utf-8")
cmake_version_file.write(f'set(VK_BOOTSTRAP_SOURCE_HEADER_VERSION {version_tag})\n')
cmake_version_file.write(f'set(VK_BOOTSTRAP_SOURCE_HEADER_VERSION_GIT_TAG v{version_tag})\n')
cmake_version_file.close()

print("Generation finished.")

0 comments on commit b87fcf2

Please sign in to comment.