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 <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Nov 10, 2021
1 parent b42b6ac commit ebf3623
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 40 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
63 changes: 32 additions & 31 deletions base/test-apt.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ load 'assert'
}

@test "native" {
run xx-apt info file
run xx-apt show file
assert_success
assert_line "Package: file"

run xx-apt info libc6-dev
run xx-apt show libc6-dev
assert_success
assert_line "Package: libc6-dev"

run xx-apt info gcc
run xx-apt show gcc
assert_success
assert_line "Package: gcc"
}
Expand All @@ -26,21 +26,21 @@ load 'assert'
export TARGETARCH=amd64
if ! xx-info is-cross; then skip; fi

run xx-apt info file
run xx-apt show file
assert_success
assert_line "Package: file:amd64"

run xx-apt info libc6-dev
run xx-apt show libc6-dev
assert_success
assert_line "Package: libc6-dev:amd64"

export XX_APT_PREFER_CROSS=1
run xx-apt info libc6-dev
run xx-apt show libc6-dev
assert_success
assert_line "Package: libc6-dev-amd64-cross"
unset XX_APT_PREFER_CROSS

run xx-apt info gcc
run xx-apt show gcc
assert_success
assert_line "Package: gcc-x86-64-linux-gnu"
}
Expand All @@ -49,21 +49,21 @@ load 'assert'
export TARGETARCH=arm64
if ! xx-info is-cross; then return; fi

run xx-apt info file
run xx-apt show file
assert_success
assert_line "Package: file:arm64"

run xx-apt info libc6-dev
run xx-apt show libc6-dev
assert_success
assert_line "Package: libc6-dev:arm64"

export XX_APT_PREFER_CROSS=1
run xx-apt info libc6-dev
run xx-apt show libc6-dev
assert_success
assert_line "Package: libc6-dev-arm64-cross"
unset XX_APT_PREFER_CROSS

run xx-apt info gcc
run xx-apt show gcc
assert_success
assert_line "Package: gcc-aarch64-linux-gnu"
}
Expand All @@ -72,21 +72,21 @@ load 'assert'
export TARGETARCH=arm
if ! xx-info is-cross; then return; fi

run xx-apt info file
run xx-apt show file
assert_success
assert_line "Package: file:armhf"

run xx-apt info libc6-dev
run xx-apt show libc6-dev
assert_success
assert_line "Package: libc6-dev:armhf"

export XX_APT_PREFER_CROSS=1
run xx-apt info libc6-dev
run xx-apt show libc6-dev
assert_success
assert_line "Package: libc6-dev-armhf-cross"
unset XX_APT_PREFER_CROSS

run xx-apt info gcc
run xx-apt show gcc
assert_success
assert_line "Package: gcc-arm-linux-gnueabihf"
}
Expand All @@ -95,22 +95,23 @@ load 'assert'
export TARGETARCH=arm
export TARGETVARIANT=v6
if ! xx-info is-cross; then return; fi
if [ "$(xx-info vendor)" = "ubuntu" ]; then skip; fi

run xx-apt info file
run xx-apt show file
assert_success
assert_line "Package: file:armel"

run xx-apt info libc6-dev
run xx-apt show libc6-dev
assert_success
assert_line "Package: libc6-dev:armel"

export XX_APT_PREFER_CROSS=1
run xx-apt info libc6-dev
run xx-apt show libc6-dev
assert_success
assert_line "Package: libc6-dev-armel-cross"
unset XX_APT_PREFER_CROSS

run xx-apt info gcc
run xx-apt show gcc
assert_success
assert_line "Package: gcc-arm-linux-gnueabi"
unset TARGETVARIANT
Expand All @@ -120,16 +121,16 @@ load 'assert'
export TARGETARCH=s390x
if ! xx-info is-cross; then return; fi

run xx-apt info file
run xx-apt show file
assert_success
assert_line "Package: file:s390x"

run xx-apt info libc6-dev
run xx-apt show libc6-dev
assert_success
assert_line "Package: libc6-dev:s390x"

export XX_APT_PREFER_CROSS=1
run xx-apt info libc6-dev
run xx-apt show libc6-dev
assert_success
assert_line "Package: libc6-dev-s390x-cross"
unset XX_APT_PREFER_CROSS
Expand All @@ -139,7 +140,7 @@ load 'assert'
return
fi

run xx-apt info gcc
run xx-apt show gcc
assert_success
assert_line "Package: gcc-s390x-linux-gnu"
}
Expand All @@ -148,16 +149,16 @@ load 'assert'
export TARGETARCH=ppc64le
if ! xx-info is-cross; then return; fi

run xx-apt info file
run xx-apt show file
assert_success
assert_line "Package: file:ppc64el"

run xx-apt info libc6-dev
run xx-apt show libc6-dev
assert_success
assert_line "Package: libc6-dev:ppc64el"

export XX_APT_PREFER_CROSS=1
run xx-apt info libc6-dev
run xx-apt show libc6-dev
assert_success
assert_line "Package: libc6-dev-ppc64el-cross"
unset XX_APT_PREFER_CROSS
Expand All @@ -167,7 +168,7 @@ load 'assert'
return
fi

run xx-apt info gcc
run xx-apt show gcc
assert_success
assert_line "Package: gcc-powerpc64le-linux-gnu"
}
Expand All @@ -176,21 +177,21 @@ load 'assert'
export TARGETARCH=386
if ! xx-info is-cross; then return; fi

run xx-apt info file
run xx-apt show file
assert_success
assert_line "Package: file:i386"

run xx-apt info libc6-dev
run xx-apt show libc6-dev
assert_success
assert_line "Package: libc6-dev:i386"

export XX_APT_PREFER_CROSS=1
run xx-apt info libc6-dev
run xx-apt show libc6-dev
assert_success
assert_line "Package: libc6-dev-i386-cross"
unset XX_APT_PREFER_CROSS

run xx-apt info gcc
run xx-apt show gcc
assert_success
assert_line "Package: gcc-i686-linux-gnu"
}
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 ebf3623

Please sign in to comment.