Install factory tests onto factory test images

Make this happen by emerging the autotest-factory-install
package into the image.  This installs the set of tests
needed by factory images.

TEST=Buildbots and inspection
BUG=chromium:313960

CQ-DEPEND=CL:62089

Change-Id: Ie2a49dac3ca93d25ee57538191f30786538e2a0a
Reviewed-on: https://chromium-review.googlesource.com/177372
Tested-by: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Aviv Keshet <akeshet@chromium.org>
Commit-Queue: Christopher Wiley <wiley@chromium.org>
diff --git a/build_library/test_image_util.sh b/build_library/test_image_util.sh
index ddb5d2d..e3bbf24 100755
--- a/build_library/test_image_util.sh
+++ b/build_library/test_image_util.sh
@@ -62,17 +62,19 @@
   if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ||
       should_build_image "${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"; then
     emerge_to_image --root="${root_fs_dir}" factorytest-init
+
+
+    # Install the factory tests and their dependencies into the autotest client
+    # library.
     INSTALL_MASK="${FACTORY_TEST_INSTALL_MASK}"
     emerge_to_image --root="${root_fs_dir}/usr/local" \
-      chromeos-base/autotest chromeos-base/autotest-all \
+      chromeos-base/autotest-factory-install \
       chromeos-base/chromeos-factory
+
     prepare_hwid_for_factory "${BUILD_DIR}"
 
-    local mod_factory_script
-    mod_factory_script="${SCRIPTS_DIR}/mod_for_factory_scripts/factory_setup.sh"
-    # Run factory setup script to modify the image
-    sudo -E GCLIENT_ROOT="${GCLIENT_ROOT}" ROOT_FS_DIR="${root_fs_dir}" \
-            BOARD="${BOARD}" "${mod_factory_script}"
+    echo "Modifying Release Description for Factory."
+    sudo sed -i 's/Test/Factory/' "${root_fs_dir}/etc/lsb-release"
   fi
 
   # Re-run ldconfig to fix /etc/ld.so.cache.
diff --git a/build_packages b/build_packages
index ec74791..c7040bc 100755
--- a/build_packages
+++ b/build_packages
@@ -204,6 +204,7 @@
     PACKAGES+=( chromeos-base/chromeos-factory )
     PACKAGES+=( chromeos-base/factorytest-init )
     PACKAGES+=( chromeos-base/chromeos-hwid )
+    PACKAGES+=( chromeos-base/autotest-factory-install )
   fi
   if [[ "${FLAGS_withtest}" -eq "${FLAGS_TRUE}" ]]; then
     PACKAGES+=( chromeos-base/chromeos-test )
diff --git a/common.sh b/common.sh
index 741730c..9816854 100644
--- a/common.sh
+++ b/common.sh
@@ -430,7 +430,6 @@
   /boot/config-*
   /boot/System.map-*
   /usr/local/build/autotest
-  /usr/local/autotest
   /lib/modules/*/kernel/drivers/input/misc/uinput.ko
   /lib/modules/*/build
   /lib/modules/*/source
@@ -442,26 +441,8 @@
   ${COMMON_INSTALL_MASK}
   */.svn
   */CVS
-  /usr/local/autotest/[^c]*
   /usr/local/autotest/conmux
-  /usr/local/autotest/client/deps/chrome_test
-  /usr/local/autotest/client/deps/piglit
-  /usr/local/autotest/client/deps/pyauto_dep
-  /usr/local/autotest/client/deps/realtimecomm_*
-  /usr/local/autotest/client/site_tests/graphics_WebGLConformance
-  /usr/local/autotest/client/site_tests/platform_ToolchainOptions
-  /usr/local/autotest/client/site_tests/realtimecomm_GTalk*
-  /usr/local/autotest/client/tests
-  /usr/local/build/autotest/[^c]*
-  /usr/local/build/autotest/conmux
-  /usr/local/build/autotest/client/deps/chrome_test
-  /usr/local/build/autotest/client/deps/piglit
-  /usr/local/build/autotest/client/deps/pyauto_dep
-  /usr/local/build/autotest/client/deps/realtimecomm_*
-  /usr/local/build/autotest/client/site_tests/graphics_WebGLConformance
-  /usr/local/build/autotest/client/site_tests/platform_ToolchainOptions
-  /usr/local/build/autotest/client/site_tests/realtimecomm_GTalk*
-  /usr/local/build/autotest/client/tests
+  /usr/local/build/autotest
   /usr/local/factory/bundle
   "
 
