Merge main -> google

* 6c1869bc Add license header to linker scripts (#2724)
* 6d32fe81 Updates all e2e tests to use TracedModuleTestCase (#2736)
* 7fea2dd1 Revert "[android] Ignore adb push status for the executable (#2627)" (#2735)
* da48d03c Adds a class for tracing module calls and example tests. (#2660)
* d66150d8 Enables `conv_test` on vulkan. (#2723)
* a3b73bf6 Add .python-version to .gitignore (#2727)
* 6d2bfd35 Enables passing MobileNet and MobileNetV2 vision tests (#2725)
* 763dc098 Fix ModelBuilder build (#2726)
* 528a86a7 Update the codegen pipeline example snippets to better demonstrate (#2709)
* 91a05ff5 Merge google -> main (#2719)
* f0307a87 Revert "Merge google -> main" (#2718)
* 77d2f8b4 Merge google -> main (#2711)
* aafabbcb Add linker scripts to cmake pyiree builds to hide symbols. (#2707)
* 1918d5c7 Updated gather to run on LLVM and SPIRV (#2701)
* ec38aa00 Add a VM to EmitC conversion and CModule Target (#2536)
* 32fe2c9b Revert "Add a VM to EmitC conversion and CModule Target (#2536)" (#2703)
* e7f90b61 Revert addition of DYLIB-LLVM-AOT as a default backend (#2702)
* 48efada8 Dump input values to a file. (#2683)
* 0fd8a550 Mark shell scripts as executable (#2699)
* 966fe78f Add dep "//iree/base:localfile" to iree-run-mlir (#2687)
* 64e29879 Merge google -> main (#2698)
* ced7477f Update scripts for packaging wheels from bazel.
* 1c05e0ae Disable dylib driver for android build (#2692)
* e00a85f8 Disable a few gcc warnings that are chatty.
* 74af1f01 Add a config for gcc. (#2696)
* eec62a1e Remove dylib-llvm-aot tests (#2694)
* 11bd7a00 Fix stdalign include in Android (#2688)
* b9026bd6 Enable dylib-llvm-aot backend e2e/xla_op tests (#2639)
* 8ed9f73f Added Complex operation lowerings to pre-target conversion (#2662)
* 8224247a Working around duplicate func->llvm.func rewrites. (#2685)
* f2d6649c Bump pybind11 to head. (#2592)
* 9ac5241d [NFC] Remove empty ArrayRef<NamedAttribute> arg in op creation (#2686)
* 36abdfde [ModelBuilder] Revert spurious path change (#2684)
* c96bbb1d Merge pull request #2568 from google/benvanik-flatcc-vm
* f80864f8 [ModelBuilder] Add MemRefUtil helpers for padding. (#2577)
* 1425737d Fix flatcc target name and binary path (#2599)
* 8c18b8c3 Refactoring bytecode_module to use flatcc instead of flatbuffers C++. This imp..
* 3762c132 Linking in the flatcc bytecode_module_def files. This ensures they are correct..
* eb53de3e Building bytecode_module_def with flatcc.

PiperOrigin-RevId: 324296127
diff --git a/packaging/python/hack_python_package_from_runfiles.py b/packaging/python/hack_python_package_from_runfiles.py
new file mode 100644
index 0000000..61c2d6e
--- /dev/null
+++ b/packaging/python/hack_python_package_from_runfiles.py
@@ -0,0 +1,102 @@
+#!/usr/bin/python
+# 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.
+
+# Given a runfiles directory from a bazel build, does surgery to extract
+# a usable python package directory. In addition to the bazel directory
+# structure being unnecessarily obtuse, it is also really hard to actually
+# name files correctly. This affects python extension modules which must be
+# named with a specific extension suffix. Bazel is extremely unflexible and
+# we patch around it with this script. For the record, there are various ways
+# to write custom rules to do this more natively, but it is all complicated
+# and needless complexity. We opt for a script that is at least readable by
+# mere mortals and in one place.
+# Usage:
+#   ./this_script <dest_dir> <path to bazel-bin>
+
+import os
+import platform
+import shutil
+import sys
+import sysconfig
+
+FILE_NAME_MAP = {
+    "binding.so": "binding{}".format(sysconfig.get_config_var("EXT_SUFFIX")),
+    "binding.pyd": False,
+    "binding.dylib": False,
+}
+
+
+def get_exe_suffix():
+  if platform.system() == "Windows":
+    return ".exe"
+  else:
+    return ""
+
+
+def copy_prefix(dest_dir, runfiles_dir, prefix):
+  # And finally seek into the corresponding path in the runfiles dir.
+  # Aren't bazel paths fun???
+  # Note that the "iree_core" path segment corresponds to the workspace name.
+  pkg_dir = os.path.join(runfiles_dir, "iree_core", *prefix)
+  if not os.path.exists(pkg_dir):
+    return
+  dest_dir = os.path.join(dest_dir)
+  for root, dirs, files in os.walk(pkg_dir):
+    assert root.startswith(pkg_dir)
+    dest_prefix = root[len(pkg_dir):]
+    if dest_prefix.startswith(os.path.sep):
+      dest_prefix = dest_prefix[1:]
+    local_dest_dir = os.path.join(dest_dir, dest_prefix)
+    os.makedirs(local_dest_dir, exist_ok=True)
+    for file in files:
+      copy_file(os.path.join(root, file), local_dest_dir)
+
+
+def copy_file(src_file, dst_dir):
+  basename = os.path.basename(src_file)
+  dst_file = os.path.join(dst_dir, basename)
+  mapped_name = FILE_NAME_MAP.get(basename)
+  if mapped_name is False:
+    # Skip.
+    return
+  elif mapped_name is not None:
+    dst_file = os.path.join(dst_dir, mapped_name)
+  shutil.copyfile(src_file, dst_file, follow_symlinks=True)
+
+
+def main():
+  # Parse args.
+  dest_dir = sys.argv[1]
+  bazel_bin = sys.argv[2] if len(sys.argv) > 2 else os.path.join(
+      os.path.dirname(__file__), "..", "..", "bazel-bin")
+
+  # Find the path to the runfiles of the built target:
+  #   //bindings/python/packaging:all_pyiree_packages
+  runfiles_dir = os.path.join(
+      bazel_bin, "packaging", "python",
+      "all_pyiree_packages%s.runfiles" % (get_exe_suffix(),))
+  if not os.path.isdir(runfiles_dir):
+    print("ERROR: Could not find build target 'all_pyiree_packages':",
+          runfiles_dir)
+    print("Make sure to build target", "//packaging/python:all_pyiree_packages")
+    sys.exit(1)
+
+  copy_prefix(dest_dir, runfiles_dir, ("bindings", "python"))
+  copy_prefix(dest_dir, runfiles_dir,
+              ("integrations", "tensorflow", "bindings", "python"))
+
+
+if __name__ == "__main__":
+  main()