blob: 4d984d2ef1cceb0f7e73a17d2edc2ab3cd08f9af [file] [log] [blame] [edit]
#!/bin/bash -ex
# Copyright 2022 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# HACK: Print all outputs to stderr to avoid shuffled logs in Bazel output.
exec >&2
export LANG=en_US.UTF-8
for i in /stage/tarballs/*; do
tar -xv -f "${i}" -C /
done
locale-gen --jobs 1
export SOURCE_DATE_EPOCH=946710000
for PYTHON_VERSION in python3.6 python3.8
do
if ! command -v "${PYTHON_VERSION}" > /dev/null; then
continue
fi
# Python 3.8 changed the lib dir path.
PYTHON_LIBDIR=lib
if [[ "${PYTHON_VERSION}" == "python3.6" ]]; then
PYTHON_LIBDIR=lib64
fi
# Patch portage to support binpkg-hermetic.
# Ideally we land https://chromium-review.googlesource.com/c/chromiumos/third_party/portage_tool/+/4018820
# and can remove this hack.
# The patch was generated by running:
# $ git format-patch HEAD~
# $ sed -i -E -e 's|([ab])/bin/|\1/usr/PYTHON_LIBDIR/portage/PYTHON_VERSION/|g' \
# -e 's|([ab])/lib/portage/|\1/usr/PYTHON_LIBDIR/PYTHON_VERSION/site-packages/portage/|g' \
# *.patch
if ! patch --forward -d "/" -p 1 < <(
find /usr/src/portage -iname '*.patch' | sort | xargs \
sed -e "s/PYTHON_VERSION/${PYTHON_VERSION}/g" \
-e "s/PYTHON_LIBDIR/${PYTHON_LIBDIR}/g"
) && RC="$?"; then
# Exit code 1 means some hunks failed to apply. They were either already applied, or
# had a merge conflict. Not ideal that we can't differentiate between the two.
# Exit code 2 means something bad happened. Let's ignore exit 1 for now.
# We will eventually land all of this upstream.
if [[ "${RC}" -gt 1 ]]; then
exit 1
fi
fi
# TODO: Consider using fakeroot-like approach to emulate file permissions.
sed -i -e '/dir_mode_map = {/,/}/s/False/True/' \
"/usr/${PYTHON_LIBDIR}/${PYTHON_VERSION}/site-packages/portage/package/ebuild/config.py"
# HACK: Allow FEATURES=fakeroot even if UID is 0.
# TODO: Land https://chromium-review.googlesource.com/c/chromiumos/third_party/portage_tool/+/4519681
sed -i "s/fakeroot = fakeroot and uid != 0/fakeroot = fakeroot/" \
"/usr/${PYTHON_LIBDIR}/${PYTHON_VERSION}/site-packages/portage/package/ebuild/doebuild.py"
"${PYTHON_VERSION}" -m compileall "/usr/${PYTHON_LIBDIR}/${PYTHON_VERSION}/site-packages/portage/"
done
rm -f /usr/src/portage/*