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 <cwallez@chromium.org>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fae3d77..ece7a2c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -181,6 +181,7 @@
 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 ea87236..6b9c0f4 100644
--- a/generator/CMakeLists.txt
+++ b/generator/CMakeLists.txt
@@ -27,6 +27,7 @@
     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 @@
     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 c198722..0d34b88 100644
--- a/generator/generator_lib.py
+++ b/generator/generator_lib.py
@@ -90,6 +90,16 @@
     # --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
 
@@ -237,6 +247,11 @@
         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,
         type=str,