[Mlir-commits] [mlir] d86688f - [mlir][python] Segment MLIR Python test dialect to avoid testonly dependency.
Stella Laurenzo
llvmlistbot at llvm.org
Tue Oct 26 11:47:52 PDT 2021
Author: Stella Laurenzo
Date: 2021-10-26T18:47:36Z
New Revision: d86688fb1f14a640bdc5fe1792c318bd818e124d
URL: https://github.com/llvm/llvm-project/commit/d86688fb1f14a640bdc5fe1792c318bd818e124d
DIFF: https://github.com/llvm/llvm-project/commit/d86688fb1f14a640bdc5fe1792c318bd818e124d.diff
LOG: [mlir][python] Segment MLIR Python test dialect to avoid testonly dependency.
With https://reviews.llvm.org/rG14c9207063bb00823a5126131e50c93f6e288bd3, the build is broken with -DMLIR_INCLUDE_TESTS=OFF. This patch fixes the build and we may want to do a better fix to the layering in a followup.
Differential Revision: https://reviews.llvm.org/D112560
Added:
Modified:
mlir/python/CMakeLists.txt
mlir/test/CMakeLists.txt
Removed:
################################################################################
diff --git a/mlir/python/CMakeLists.txt b/mlir/python/CMakeLists.txt
index 54cc51f0ba173..6a49c773e8fe9 100644
--- a/mlir/python/CMakeLists.txt
+++ b/mlir/python/CMakeLists.txt
@@ -8,10 +8,6 @@ declare_mlir_python_sources(MLIRPythonSources)
declare_mlir_python_sources(MLIRPythonSources.Dialects
ADD_TO_PARENT MLIRPythonSources)
-declare_mlir_python_sources(MLIRPythonTestSources)
-declare_mlir_python_sources(MLIRPythonTestSources.Dialects
- ADD_TO_PARENT MLIRPythonTestSources)
-
################################################################################
# Pure python sources and generated code
################################################################################
@@ -113,26 +109,6 @@ declare_mlir_dialect_python_bindings(
dialects/_memref_ops_ext.py
DIALECT_NAME memref)
-# TODO: this uses a tablegen file from the test directory and should be
-# decoupled from here.
-declare_mlir_python_sources(
- MLIRPythonSources.Dialects.PythonTest
- ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
- ADD_TO_PARENT MLIRPythonSources.Dialects
- SOURCES dialects/python_test.py)
-set(LLVM_TARGET_DEFINITIONS
- "${MLIR_MAIN_SRC_DIR}/test/python/python_test_ops.td")
-mlir_tablegen(
- "dialects/_python_test_ops_gen.py"
- -gen-python-op-bindings
- -bind-dialect=python_test)
-add_public_tablegen_target(PythonTestDialectPyIncGen)
-declare_mlir_python_sources(
- MLIRPythonSources.Dialects.PythonTest.ops_gen
- ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}"
- ADD_TO_PARENT MLIRPythonSources.Dialects.PythonTest
- SOURCES "dialects/_python_test_ops_gen.py")
-
declare_mlir_dialect_python_bindings(
ADD_TO_PARENT MLIRPythonSources.Dialects
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
@@ -312,19 +288,48 @@ declare_mlir_python_extension(MLIRPythonExtension.Transforms
MLIRCAPITransforms
)
-# TODO: This should not be included in the main Python extension. However,
+# TODO: Figure out how to put this in the test tree.
+# This should not be included in the main Python extension. However,
# putting it into MLIRPythonTestSources along with the dialect declaration
# above confuses Python module loader when running under lit.
-declare_mlir_python_extension(MLIRPythonExtension.PythonTest
- MODULE_NAME _mlirPythonTest
- ADD_TO_PARENT MLIRPythonSources.Dialects
- SOURCES
- ${MLIR_SOURCE_DIR}/test/python/lib/PythonTestModule.cpp
- PRIVATE_LINK_LIBS
- LLVMSupport
- EMBED_CAPI_LINK_LIBS
- MLIRCAPIPythonTestDialect
-)
+set(_ADDL_TEST_SOURCES)
+if(MLIR_INCLUDE_TESTS)
+ set(_ADDL_TEST_SOURCES MLIRPythonTestSources)
+ declare_mlir_python_sources(MLIRPythonTestSources)
+ declare_mlir_python_sources(MLIRPythonTestSources.Dialects
+ ADD_TO_PARENT MLIRPythonTestSources)
+
+ # TODO: this uses a tablegen file from the test directory and should be
+ # decoupled from here.
+ declare_mlir_python_sources(
+ MLIRPythonTestSources.Dialects.PythonTest
+ ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
+ ADD_TO_PARENT MLIRPythonTestSources.Dialects
+ SOURCES dialects/python_test.py)
+ set(LLVM_TARGET_DEFINITIONS
+ "${MLIR_MAIN_SRC_DIR}/test/python/python_test_ops.td")
+ mlir_tablegen(
+ "dialects/_python_test_ops_gen.py"
+ -gen-python-op-bindings
+ -bind-dialect=python_test)
+ add_public_tablegen_target(PythonTestDialectPyIncGen)
+ declare_mlir_python_sources(
+ MLIRPythonTestSources.Dialects.PythonTest.ops_gen
+ ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}"
+ ADD_TO_PARENT MLIRPythonTestSources.Dialects.PythonTest
+ SOURCES "dialects/_python_test_ops_gen.py")
+
+ declare_mlir_python_extension(MLIRPythonTestSources.PythonTestExtension
+ MODULE_NAME _mlirPythonTest
+ ADD_TO_PARENT MLIRPythonTestSources.Dialects
+ SOURCES
+ ${MLIR_SOURCE_DIR}/test/python/lib/PythonTestModule.cpp
+ PRIVATE_LINK_LIBS
+ LLVMSupport
+ EMBED_CAPI_LINK_LIBS
+ MLIRCAPIPythonTestDialect
+ )
+endif()
################################################################################
# Common CAPI dependency DSO.
@@ -347,6 +352,7 @@ add_mlir_python_common_capi_library(MLIRPythonCAPI
DECLARED_SOURCES
MLIRPythonSources
MLIRPythonExtension.AllPassesRegistration
+ ${_ADDL_TEST_SOURCES}
)
################################################################################
@@ -361,13 +367,7 @@ add_mlir_python_modules(MLIRPythonModules
MLIRPythonSources
MLIRPythonExtension.AllPassesRegistration
MLIRPythonCAPIHeaderSources
+ ${_ADDL_TEST_SOURCES}
COMMON_CAPI_LINK_LIBS
MLIRPythonCAPI
)
-
-add_mlir_python_modules(MLIRPythonTestModules
- ROOT_PREFIX "${MLIR_BINARY_DIR}/python_packages/mlir_test/mlir"
- INSTALL_PREFIX "python_packages/mlir_test/mlir"
- DECLARED_SOURCES
- MLIRPythonTestSources
- )
diff --git a/mlir/test/CMakeLists.txt b/mlir/test/CMakeLists.txt
index 8674c65cf4863..7c5eceebfcc4c 100644
--- a/mlir/test/CMakeLists.txt
+++ b/mlir/test/CMakeLists.txt
@@ -128,7 +128,6 @@ endif()
if(MLIR_ENABLE_BINDINGS_PYTHON)
list(APPEND MLIR_TEST_DEPENDS
MLIRPythonModules
- MLIRPythonTestModules
)
endif()
More information about the Mlir-commits
mailing list