From 6b67a90d8b72bcbe6a2ac350091c447a40f488c4 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Fri, 7 Apr 2023 07:52:36 +0000 Subject: [PATCH] Allow setting markupsafe directory in CMake. This CL updates the configuration to allow providing the markupsafe folder in the CMake configuration. The generator is updated in order to in set the folder into the path so `jinja2` can find markupsafe. Change-Id: I3b79deba0d8c2af9c751ddb63c4febc542e904df Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/126661 Commit-Queue: Corentin Wallez Auto-Submit: Dan Sinclair Kokoro: Kokoro Reviewed-by: Ben Clayton Reviewed-by: Corentin Wallez --- CMakeLists.txt | 1 + generator/CMakeLists.txt | 4 ++++ generator/generator_lib.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index fae3d779fc..ece7a2cb00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,6 +181,7 @@ set_if_not_defined(DAWN_THIRD_PARTY_DIR "${Dawn_SOURCE_DIR}/third_party" "Direct set_if_not_defined(DAWN_ABSEIL_DIR "${DAWN_THIRD_PARTY_DIR}/abseil-cpp" "Directory in which to find Abseil") set_if_not_defined(DAWN_GLFW_DIR "${DAWN_THIRD_PARTY_DIR}/glfw" "Directory in which to find GLFW") set_if_not_defined(DAWN_JINJA2_DIR "${DAWN_THIRD_PARTY_DIR}/jinja2" "Directory in which to find Jinja2") +set_if_not_defined(DAWN_MARKUPSAFE_DIR "${DAWN_THIRD_PARTY_DIR}/markupsafe" "Directory in which to find MarkupSafe") set_if_not_defined(DAWN_KHRONOS_DIR "${DAWN_THIRD_PARTY_DIR}/khronos" "Directory in which to find Khronos GL headers") set_if_not_defined(DAWN_SPIRV_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-headers/src" "Directory in which to find SPIRV-Headers") set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-tools/src" "Directory in which to find SPIRV-Tools") diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index ea87236f82..6b9c0f43a9 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -27,6 +27,7 @@ if (NOT DAWN_JINJA2_DIR) endif() else() message(STATUS "Dawn: using jinja2 at ${DAWN_JINJA2_DIR}") + message(STATUS "Dawn: using markupsafe at ${DAWN_MARKUPSAFE_DIR}") endif() # Function to invoke a generator_lib.py generator. @@ -54,6 +55,9 @@ function(DawnGenerator) if (DAWN_JINJA2_DIR) list(APPEND BASE_ARGS --jinja2-path ${DAWN_JINJA2_DIR}) endif() + if (DAWN_MARKUPSAFE_DIR) + list(APPEND BASE_ARGS --markupsafe-path ${DAWN_MARKUPSAFE_DIR}) + endif() # Call the generator to get the list of its dependencies. execute_process( diff --git a/generator/generator_lib.py b/generator/generator_lib.py index c198722f09..0d34b886b9 100644 --- a/generator/generator_lib.py +++ b/generator/generator_lib.py @@ -90,6 +90,16 @@ except ValueError: # --jinja2-path isn't passed, ignore the exception and just import Jinja2 # assuming it already is in the Python PATH. pass +kMarkupSafePath = '--markupsafe-path' +try: + markupsafe_path_argv_index = sys.argv.index(kMarkupSafePath) + # Add parent path for the import to succeed. + path = os.path.join(sys.argv[markupsafe_path_argv_index + 1], os.pardir) + sys.path.insert(1, path) +except ValueError: + # --markupsafe-path isn't passed, ignore the exception and just import + # assuming it already is in the Python PATH. + pass import jinja2 @@ -236,6 +246,11 @@ def run_generator(generator): default=None, type=str, help='Additional python path to set before loading Jinja2') + parser.add_argument( + kMarkupSafePath, + default=None, + type=str, + help='Additional python path to set before loading MarkupSafe') parser.add_argument( '--output-json-tarball', default=None,