Disables installed tests (take 2). (#7433)

* Disables installed tests (take 2).

Revert "Revert "Reverts the "installed tests" feature." (#6798)"

This reverts commit 801c1089cb46d79847177b75f2f771469b46d3b0.
diff --git a/build_tools/cmake/iree_cc_test.cmake b/build_tools/cmake/iree_cc_test.cmake
index 4651837..02d4151 100644
--- a/build_tools/cmake/iree_cc_test.cmake
+++ b/build_tools/cmake/iree_cc_test.cmake
@@ -5,7 +5,6 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 include(CMakeParseArguments)
-include(iree_installed_test)
 
 # iree_cc_test()
 #
@@ -124,9 +123,7 @@
   list(APPEND _RULE_DEPS "gmock")
 
   string(REPLACE "::" "/" _PACKAGE_PATH ${_PACKAGE_NS})
-  set(_TEST_NAME "${_PACKAGE_PATH}/${_RULE_NAME}")
-
-  list(APPEND _RULE_LABELS "${_PACKAGE_PATH}")
+  set(_NAME_PATH "${_PACKAGE_PATH}/${_RULE_NAME}")
 
   # Case for cross-compiling towards Android.
   if(ANDROID)
@@ -134,10 +131,10 @@
     set(_ANDROID_ABS_DIR "/data/local/tmp/${_ANDROID_REL_DIR}")
 
     # Define a custom target for pushing and running the test on Android device.
-    set(_TEST_NAME ${_TEST_NAME}_on_android_device)
+    set(_NAME_PATH ${_NAME_PATH}_on_android_device)
     add_test(
       NAME
-        ${_TEST_NAME}
+        ${_NAME_PATH}
       COMMAND
         "${CMAKE_SOURCE_DIR}/build_tools/cmake/run_android_test.${IREE_HOST_SCRIPT_EXT}"
         "${_ANDROID_REL_DIR}/$<TARGET_FILE_NAME:${_NAME}>"
@@ -151,25 +148,21 @@
         TEST_EXECUTABLE=$<TARGET_FILE:${_NAME}>
         TEST_TMPDIR=${_ANDROID_ABS_DIR}/test_tmpdir
     )
-    set_property(TEST ${_TEST_NAME} PROPERTY ENVIRONMENT ${_ENVIRONMENT_VARS})
-    set_property(TEST ${_TEST_NAME} PROPERTY LABELS "${_RULE_LABELS}")
+    set_property(TEST ${_NAME_PATH} PROPERTY ENVIRONMENT ${_ENVIRONMENT_VARS})
   else(ANDROID)
-    iree_add_installed_test(
-      TEST_NAME "${_TEST_NAME}"
-      LABELS "${_RULE_LABELS}"
+    add_test(
+      NAME
+        ${_NAME_PATH}
       COMMAND
         # We run all our tests through a custom test runner to allow temp
         # directory cleanup upon test completion.
         "${CMAKE_SOURCE_DIR}/build_tools/cmake/run_test.${IREE_HOST_SCRIPT_EXT}"
         "$<TARGET_FILE:${_NAME}>"
-      INSTALLED_COMMAND
-        # Must match install destination below.
-        "${_PACKAGE_PATH}/$<TARGET_FILE_NAME:${_NAME}>"
-    )
+      )
+    set_property(TEST ${_NAME_PATH} PROPERTY ENVIRONMENT "TEST_TMPDIR=${IREE_BINARY_DIR}/tmp/${_NAME}_test_tmpdir")
+    iree_add_test_environment_properties(${_NAME_PATH})
   endif(ANDROID)
 
-  install(TARGETS ${_NAME}
-    DESTINATION "tests/${_PACKAGE_PATH}"
-    COMPONENT Tests
-  )
+  list(APPEND _RULE_LABELS "${_PACKAGE_PATH}")
+  set_property(TEST ${_NAME_PATH} PROPERTY LABELS "${_RULE_LABELS}")
 endfunction()
diff --git a/build_tools/cmake/iree_installed_test.cmake b/build_tools/cmake/iree_installed_test.cmake
deleted file mode 100644
index 1f99997..0000000
--- a/build_tools/cmake/iree_installed_test.cmake
+++ /dev/null
@@ -1,92 +0,0 @@
-# Copyright 2020 The IREE Authors
-#
-# Licensed under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-# iree_add_installed_test()
-#
-# Creates a build-time and exported install-time test. All tests are installed
-# into the tests/ tree. Calling code must arrange to install dependencies of the
-# test into that tree.
-#
-# Parameters:
-# TEST_NAME: Name of the test (as in "some/path/to/test").
-# COMMAND: Passed to add_test() as is.
-# ENVIRONMENT: Set as the ENVIRONMENT property of the build-time test.
-# INSTALLED_COMMAND: Corrollary to the 'COMMAND' argument but added to the
-#   install time definition.
-# WORKING_DIRECTORY: Passed to add_test() as is. Note that in the install tree
-# all tests run in the tests/ directory.
-# LABELS: Labels to pass to add_test() and installed tests.
-function(iree_add_installed_test)
-  cmake_parse_arguments(
-    _RULE
-    ""
-    "TEST_NAME"
-    "COMMAND;ENVIRONMENT;INSTALLED_COMMAND;WORKING_DIRECTORY;LABELS"
-    ${ARGN}
-  )
-
-
-  add_test(
-    NAME
-      ${_RULE_TEST_NAME}
-    COMMAND
-      ${_RULE_COMMAND}
-  )
-  if (DEFINED _RULE_WORKING_DIRECTORY)
-    set_property(
-      TEST
-        ${_RULE_TEST_NAME}
-      PROPERTY WORKING_DIRECTORY
-        "${_RULE_WORKING_DIRECTORY}"
-    )
-  endif()
-  set_property(
-    TEST
-      ${_RULE_TEST_NAME}
-    PROPERTY LABELS
-      "${_RULE_LABELS}"
-  )
-  set_property(
-    TEST
-      ${_RULE_TEST_NAME}
-    PROPERTY ENVIRONMENT
-      "TEST_TMPDIR=${CMAKE_BINARY_DIR}/${_RULE_TEST_NAME}_test_tmpdir"
-      ${_RULE_ENVIRONMENT}
-  )
-  iree_add_test_environment_properties(${_RULE_TEST_NAME})
-
-  # Write the to the installed ctest file template.
-  set(_installed_ctest_input_file
-        "${CMAKE_BINARY_DIR}/iree_installed_tests.cmake.in")
-  get_property(_has_tests GLOBAL PROPERTY IREE_HAS_INSTALLED_TESTS)
-  if(NOT _has_tests)
-    # First time.
-    file(WRITE "${_installed_ctest_input_file}")  # Truncate.
-    set_property(GLOBAL PROPERTY IREE_HAS_INSTALLED_TESTS ON)
-  endif()
-
-  # Now write directives to the installed tests cmake file.
-  file(APPEND "${_installed_ctest_input_file}"
-    "add_test(${_RULE_TEST_NAME} ${_RULE_INSTALLED_COMMAND})\n"
-    "set_tests_properties(${_RULE_TEST_NAME} PROPERTIES LABELS \"${_RULE_LABELS}\")\n"
-  )
-
-  # First time generation and setup to install. Note that since this all runs
-  # at the generate phase, it doesn't matter that we trigger it before all
-  # tests accumulate.
-  if(NOT _has_tests)
-    set(_installed_ctest_output_file "${CMAKE_BINARY_DIR}/iree_installed_tests.cmake")
-    file(GENERATE
-      OUTPUT "${_installed_ctest_output_file}"
-      INPUT "${_installed_ctest_input_file}"
-    )
-    install(FILES "${_installed_ctest_output_file}"
-      DESTINATION tests
-      RENAME "CTestTestfile.cmake"
-      COMPONENT Tests
-    )
-  endif()
-endfunction()
diff --git a/build_tools/cmake/iree_lit_test.cmake b/build_tools/cmake/iree_lit_test.cmake
index 9f54ec9..e86456d 100644
--- a/build_tools/cmake/iree_lit_test.cmake
+++ b/build_tools/cmake/iree_lit_test.cmake
@@ -5,7 +5,6 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 include(CMakeParseArguments)
-include(iree_installed_test)
 
 # iree_lit_test()
 #
@@ -61,11 +60,9 @@
   iree_package_ns(_PACKAGE_NS)
   string(REPLACE "::" "/" _PACKAGE_PATH ${_PACKAGE_NS})
   set(_NAME_PATH "${_PACKAGE_PATH}/${_RULE_NAME}")
-  list(APPEND _RULE_LABELS "${_PACKAGE_PATH}")
-
-  iree_add_installed_test(
-    TEST_NAME "${_NAME_PATH}"
-    LABELS "${_RULE_LABELS}"
+  add_test(
+    NAME
+      ${_NAME_PATH}
     COMMAND
       # We run all our tests through a custom test runner to allow setup
       # and teardown.
@@ -73,18 +70,14 @@
       "${CMAKE_SOURCE_DIR}/iree/tools/run_lit.${IREE_HOST_SCRIPT_EXT}"
       ${_TEST_FILE_PATH}
       ${_DATA_DEP_PATHS}
-    INSTALLED_COMMAND
-      # TODO: Make the lit runner be not a shell script and more cross-platform.
-      # Note that the data deps are not bundled: must be externally on the path.
-      bin/run_lit.${IREE_HOST_SCRIPT_EXT}
-      ${_TEST_FILE_PATH}
   )
-  set_property(TEST ${_NAME_PATH} PROPERTY REQUIRED_FILES "${_TEST_FILE_PATH}")
 
-  install(FILES ${_TEST_FILE_PATH}
-    DESTINATION "tests/${_PACKAGE_PATH}"
-    COMPONENT Tests
-  )
+  list(APPEND _RULE_LABELS "${_PACKAGE_PATH}")
+  set_property(TEST ${_NAME_PATH} PROPERTY LABELS "${_RULE_LABELS}")
+  set_property(TEST ${_NAME_PATH} PROPERTY REQUIRED_FILES "${_TEST_FILE_PATH}")
+  set_property(TEST ${_NAME_PATH} PROPERTY ENVIRONMENT "TEST_TMPDIR=${IREE_BINARY_DIR}/tmp/${_NAME}_test_tmpdir")
+  iree_add_test_environment_properties(${_NAME_PATH})
+
   # TODO(gcmn): Figure out how to indicate a dependency on _RULE_DATA being built
 endfunction()
 
diff --git a/build_tools/cmake/iree_python.cmake b/build_tools/cmake/iree_python.cmake
index 09f11da..447ab91 100644
--- a/build_tools/cmake/iree_python.cmake
+++ b/build_tools/cmake/iree_python.cmake
@@ -5,7 +5,6 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 include(CMakeParseArguments)
-include(iree_installed_test)
 
 ###############################################################################
 # Main user rules
@@ -262,7 +261,7 @@
 #
 # Parameters:
 # NAME: name of test
-# SRCS: Test source file
+# SRCS: Test source file (single file only, despite name)
 # ARGS: Command line arguments to the Python source file.
 # LABELS: Additional labels to apply to the test. The package path is added
 #     automatically.
@@ -295,25 +294,21 @@
   set(_NAME_PATH "${_PACKAGE_PATH}/${_RULE_NAME}")
   list(APPEND _RULE_LABELS "${_PACKAGE_PATH}")
 
-  iree_add_installed_test(
-    TEST_NAME "${_NAME_PATH}"
-    LABELS "${_RULE_LABELS}"
-    ENVIRONMENT
-      "PYTHONPATH=${IREE_BINARY_DIR}/compiler-api/python_package:${IREE_BINARY_DIR}/bindings/python:$ENV{PYTHONPATH}"
+  add_test(
+    NAME ${_NAME_PATH}
     COMMAND
       "${IREE_SOURCE_DIR}/build_tools/cmake/run_test.${IREE_HOST_SCRIPT_EXT}"
       "${Python3_EXECUTABLE}"
-      "${_SRC_DIR}/${_RULE_SRCS}"
+      "${CMAKE_CURRENT_SOURCE_DIR}/${_RULE_SRCS}"
       ${_RULE_ARGS}
-    INSTALLED_COMMAND
-      python
-      "${_PACKAGE_PATH}/${_RULE_SRCS}"
   )
 
-  install(FILES ${_RULE_SRCS}
-    DESTINATION "tests/${_PACKAGE_PATH}"
-    COMPONENT Tests
+  set_property(TEST ${_NAME_PATH} PROPERTY LABELS "${_RULE_LABELS}")
+  set_property(TEST ${_NAME_PATH} PROPERTY ENVIRONMENT
+      "PYTHONPATH=${IREE_BINARY_DIR}/compiler-api/python_package:${IREE_BINARY_DIR}/bindings/python:$ENV{PYTHONPATH}"
+      "TEST_TMPDIR=${IREE_BINARY_DIR}/tmp/${_NAME}_test_tmpdir"
   )
+  iree_add_test_environment_properties(${_NAME_PATH})
 
   # TODO(marbre): Find out how to add deps to tests.
   #               Similar to _RULE_DATA in iree_lit_test().