blob: 68c2d006dae6095ad6a9627fc78cc9be3dc5d41f [file] [edit]
#!/bin/bash
# Copyright 2025 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This command, when run, copies over a number of PATHS in the 3pp tree (paths are not the same
# as packages, for example "tools/cmake" is a package but not a path).
#
# If the whole operation is successful, we print out the path to the temporary directory and
# exit zero. This makes it easier to do stuff.
set -e
set -o pipefail
die() {
printf '%s\n' "$@" 1>&2
exit 1
}
case "$#" in
0) die 'need positional parameters' ;;
*) : 'do nothing'
esac
oldpwd="$PWD"
nominal_self_dir="$(dirname -- "$0")" || die 'failed to determine nominal self dir'
my_basename="$(basename -- "$0")" || die 'failed to get basename'
self="$( cd -P -- "$nominal_self_dir" && printf '%s/%s' "$(pwd -P)" "$my_basename" )" || die 'failed to find self'
selfdir="$(dirname -- "$self")" || die 'cannot find own directory'
td="$(mktemp -d)" || die 'failed to make temporary directory'
defd="$(mktemp -d)" || die 'failed to defensively chdir'
cd -P -- "$defd" || die 'failed to chdir to defensive directory'
mkdir -p "$td"/pool || die 'failed to make package pool'
for the_path in "$@"; do
test -e "$selfdir"/"$the_path" || die "path '$the_path' does not exist"
test -d "$selfdir"/"$the_path" || die "path '$the_path' is not directory"
cp -r -- "$selfdir"/"$the_path" "$td"/pool
done
printf '%s\n' "$td"/pool