From 25bdc8b12d517e398316bfd22bda0edcf099e2b4 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Tue, 9 Nov 2021 23:17:56 -0800 Subject: [PATCH] xx-apt: add special case for ubuntu repo switch Signed-off-by: Tonis Tiigi --- .github/workflows/build.yml | 8 +++++ base/test-apt.bats | 63 +++++++++++++++++++------------------ base/test-clang.bats | 2 ++ base/test-go.bats | 3 ++ base/test-info-debian.bats | 8 ++++- base/test-windres.bats | 3 ++ base/test_helper.bash | 10 +++++- base/xx-apt | 62 ++++++++++++++++++++++++++++++++---- base/xx-info | 4 +-- 9 files changed, 122 insertions(+), 41 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1032324..7beaa2c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -63,6 +63,14 @@ jobs: image: fedora:35 typ: rhel allow-failure: false + - + image: ubuntu:20.04 + typ: debian + allow-failure: false + - + image: ubuntu:21.10 + typ: debian + allow-failure: false steps: - name: Checkout diff --git a/base/test-apt.bats b/base/test-apt.bats index c2d0318..997a9b3 100755 --- a/base/test-apt.bats +++ b/base/test-apt.bats @@ -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" } @@ -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" } @@ -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" } @@ -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" } @@ -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 @@ -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 @@ -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" } @@ -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 @@ -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" } @@ -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" } diff --git a/base/test-clang.bats b/base/test-clang.bats index 8e5a61e..fbef8fb 100755 --- a/base/test-clang.bats +++ b/base/test-clang.bats @@ -211,6 +211,7 @@ testBuildHello() { } @test "armv6-c-lld" { + if [ "$(xx-info vendor)" = "ubuntu" ]; then skip; fi export TARGETARCH=arm export TARGETVARIANT=v6 testHelloCLLD @@ -265,6 +266,7 @@ testBuildHello() { } @test "armv6-c++-lld" { + if [ "$(xx-info vendor)" = "ubuntu" ]; then skip; fi export TARGETARCH=arm export TARGETVARIANT=v6 testHelloCPPLLD diff --git a/base/test-go.bats b/base/test-go.bats index 751edb8..a57d57e 100755 --- a/base/test-go.bats +++ b/base/test-go.bats @@ -149,6 +149,9 @@ testHelloGO() { } @test "riscv64-hellogo" { + if ! supportRiscVGo; then + skip "RISC-V GO not supported" + fi export TARGETARCH=riscv64 testHelloGO } diff --git a/base/test-info-debian.bats b/base/test-info-debian.bats index 6314653..eb05d13 100755 --- a/base/test-info-debian.bats +++ b/base/test-info-debian.bats @@ -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" { diff --git a/base/test-windres.bats b/base/test-windres.bats index b06bfc7..f9e2341 100755 --- a/base/test-windres.bats +++ b/base/test-windres.bats @@ -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 diff --git a/base/test_helper.bash b/base/test_helper.bash index c87498d..f50f8b5 100644 --- a/base/test_helper.bash +++ b/base/test_helper.bash @@ -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 } diff --git a/base/xx-apt b/base/xx-apt index f2fcc36..a4c2871 100755 --- a/base/xx-apt +++ b/base/xx-apt @@ -49,6 +49,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=$# @@ -84,13 +128,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 @@ -100,11 +155,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 diff --git a/base/xx-info b/base/xx-info index bd742fe..e067e91 100755 --- a/base/xx-info +++ b/base/xx-info @@ -110,7 +110,7 @@ fi vendor="" -if [ "$XX_VENDOR" != "unknown" ] && [ "$XX_VENDOR" != "debian" ] && [ "$XX_VENDOR" != "rhel" ] && [ "$XX_VENDOR" != "fedora" ] && [ "$XX_VENDOR" != "centos" ] && [ "$XX_VENDOR" != "rocky" ]; then +if [ "$XX_VENDOR" != "unknown" ] && [ "$XX_VENDOR" != "debian" ] && [ "$XX_VENDOR" != "rhel" ] && [ "$XX_VENDOR" != "fedora" ] && [ "$XX_VENDOR" != "centos" ] && [ "$XX_VENDOR" != "rocky" ] && [ "$XX_VENDOR" != "ubuntu" ]; then vendor="-${XX_VENDOR}" fi @@ -277,7 +277,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}