Skip to content

Commit

Permalink
wip: add support for xx-dnf
Browse files Browse the repository at this point in the history
  • Loading branch information
panekj committed Feb 5, 2024
1 parent 4880178 commit a44a91d
Show file tree
Hide file tree
Showing 8 changed files with 460 additions and 3 deletions.
10 changes: 8 additions & 2 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ variable "TEST_BASE_TYPE" {
}

variable "TEST_BASE_IMAGE" {
default = TEST_BASE_TYPE == "alpine" ? "alpine:3.19" : TEST_BASE_TYPE == "debian" ? "debian:bookworm" : null
default = TEST_BASE_TYPE == "alpine" ? "alpine:3.19" : TEST_BASE_TYPE == "debian" ? "debian:bookworm" : TEST_BASE_TYPE == "rhel" ? "fedora:39" : null
}

variable "DEV_SDK_PLATFORM" {
Expand Down Expand Up @@ -55,6 +55,7 @@ group "test" {
"test-info",
"test-apk",
"test-apt",
"test-dnf",
"test-verify",
"test-clang",
"test-go",
Expand All @@ -77,6 +78,11 @@ target "test-apt" {
target = "test-apt"
}

target "test-dnf" {
inherits = ["test-base"]
target = "test-dnf"
}

target "test-verify" {
inherits = ["test-base"]
target = "test-verify"
Expand Down Expand Up @@ -356,4 +362,4 @@ target "sigtool" {
"linux/arm64",
"linux/arm/v7",
]
}
}
4 changes: 4 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ FROM test-base AS test-apk
COPY test-apk.bats .
RUN --mount=type=cache,target=/pkg-cache,sharing=locked [ ! -f /etc/alpine-release ] || ./test-apk.bats

FROM test-base AS test-dnf
COPY test-dnf.bats .
RUN --mount=type=cache,target=/pkg-cache,sharing=locked [ ! -f /etc/fedora-release ] || ./test-dnf.bats

FROM test-base AS test-verify
COPY test-verify.bats .
RUN --mount=type=cache,target=/pkg-cache,sharing=locked ./test-verify.bats
Expand Down
230 changes: 230 additions & 0 deletions src/test-dnf.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
#!/usr/bin/env bats

load 'assert'

@test "no_cmd" {
run xx-dnf
assert_failure
assert_output --partial "usage: dnf [options] COMMAND"
}

@test "native" {
run xx-dnf info file
assert_success
assert_line "Name : file"

run xx-dnf info glibc-devel
assert_success
assert_line "Name : glibc-devel"

run xx-dnf info gcc
assert_success
assert_line "Name : gcc"
}

@test "essentials" {
run xx-dnf info xx-c-essentials
assert_success

run xx-dnf info xx-cxx-essentials
assert_success
}

@test "amd64" {
export TARGETARCH=amd64
if ! xx-info is-cross; then skip; fi

run xx-dnf info file
assert_success
assert_line "Architecture : x86_64"

run xx-dnf info glibc-devel
assert_success
assert_line "Architecture : x86_64"

export XX_dnf_PREFER_CROSS=1
run xx-dnf info glibc-devel
assert_success
assert_line "Package: glibc-devel-amd64-cross"
unset XX_dnf_PREFER_CROSS

run xx-dnf info gcc
assert_success
assert_line "Architecture : x86_64"
}

@test "arm64" {
export TARGETARCH=arm64
if ! xx-info is-cross; then return; fi

run xx-dnf info file
assert_success
assert_line "Architecture : aarch64"

run xx-dnf info glibc-devel
assert_success
assert_line "Architecture : aarch64"

export XX_dnf_PREFER_CROSS=1
run xx-dnf info glibc-devel
assert_success
assert_line "Name: glibc-devel-arm64-cross"
unset XX_dnf_PREFER_CROSS

run xx-dnf info gcc
assert_success
assert_line "Architecture : aarch64"
}

@test "arm" {
export TARGETARCH=arm
if ! xx-info is-cross; then return; fi

run xx-dnf info file
assert_success
assert_line "Package: file:armhf"

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

export XX_dnf_PREFER_CROSS=1
run xx-dnf info libc6-dev
assert_success
assert_line "Package: libc6-dev-armhf-cross"
unset XX_dnf_PREFER_CROSS

run xx-dnf info gcc
assert_success
assert_line "Package: gcc-arm-linux-gnueabihf"
}

@test "armv6" {
export TARGETARCH=arm
export TARGETVARIANT=v6
if ! xx-info is-cross; then return; fi
if [ "$(xx-info vendor)" = "ubuntu" ]; then skip; fi

run xx-dnf info file
assert_success
assert_line "Package: file:armel"

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

export XX_dnf_PREFER_CROSS=1
run xx-dnf info libc6-dev
assert_success
assert_line "Package: libc6-dev-armel-cross"
unset XX_dnf_PREFER_CROSS

run xx-dnf info gcc
assert_success
assert_line "Package: gcc-arm-linux-gnueabi"
unset TARGETVARIANT
}

@test "s390x" {
export TARGETARCH=s390x
if ! xx-info is-cross; then return; fi

run xx-dnf info file
assert_success
assert_line "Package: file:s390x"

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

export XX_dnf_PREFER_CROSS=1
run xx-dnf info libc6-dev
assert_success
assert_line "Package: libc6-dev-s390x-cross"
unset XX_dnf_PREFER_CROSS

# buster has no gcc package for arm64
if [ "$(uname -m)" == "aarch64" ] && [ "$(cat /etc/debian_version | cut -d. -f 1)" = "10" ]; then
return
fi

run xx-dnf info gcc
assert_success
assert_line "Package: gcc-s390x-linux-gnu"
}

@test "ppc64le" {
export TARGETARCH=ppc64le
if ! xx-info is-cross; then return; fi

run xx-dnf info file
assert_success
assert_line "Package: file:ppc64el"

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

export XX_dnf_PREFER_CROSS=1
run xx-dnf info libc6-dev
assert_success
assert_line "Package: libc6-dev-ppc64el-cross"
unset XX_dnf_PREFER_CROSS

# buster has no gcc package for arm64
if [ "$(uname -m)" == "aarch64" ] && [ "$(cat /etc/debian_version | cut -d. -f 1)" = "10" ]; then
return
fi

run xx-dnf info gcc
assert_success
assert_line "Package: gcc-powerpc64le-linux-gnu"
}

@test "386" {
export TARGETARCH=386
if ! xx-info is-cross; then return; fi

run xx-dnf info file
assert_success
assert_line "Package: file:i386"

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

export XX_dnf_PREFER_CROSS=1
run xx-dnf info libc6-dev
assert_success
assert_line "Package: libc6-dev-i386-cross"
unset XX_dnf_PREFER_CROSS

run xx-dnf info gcc
assert_success
assert_line "Package: gcc-i686-linux-gnu"
}

@test "skip-nolinux" {
export TARGETOS="darwin"
export TARGETARCH="amd64"
run xx-dnf install foo
assert_success
unset TARGETOS
unset TARGETARCH
}

@test "checkpkg" {
run dnf show wget
assert_success
run dnf show wget-notexist
assert_failure
}

@test "print-source-file" {
run xx-dnf --print-source-file
assert_success
assert_output --partial "/etc/dnf/sources.list"

run test -e "$(xx-dnf --print-source-file)"
assert_success
}
8 changes: 8 additions & 0 deletions src/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
add() {
if [ -f /etc/alpine-release ]; then
apk add "$@"
elif [ -f /etc/fedora-release ]; then
xxrun dnf install "$@"
else
xxrun apt install -y --no-install-recommends "$@"
fi
Expand All @@ -11,6 +13,8 @@ add() {
del() {
if [ -f /etc/alpine-release ]; then
apk del "$@" 2>/dev/null || true
elif [ -f /etc/fedora-release ]; then
xxrun dnf remove "$@"
else
xxrun apt remove --autoremove -y "$@" 2>/dev/null || true
fi
Expand All @@ -19,6 +23,8 @@ del() {
xxadd() {
if [ -f /etc/alpine-release ]; then
xx-apk add "$@"
elif [ -f /etc/fedora-release ]; then
xxrun xx-dnf install "$@"
else
xxrun xx-apt install -y --no-install-recommends "$@"
fi
Expand All @@ -27,6 +33,8 @@ xxadd() {
xxdel() {
if [ -f /etc/alpine-release ]; then
xx-apk del "$@" 2>/dev/null || true
elif [ -f /etc/fedora-release ]; then
xxrun xx-dnf remove "$@"
else
xxrun xx-apt remove -y --autoremove "$@" 2>/dev/null || true
fi
Expand Down
3 changes: 3 additions & 0 deletions src/xx-cargo
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ if [ ! -f "$done_file" ]; then
elif [ -f /etc/alpine-release ]; then
# XX_VENDOR overrided to match the distrib one to install packages
XX_VENDOR=$vendor execSilent xx-apk add rust-stdlib
elif [ -f /etc/fedora-release ]; then
# XX_VENDOR overrided to match the distrib one to install packages
XX_VENDOR=$vendor execSilent xx-dnf install --assumeyes rust-std-static
else
# XX_VENDOR overrided to match the distrib one to install packages
XX_VENDOR=$vendor execSilent xx-apt-get install -y libstd-rust-dev
Expand Down
29 changes: 28 additions & 1 deletion src/xx-cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ installwget() {
if command -v apk >/dev/null 2>/dev/null; then
apk add wget >/dev/null 2>/dev/null
fi
if command -v dnf >/dev/null 2>/dev/null; then
dnf install wget >/dev/null 2>/dev/null
fi
}

writexcrun() {
Expand Down Expand Up @@ -464,7 +467,20 @@ export PKG_CONFIG_LIBDIR=/${target}/usr/lib/pkgconfig/
exec pkg-config "\$@"
EOT
chmod +x "/usr/bin/${target}-pkg-config"
elif [ -f /etc/fedora-release ]; then
config="${config} --sysroot=/${target}/"

if [ -n "$is_bfd" ]; then
config="${config} -Wl,-rpath-link,/${target}/usr/lib"
fi

cat <<EOT >"/usr/bin/${target}-pkg-config"
#!/usr/bin/env sh
export PKG_CONFIG_SYSROOT_DIR=/${target}
export PKG_CONFIG_LIBDIR=/${target}/usr/lib/pkgconfig/
exec pkg-config "\$@"
EOT
chmod +x "/usr/bin/${target}-pkg-config"
fi
elif [ ! -f "/usr/bin/${target}-pkg-config" ] && [ ! -h "/usr/bin/${target}-pkg-config" ]; then
ln -s pkg-config "/usr/bin/${target}-pkg-config"
Expand Down Expand Up @@ -530,6 +546,17 @@ EOT
fi
fi

if [ -f /etc/fedora-release ]; then
# if vendor is not fedora then sysroot needs to be linked to the custom vendor
fedoratriple=$(echo "$target" | sed s/-[[:alpha:]][[:alpha:]]*-/-fedora-/ | sed s/^riscv64gc-/riscv64-/)
if [ "$target" != "$fedoratriple" ]; then
# shellcheck disable=SC2044
for f in $(find / -type d -name "$fedoratriple"); do
ln -s "$fedoratriple" "$(dirname "$f")/$target"
done
fi
fi

if [ "${targetos}" = "darwin" ]; then
if ! command -v xcrun 2>/dev/null >/dev/null; then
writexcrun
Expand Down Expand Up @@ -637,7 +664,7 @@ if [ -n "${printSysroot}" ]; then
setup

if xx-info is-cross; then
if [ -f "/etc/alpine-release" ]; then
if [ -f "/etc/alpine-release" ] || [ -f "/etc/fedora-release" ]; then
echo "/${target}/"
exit 0
fi
Expand Down
Loading

0 comments on commit a44a91d

Please sign in to comment.