Step 3/n: Add build support for compiler2 and tests.
* Also changes iree_py_library rules to symlink vs copy python sources (because it was annoying me greatly).
* Symlinks iree-translate into the new pyiree.tools.core package.
* Creates the stub for pyiree.tools.tf package (will be populated later).
* TensorFlow compiler tests is in the suite but will no-op if dependencies are not met (they are not now).
diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt
index 3febc3b..0fdc05e 100644
--- a/bindings/python/CMakeLists.txt
+++ b/bindings/python/CMakeLists.txt
@@ -18,3 +18,4 @@
set(PYBIND_EXTENSION_COPTS "-fvisibility=hidden")
add_subdirectory(pyiree)
+add_subdirectory(tests)
diff --git a/bindings/python/pyiree/CMakeLists.txt b/bindings/python/pyiree/CMakeLists.txt
index 55ac43d..73728d5 100644
--- a/bindings/python/pyiree/CMakeLists.txt
+++ b/bindings/python/pyiree/CMakeLists.txt
@@ -13,7 +13,9 @@
# limitations under the License.
add_subdirectory(common)
+add_subdirectory(compiler2)
add_subdirectory(rt)
+add_subdirectory(tools/core)
if(${IREE_BUILD_COMPILER})
add_subdirectory(compiler)
diff --git a/bindings/python/pyiree/compiler2/.skip_bazel_to_cmake b/bindings/python/pyiree/compiler2/.skip_bazel_to_cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bindings/python/pyiree/compiler2/.skip_bazel_to_cmake
diff --git a/bindings/python/pyiree/compiler2/CMakeLists.txt b/bindings/python/pyiree/compiler2/CMakeLists.txt
new file mode 100644
index 0000000..c67229a
--- /dev/null
+++ b/bindings/python/pyiree/compiler2/CMakeLists.txt
@@ -0,0 +1,23 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+iree_py_library(
+ NAME
+ compiler2
+ SRCS
+ "__init__.py"
+ "core.py"
+ "tf.py"
+ "tools.py"
+)
diff --git a/bindings/python/pyiree/compiler2/tools.py b/bindings/python/pyiree/compiler2/tools.py
index 8bf4ad8..fab668b 100644
--- a/bindings/python/pyiree/compiler2/tools.py
+++ b/bindings/python/pyiree/compiler2/tools.py
@@ -149,7 +149,9 @@
run_args["input"] = immediate_input
# Capture output.
- run_args["capture_output"] = True
+ # Upgrade note: Python >= 3.7 can just use capture_output=True
+ run_args["stdout"] = subprocess.PIPE
+ run_args["stderr"] = subprocess.PIPE
process = subprocess.run(command_line, **run_args)
if process.returncode != 0:
raise CompilerToolError(process)
diff --git a/bindings/python/pyiree/tools/core/.skip_bazel_to_cmake b/bindings/python/pyiree/tools/core/.skip_bazel_to_cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bindings/python/pyiree/tools/core/.skip_bazel_to_cmake
diff --git a/bindings/python/pyiree/tools/core/CMakeLists.txt b/bindings/python/pyiree/tools/core/CMakeLists.txt
new file mode 100644
index 0000000..94027d3
--- /dev/null
+++ b/bindings/python/pyiree/tools/core/CMakeLists.txt
@@ -0,0 +1,56 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+iree_py_library(
+ NAME
+ core
+ SRCS
+ "__init__.py"
+)
+
+# Adds a command to TARGET which symlinks a tool from elsewhere
+# (FROM_TOOL_TARGET_NAME) to a local file name (TO_EXE_NAME).
+function(_symlink_tool)
+ cmake_parse_arguments(
+ ARG
+ ""
+ "TARGET;FROM_TOOL_TARGET;TO_EXE_NAME"
+ ""
+ ${ARGN}
+ )
+
+ # Transform TARGET
+ iree_package_ns(_PACKAGE_NS)
+ iree_package_name(_PACKAGE_NAME)
+ set(_TARGET "${_PACKAGE_NAME}_${ARG_TARGET}")
+ set(_FROM_TOOL_TARGET ${ARG_FROM_TOOL_TARGET})
+
+ add_custom_command(
+ TARGET "${_TARGET}"
+ BYPRODUCTS
+ "${CMAKE_CURRENT_BINARY_DIR}/${ARG_TO_EXE_NAME}${CMAKE_EXECUTABLE_SUFFIX}"
+ COMMAND
+ ${CMAKE_COMMAND} -E create_symlink
+ "$<TARGET_FILE:${_FROM_TOOL_TARGET}>"
+ "${CMAKE_CURRENT_BINARY_DIR}/${ARG_TO_EXE_NAME}${CMAKE_EXECUTABLE_SUFFIX}"
+ )
+endfunction()
+
+if(${IREE_BUILD_COMPILER})
+ _symlink_tool(
+ TARGET core
+ FROM_TOOL_TARGET iree_tools_iree-translate
+ TO_EXE_NAME iree-translate
+ )
+endif()
diff --git a/bindings/python/pyiree/tools/core/__init__.py b/bindings/python/pyiree/tools/core/__init__.py
new file mode 100644
index 0000000..4ce9c14
--- /dev/null
+++ b/bindings/python/pyiree/tools/core/__init__.py
@@ -0,0 +1,29 @@
+# Lint-as: python3
+"""Core tools."""
+
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+from typing import Optional
+
+import os
+import platform
+
+
+def get_tool(exe_name: str) -> Optional[str]:
+ if platform.system() == "Windows":
+ exe_name = exe_name + ".exe"
+ this_path = os.path.dirname(__file__)
+ tool_path = os.path.join(this_path, exe_name)
+ return tool_path
diff --git a/bindings/python/pyiree/tools/tf/__init__.py b/bindings/python/pyiree/tools/tf/__init__.py
new file mode 100644
index 0000000..ceb37ea
--- /dev/null
+++ b/bindings/python/pyiree/tools/tf/__init__.py
@@ -0,0 +1,29 @@
+# Lint-as: python3
+"""TensorFlow tools."""
+
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+from typing import Optional
+
+import os
+import platform
+
+
+def get_tool(exe_name: str) -> Optional[str]:
+ if platform.system() == "Windows":
+ exe_name = exe_name + ".exe"
+ this_path = os.path.dirname(__file__)
+ tool_path = os.path.join(this_path, exe_name)
+ return tool_path
diff --git a/bindings/python/tests/.skip_bazel_to_cmake b/bindings/python/tests/.skip_bazel_to_cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bindings/python/tests/.skip_bazel_to_cmake
diff --git a/bindings/python/tests/CMakeLists.txt b/bindings/python/tests/CMakeLists.txt
new file mode 100644
index 0000000..e70629a
--- /dev/null
+++ b/bindings/python/tests/CMakeLists.txt
@@ -0,0 +1,33 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+iree_py_test(
+ NAME
+ compiler_core_test
+ SRCS
+ "compiler_core_test.py"
+ DEPS
+ bindings::python::pyiree::compiler2
+ bindings::python::pyiree::tools::core
+)
+
+iree_py_test(
+ NAME
+ compiler_tf_test
+ SRCS
+ "compiler_tf_test.py"
+ DEPS
+ bindings::python::pyiree::compiler2
+ bindings::python::pyiree::tools::tf
+)
diff --git a/build_tools/cmake/iree_multipy.cmake b/build_tools/cmake/iree_multipy.cmake
index 1ac1028..13510d4 100644
--- a/build_tools/cmake/iree_multipy.cmake
+++ b/build_tools/cmake/iree_multipy.cmake
@@ -237,14 +237,20 @@
iree_package_name(_PACKAGE_NAME)
set(_NAME "${_PACKAGE_NAME}_${ARG_NAME}")
- # Add path to each source file
- list(TRANSFORM ARG_SRCS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/")
-
add_custom_target(${_NAME} ALL
- COMMAND ${CMAKE_COMMAND} -E copy ${ARG_SRCS} "${CMAKE_CURRENT_BINARY_DIR}/"
DEPENDS ${ARG_DEPS}
)
+ # Symlink each file as its own target.
+ foreach(SRC_FILE ${ARG_SRCS})
+ add_custom_command(
+ TARGET ${_NAME}
+ COMMAND ${CMAKE_COMMAND} -E create_symlink
+ "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE}"
+ BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE}"
+ )
+ endforeach()
+
# Add PYEXT_DEPS.
if(${ARG_PYEXT_DEPS})
foreach(V ${IREE_MULTIPY_VERSIONS_EFFECTIVE})