Skip to content

Commit ff29650

Browse files
committed
Only install git strangely when there is reason to do so
We install `git` in the `cross` container, intending that it come from the git-core PPA and thus be of a recent version. If we can find a Debian-style architecture name that is correct for the `cross` target triple, then we install it for that architecture. In principle we might find such a name without the PPA having a build for that architecture, but that is in practice unlikely to occur and, if it does, then either the `git` we do manage to install is new enough, or we will get test failures due to absent features the test suite needs (such as `GIT_CONFIG_{COUNT,KEY,VALUE}` support). When we don't find such a name, we use the host architecture. When we install `git` for the target architecture, its `perl` and `liberror-perl` dependencies, which as declared must be of that architecture as well, may not be installable. We run into this problem in the container for `s390x-unknown-linux-gnu`. To solve it, we install the dependencies except for those, as well as ensuring those are installed for the host architecture, and then install `git` while forcing it install even if those two dependencies are considered unmet. This works because `git` doesn't use `perl` as a library, but rather as an interpreter for some scripts; and `libperl-error` is a library, but it is a Perl module used from Perl scripts, not a shared library object any Git-related binaries have to load. (Currently, direct dependencies of `git` are hard-coded, which, as commented, may be worth changing to decrease the likelihood of breakage in future versions.) In order to test that the procedure really has a chance of working on a variety of architectures (in case `cross` is to be used to test others at some point), this complex procedure for installing `git` is used whether it is being installed for the target or the host architecture. But this doesn't provide much assurance; that the procedure works when it is effectively just installing exactly the same packages as would be installed anyway does not imply that it works with other cross-target installations where it would be installing different packages. More importantly, using this even when it is known not to be needed obscures the cases where it is not needed, and may create the impression that test failures are due to the strange way `git` was installed, even when they are not. Therefore, this modifies the `cross` container customization script so we only take the strange semi-manual dependency installation approach when there is a chance it might actually be needed, i.e., when we are installing `git` for the cross target rather than the host target.
1 parent 0c1f14a commit ff29650

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

etc/docker/test-cross-context/customize.sh

+31-23
Original file line numberDiff line numberDiff line change
@@ -76,29 +76,37 @@ gix_test_deps=(
7676
pkgconf
7777
)
7878

79-
# Install everything we need except `git` (and what we already have). We can't
80-
# necessarily install `git` this way, because it insists on `perl` and
81-
# `liberror-perl` dependencies of the same architecture as it. These may not be
82-
# possible to install in a mixed environment, where most packages are a
83-
# different architecture, and where `perl` is a dependency of other important
84-
# packages. So we will install everything else first (then manually add `git`).
85-
apt-get install --no-install-recommends -y \
86-
"${git_deps[@]}" "${gix_test_deps[@]}" file
79+
if test -n "$apt_suffix"; then
80+
# Install everything we need except `git` (and what we already have). We
81+
# can't necessarily install `git` this way, because it insists on `perl`
82+
# and `liberror-perl` dependencies of the same architecture as it. These
83+
# may not be possible to install in a mixed environment, where most
84+
# packages are a different architecture, and where `perl` is a dependency
85+
# of other important packages. So we will install everything else first
86+
# (then manually add `git`).
87+
apt-get install --no-install-recommends -y \
88+
"${git_deps[@]}" "${gix_test_deps[@]}" file
8789

88-
# Add `git` by manually downloading it and installing it with `dpkg`, forcing
89-
# installation to proceed even if its `perl` and `liberror-perl` dependencies,
90-
# as declared by `git`, are absent. (We have already installed them, but in a
91-
# possibly different architecture. `git` can still use them, because its use is
92-
# to run scripts, rather than to link to a shared library they provide.) It is
93-
# preferred to let `apt-get download` drop privileges to the `_apt` user during
94-
# download, so we download it inside `/tmp`. But we create a subdirectory so it
95-
# is safe to make assumptions about what files globs can expand to, even if
96-
# `/tmp` is mounted to an outside share temp dir on a multi-user system.
97-
mkdir /tmp/dl # Don't use `-p`; if it exists already, we cannot trust it.
98-
chown _apt /tmp/dl # Use owner, as the container may not have an `_apt` group.
99-
(cd /tmp/dl && apt-get download "git$apt_suffix")
100-
dpkg --ignore-depends="perl$apt_suffix,liberror-perl$apt_suffix" \
101-
-i /tmp/dl/git[-_]*.deb
90+
# Add `git` by manually downloading it and installing it with `dpkg`,
91+
# forcing installation to proceed even if its `perl` and `liberror-perl`
92+
# dependencies, as declared by `git`, are absent. (We have already
93+
# installed them, but in a possibly different architecture. `git` can still
94+
# use them, because its use is to run scripts, rather than to link to a
95+
# shared library they provide.) It is preferred to let `apt-get download`
96+
# drop privileges to the `_apt` user during download, so we download it
97+
# inside `/tmp`. But we create a subdirectory so it is safe to make
98+
# assumptions about what files globs can expand to, even if `/tmp` is
99+
# mounted to an outside share temp dir on a multi-user system.
100+
mkdir /tmp/dl # Don't use `-p`; if it exists already, we cannot trust it.
101+
chown _apt /tmp/dl # Use owner, as the container may have no `_apt` group.
102+
(cd /tmp/dl && apt-get download "git$apt_suffix")
103+
dpkg --ignore-depends="perl$apt_suffix,liberror-perl$apt_suffix" \
104+
-i /tmp/dl/git[-_]*.deb
105+
rm -r /tmp/dl
106+
else
107+
# Install everything we need, including `git`.
108+
apt-get install --no-install-recommends -y git "${gix_test_deps[@]}" file
109+
fi
102110

103111
# Show information about the newly installed `git` (and ensure it can run).
104112
git version --build-options
@@ -107,7 +115,7 @@ file -- "$git"
107115

108116
# Clean up files related to package management that we won't need anymore.
109117
apt-get clean
110-
rm -rf /tmp/dl /var/lib/apt/lists/*
118+
rm -rf /var/lib/apt/lists/*
111119

112120
# If this image has a runner script `cross` uses for Android, patch the script
113121
# to add the ability to suppress its customization of `LD_PRELOAD`. The runner

0 commit comments

Comments
 (0)