Skip to content

Commit

Permalink
xx-apt: add special case for ubuntu repo switch
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed Nov 10, 2021
1 parent b42b6ac commit e0a9e79
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 9 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ jobs:
image: debian:sid
typ: debian
allow-failure: true
-
image: ubuntu:18.04
typ: debian
allow-failure: false
-
image: ubuntu:20.04
typ: debian
allow-failure: false
-
image: ubuntu:21.10
typ: debian
allow-failure: false
steps:
-
name: Checkout
Expand Down
2 changes: 2 additions & 0 deletions base/test-clang.bats
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ testBuildHello() {
}

@test "armv6-c-lld" {
if [ "$(xx-info vendor)" = "ubuntu" ]; then skip; fi
export TARGETARCH=arm
export TARGETVARIANT=v6
testHelloCLLD
Expand Down Expand Up @@ -265,6 +266,7 @@ testBuildHello() {
}

@test "armv6-c++-lld" {
if [ "$(xx-info vendor)" = "ubuntu" ]; then skip; fi
export TARGETARCH=arm
export TARGETVARIANT=v6
testHelloCPPLLD
Expand Down
8 changes: 7 additions & 1 deletion base/test-info-debian.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

load "assert"

vendor="debian"

if grep "Ubuntu" /etc/issue 2>/dev/null >/dev/null; then
vendor="ubuntu"
fi

@test "vendor" {
assert_equal "debian" "$(xx-info vendor)"
assert_equal "$vendor" "$(xx-info vendor)"
}

@test "libc" {
Expand Down
62 changes: 56 additions & 6 deletions base/xx-apt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,50 @@ else
arg0="apt"
fi

fixubuntusources() {
# fix ubuntu sources
if grep "# generated by xx-apt" /etc/apt/sources.list >/dev/null 2>/dev/null; then
return
fi

group1="amd64,i386"
group2="arm64,armhf,ppc64el,s390x"

nativearch="$(TARGETPLATFORM="" TARGETPAIR="" TARGETARCH="" TARGETOS="" xx-info arch)"

while IFS="" read -r p || [ -n "$p" ]; do

if echo "$p" | grep -E "^(deb|deb-src) "; then
case "${nativearch}" in
amd64,386)
echo "$p" | sed "s/http:\/\/archive.ubuntu.com\/ubuntu\//[arch=$group2] http:\/\/ports.ubuntu.com\/ubuntu-ports\//" | sed "s/http:\/\/security.ubuntu.com\/ubuntu\//[arch=$group2] http:\/\/ports.ubuntu.com\/ubuntu-ports\//" >>/tmp/sources.xx-cross
echo "$p" | sed "s/ http/ [arch=$group1] http/" >>/tmp/sources.xx
;;
*)
if echo "$p" | grep -E "-security "; then
echo "$p" | sed "s/http:\/\/ports.ubuntu.com\/ubuntu-ports\//[arch=$group1] http:\/\/security.ubuntu.com\/ubuntu\//" >>/tmp/sources.xx-cross
else
echo "$p" | sed "s/http:\/\/ports.ubuntu.com\/ubuntu-ports\//[arch=$group1] http:\/\/archive.ubuntu.com\/ubuntu\//" >>/tmp/sources.xx-cross
fi
echo "$p" | sed "s/ http/ [arch=$group2] http/" >>/tmp/sources.xx
;;
esac
else
echo "$p" >>/tmp/sources.xx
fi

done \
< \
\
/etc/apt/sources.list

cat /tmp/sources.xx >/etc/apt/sources.list
echo "# generated by xx-apt" >>/etc/apt/sources.list
cat /tmp/sources.xx-cross >>/etc/apt/sources.list

rm /tmp/sources.xx /tmp/sources.xx-cross
}

packages=
parsed=
n=$#
Expand Down Expand Up @@ -80,13 +124,24 @@ if [ -z "${parsed}" ]; then
exec apt "$@"
fi

if [ "$TARGETARCH" = "riscv64" ]; then
nocross=
if ! xx-info is-cross; then
nocross=1
fi

if [ "$TARGETARCH" = "riscv64" ] && [ "$(xx-info vendor)" = "debian" ]; then
apt-get update
apt-get install -y debian-ports-archive-keyring
echo "deb [ arch=riscv64 ] http://ftp.ports.debian.org/debian-ports sid main" >>/etc/apt/sources.list.d/riscv64-sid.list
fi

if ! dpkg --print-foreign-architectures | grep "$XX_PKG_ARCH" >/dev/null; then
if [ "$(xx-info vendor)" = "ubuntu" ] && [ -z "$nocross" ]; then
# ubuntu uses different repositories for amd64/386 and rest of the architectures
# so we need to fix the sources.list and add new ones
fixubuntusources
fi

dpkg --add-architecture "$XX_PKG_ARCH"
apt-get update
fi
Expand All @@ -96,11 +151,6 @@ if [ "$suffix" = "x86_64-linux-gnu" ]; then
suffix="x86-64-linux-gnu"
fi

nocross=
if ! xx-info is-cross; then
nocross=1
fi

packages2=
for p in ${packages}; do
if [ "${p}" = "xx-c-essentials" ]; then
Expand Down
4 changes: 2 additions & 2 deletions base/xx-info
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fi

vendor=""

if [ "$XX_VENDOR" != "unknown" ] && [ "$XX_VENDOR" != "debian" ]; then
if [ "$XX_VENDOR" != "unknown" ] && [ "$XX_VENDOR" != "debian" ] && [ "$XX_VENDOR" != "ubuntu" ]; then
vendor="-${XX_VENDOR}"
fi

Expand Down Expand Up @@ -265,7 +265,7 @@ case "$TARGETARCH" in
esac

XX_PKG_ARCH=$TARGETARCH
if [ "$XX_VENDOR" = "debian" ]; then
if [ "$XX_VENDOR" = "debian" ] || [ "$XX_VENDOR" = "ubuntu" ]; then
XX_PKG_ARCH=${XX_DEBIAN_ARCH}
elif [ "$XX_VENDOR" = "alpine" ]; then
XX_PKG_ARCH=${XX_ALPINE_ARCH}
Expand Down

0 comments on commit e0a9e79

Please sign in to comment.