Rework rebuild-internal.sh to ease dockerization

Script rebuild-internal.sh has all the logic to build crosvm and its
dependencies.  This patch reworks the script to make it more friendly to
being executed during the building of a docker image, as well as from
within a running docker container, while at the same time preserving its
ability to be executed stand-alone, or inside a GCP instance, or on an
ARM board.

-- Make SOURCE_DIR, WORKING_DIR, OUTPUT_DIR, TOOLS_DIR, and
CUSTOM_MANIFEST overridable by the caller, with the same defaults as
before.  These variables will be set differently by docker.
-- Move the setting of these variables, except for TOOLS_DIR, to
function setup_env().  Setup_env() is needed only when syncing and
building sources, not when installing debian packages.  Since docker
will invoke this script while building an image, to install the debian
packages, and then separately when running the container, it makes sense
to move them into their own function.  TOOLS_DIR stays outside of
setup_env(), since it is needed by install_packages()
-- Rename arm64_build() --> aarch64_build() and x86_build() -->
x86_64_build() for better consistency.
-- Move the apt-install and prepare_cargo() steps out of the *_build()
functions and into install_packages(), so all build-setup logic is in
one place.

Bug: 148642775 Clean up the crosvm build
Test: ran GCP, ARM, and standalone builds.

Change-Id: I355e6adcaf163ddd68af243f8b0e0c7cbf7eaae2
Signed-off-by: Iliyan Malchev <malchev@google.com>
1 file changed