diff --git a/mod_for_factory_scripts/100rebaseClient b/mod_for_factory_scripts/100rebaseClient
deleted file mode 100755
index befb92a..0000000
--- a/mod_for_factory_scripts/100rebaseClient
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-die() {
-  echo "ERROR: $*"
-  exit 1
-}
-
-echo "Rebasing autotest/client folder for factory."
-autotest_path="/usr/local/build/autotest"
-base_dir="${ROOT_FS_DIR}${autotest_path}"
-old_base_dir="${ROOT_FS_DIR}/usr/local/autotest"
-
-[ -d "${base_dir}/client" ] || die "Missing client in root: ${base_dir}"
-rm -rf ${base_dir}/packages || die "Failed to wipe packages directory."
-mv "${base_dir}/client/"* "${base_dir}" || die "Failed moving client folder."
-rmdir "${base_dir}/client" || die "Failed removing client folder."
-ln -s . "${base_dir}/client" || die "Failed creating symlink."
-ln -s "${autotest_path}" "${old_base_dir}" || die "Failed legacy symlink."
diff --git a/mod_for_factory_scripts/300modifyDescription b/mod_for_factory_scripts/300modifyDescription
deleted file mode 100755
index 5196142..0000000
--- a/mod_for_factory_scripts/300modifyDescription
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-echo "Modifying Release Description for Factory."
-FILE="${ROOT_FS_DIR}/etc/lsb-release"
-sed -i 's/Test/Factory/' "${FILE}"
diff --git a/mod_for_factory_scripts/400configAutotest b/mod_for_factory_scripts/400configAutotest
deleted file mode 100644
index ce4379b..0000000
--- a/mod_for_factory_scripts/400configAutotest
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-echo "Configure autotest setting."
-
-GLOBAL_CONFIG="${ROOT_FS_DIR}/usr/local/build/autotest/global_config.ini"
-
-if [ -f "${GLOBAL_CONFIG}" ]; then
-  echo -e "File ${GLOBAL_CONFIG} already exists."
-  exit 1
-fi
-
-cat >"${GLOBAL_CONFIG}" <<EOF
-[CLIENT]
-drop_caches: False
-drop_caches_between_iterations: False
-EOF
diff --git a/mod_for_factory_scripts/README.this_directory_is_obsolete b/mod_for_factory_scripts/README.this_directory_is_obsolete
deleted file mode 100644
index 38b5285..0000000
--- a/mod_for_factory_scripts/README.this_directory_is_obsolete
+++ /dev/null
@@ -1,3 +0,0 @@
-Please do not add new files to this directory.  Instead, use:
-
-src/third_party/chromiumos-overlay/chromeos-base/factorytest-init/factorytest-init-9999.ebuild
diff --git a/mod_for_factory_scripts/factory_setup.sh b/mod_for_factory_scripts/factory_setup.sh
deleted file mode 100755
index 9d26bbb..0000000
--- a/mod_for_factory_scripts/factory_setup.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-echo "Modifying image for factory test..."
-set -e
-
-SCRIPT_BASE="${GCLIENT_ROOT}/src/scripts/mod_for_factory_scripts/"
-for SCRIPT in "${SCRIPT_BASE}"[0-9][0-9][0-9]*[!$~]
-do
-  echo "Apply $(basename "${SCRIPT}")..."
-  bash -e "${SCRIPT}"
-done