blob: 0b1abd7886af3919b7b697670cc07447b14f9cf2 [file] [log] [blame]
# Copyright 2020 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.
# Populates a directory with everything necessary to build a remote test driver
# container.
# BuildAndCopyTastItems builds and copies all Tast related executables
# and data to targets.
BuildAndCopyTastItems() {
# Emerge tast related executables.
sudo emerge tast-cmd
sudo emerge tast-remote-tests-cros
local tast_dir="$1/tast"
local tast_bin_dir="${tast_dir}/bin"
# Copy tast related items.
mkdir -p "${tast_bin_dir}"
cp /usr/bin/tast "${tast_bin_dir}"
cp /usr/bin/tast_rtd "${tast_bin_dir}"
cp /usr/bin/remote_test_runner "${tast_bin_dir}"
cp -pdr /usr/libexec/tast/bundles "${tast_dir}"
cp -pdr /usr/share/tast/data "${tast_dir}"
cp -pdr /etc/tast/vars "${tast_dir}"
cp -pdr /home/"${USER}"/trunk/chromite/ssh_keys "${tast_dir}"
readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")"
. "${script_dir}/" || exit 1
# Script must run inside the chroot
assert_inside_chroot "$@"
# Do not run as root
DEFINE_string output_dir "" "Dir in which to put Dockerfile and dependencies"
# Parse command line flags
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Only now can we die on error. shflags functions leak non-zero error codes,
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
if [[ -z "${FLAGS_output_dir}" ]]; then
info "No --output_dir provided. Using temp dir instead"
output_dir=$(mktemp -d)
if [[ ! -d "${output_dir}" ]]; then
error "output_dir ${output_dir} must exist as a directory"
exit 1
if [[ -n "$(ls -A "${output_dir}")" ]]; then
error "output_dir ${output_dir} must be empty"
exit 1
# Write out a simple Dockerfile.
cat > "${output_dir}/Dockerfile" <<- EOF
FROM ubuntu:bionic
WORKDIR /usr/src/rtd/
COPY rtd/ .
# Create the remote test driver folder and copy test content into it.
mkdir "${rtd_dir}"
# Build and copy the tnull (fake) RTD.
sudo emerge tnull
cp /usr/bin/tnull "${rtd_dir}/"
# tast and tauto entries will eventually go here.
BuildAndCopyTastItems "${rtd_dir}"
info "Done. Wrote output to ${output_dir}"