Skip to content

Commit

Permalink
wip: add support for xx-dnf
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Panek <[email protected]>
  • Loading branch information
panekj committed Jun 17, 2024
1 parent 7a5c741 commit ba4510f
Show file tree
Hide file tree
Showing 8 changed files with 487 additions and 5 deletions.
12 changes: 9 additions & 3 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 @@ -41,7 +41,7 @@ target "test-rhel" {
inherits = ["test-src"]
args = {
TEST_BASE_TYPE = "rhel"
TEST_BASE_IMAGE = "fedora:35"
TEST_BASE_IMAGE = "fedora:40"
}
}

Expand All @@ -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",
]
}
}
11 changes: 10 additions & 1 deletion src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ COPY xx-* /out/
RUN ln -s xx-cc /out/xx-clang && \
ln -s xx-cc /out/xx-clang++ && \
ln -s xx-cc /out/xx-c++ && \
ln -s xx-apt /out/xx-apt-get
ln -s xx-apt /out/xx-apt-get && \
ln -s xx-dnf /out/xx-yum && \
ln -s xx-dnf /out/xx-microdnf && \
ln -s xx-dnf /out/xx-dnf5 && \
ln -s xx-dnf /out/xx-dnf4 && \
ln -s xx-dnf /out/xx-dnf-3

# xx builds the xx image
FROM scratch AS xx
Expand Down Expand Up @@ -83,6 +88,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
Loading

0 comments on commit ba4510f

Please sign in to comment.