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 11, 2021
1 parent b42b6ac commit c53061f
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 41 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ jobs:
image: debian:sid
typ: debian
allow-failure: true
-
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
3 changes: 3 additions & 0 deletions base/test-go.bats
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ testHelloGO() {
}

@test "riscv64-hellogo" {
if ! supportRiscVGo; then
skip "RISC-V GO not supported"
fi
export TARGETARCH=riscv64
testHelloGO
}
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
3 changes: 3 additions & 0 deletions base/test-windres.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ load 'test_helper'
}

@test "basic" {
if ! supportRC; then
skip "llvm-rc not installed" # ubuntu 18.04
fi
export XX_WINDRES_DRYRUN=1
export TARGETPLATFORM=windows/arm
export XX_TMP_FILE_FIXED=/tmp/foo
Expand Down
10 changes: 9 additions & 1 deletion base/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,17 @@ supportRiscV() {
return 0
}

supportRiscVGo() {
go version | grep -E "1.14|1.15|1.16|1.17|1.18|1.19" >/dev/null 2>&1
}

supportRiscVCGo() {
if ! supportRiscV; then
return 1
fi
go version | egrep "1.16|1.17|1.18" >/dev/null 2>&1
go version | egrep -E "1.16|1.17|1.18|1.19" >/dev/null 2>&1
}

supportRC() {
command -v llvm-rc >/dev/null 2>&1
}
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
Loading

0 comments on commit c53061f

Please sign in to comment.