Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xx-info: handle rhel arch #52

Merged
merged 1 commit into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ jobs:
image: debian:sid
typ: debian
allow-failure: true
-
image: fedora:35
typ: rhel
allow-failure: false
steps:
-
name: Checkout
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ These commands return architecture names as used by specific tools to avoid conv
- `xx-info march` - Target machine architecture that is expected to match value of `uname -m`
- `xx-info alpine-arch` - Target architecture for [Alpine package repositories](https://pkgs.alpinelinux.org/packages)
- `xx-info debian-arch` - Target architecture for [Debian package repositories](https://www.debian.org/ports/)
- `xx-info pkg-arch` - Either alpine-arch or debian-arch depending on the context
- `xx-info rhel-arch` - Target architecture for [RPM package repositories](https://docs.fedoraproject.org/ro/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch01s03.html)
- `xx-info pkg-arch` - Either alpine-arch, debian-arch or rhel-arch depending on the context

#### Target triple

Expand Down
6 changes: 6 additions & 0 deletions base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ RUN --mount=type=cache,target=/pkg-cache \
apt update && apt install --no-install-recommends -y bats vim
WORKDIR /work

FROM ${TEST_BASE_IMAGE} AS test-base-rhel
RUN --mount=type=cache,target=/pkg-cache \
rm -rf /var/cache/yum && \
ln -s /pkg-cache /var/cache/yum && \
yum -y install bats vim
WORKDIR /work

FROM test-base-${TEST_BASE_TYPE} AS test
COPY --from=assert . .
Expand Down
47 changes: 47 additions & 0 deletions base/test-info-rhel.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bats

load "assert"

@test "vendor" {
assert_equal "fedora" "$(xx-info vendor)"
}

@test "rhel-arch" {
assert_equal "$(xx-info rhel-arch)" "$(xx-info pkg-arch)"
}

@test "amd64" {
assert_equal "x86_64" "$(TARGETPLATFORM=linux/amd64 xx-info pkg-arch)"
}

@test "aarch64" {
assert_equal "aarch64" "$(TARGETPLATFORM=linux/arm64 xx-info pkg-arch)"
}

@test "arm" {
assert_equal "armv7hl" "$(TARGETPLATFORM=linux/arm xx-info pkg-arch)"
}

@test "armv6" {
assert_equal "armv6hl" "$(TARGETPLATFORM=linux/arm/v6 xx-info pkg-arch)"
}

@test "armv5" {
assert_equal "armv5tel" "$(TARGETPLATFORM=linux/arm/v5 xx-info pkg-arch)"
}

@test "386" {
assert_equal "i386" "$(TARGETPLATFORM=linux/386 xx-info pkg-arch)"
}

@test "ppc64le" {
assert_equal "ppc64le" "$(TARGETPLATFORM=linux/ppc64le xx-info pkg-arch)"
}

@test "s390x" {
assert_equal "s390x" "$(TARGETPLATFORM=linux/s390x xx-info pkg-arch)"
}

@test "riscv64" {
assert_equal "riscv64" "$(TARGETPLATFORM=linux/riscv64 xx-info pkg-arch)"
}
19 changes: 18 additions & 1 deletion base/xx-info
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
: "${XX_ALPINE_ARCH=unknown}"
# https://www.debian.org/ports/
: "${XX_DEBIAN_ARCH=unknown}"
# https://docs.fedoraproject.org/ro/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch01s03.html
: "${XX_RHEL_ARCH=unknown}"
: "${XX_TRIPLE=unknown-unknown-none}"
: "${XX_VENDOR=unknown}"
: "${XX_LIBC=}"
Expand All @@ -29,6 +31,7 @@ Commands:
march Print target machine architecture, uname -m
os Print target operating system (linux,darwin,windows,wasi)
pkg-arch Print either alpine-arch or debian-arch
rhel-arch Print target architecture for RPM package repositories
sysroot Print sysroot directory for target architecture
triple Print target triple in arch[-vendor]-os-abi form
vendor Print vendor part of target triple
Expand Down Expand Up @@ -107,7 +110,7 @@ fi

vendor=""

if [ "$XX_VENDOR" != "unknown" ] && [ "$XX_VENDOR" != "debian" ]; then
if [ "$XX_VENDOR" != "unknown" ] && [ "$XX_VENDOR" != "debian" ] && [ "$XX_VENDOR" != "rhel" ] && [ "$XX_VENDOR" != "fedora" ] && [ "$XX_VENDOR" != "centos" ] && [ "$XX_VENDOR" != "rocky" ]; then
vendor="-${XX_VENDOR}"
fi

Expand Down Expand Up @@ -182,6 +185,7 @@ case "$TARGETARCH" in
XX_MARCH="x86_64"
XX_DEBIAN_ARCH="amd64"
XX_ALPINE_ARCH="x86_64"
XX_RHEL_ARCH="x86_64"
XX_TRIPLE="x86_64${vendor}-linux-${XX_LIBC}"
if [ "$TARGETOS" = "darwin" ]; then
XX_TRIPLE="x86_64${vendor}-macos${MACOSX_VERSION_MIN}"
Expand All @@ -193,6 +197,7 @@ case "$TARGETARCH" in
XX_MARCH="aarch64"
XX_DEBIAN_ARCH="arm64"
XX_ALPINE_ARCH="aarch64"
XX_RHEL_ARCH="aarch64"
XX_TRIPLE="aarch64${vendor}-linux-${XX_LIBC}"
if [ "$TARGETOS" = "darwin" ]; then
XX_MARCH="arm64"
Expand All @@ -205,6 +210,7 @@ case "$TARGETARCH" in
XX_MARCH="armv7l"
XX_DEBIAN_ARCH="armhf"
XX_ALPINE_ARCH="armv7"
XX_RHEL_ARCH="armv7hl"
XX_TRIPLE="arm${vendor}-linux-${XX_LIBC}eabihf"
if [ "$XX_VENDOR" = "alpine" ]; then
XX_TRIPLE="armv7${vendor}-linux-${XX_LIBC}eabihf"
Expand All @@ -213,6 +219,7 @@ case "$TARGETARCH" in
XX_MARCH="armv6l"
XX_DEBIAN_ARCH="armel"
XX_ALPINE_ARCH="armhf"
XX_RHEL_ARCH="armv6hl"
XX_TRIPLE="arm${vendor}-linux-${XX_LIBC}eabi"
if [ "$XX_VENDOR" = "alpine" ]; then
XX_TRIPLE="armv6${vendor}-linux-${XX_LIBC}eabihf"
Expand All @@ -222,6 +229,7 @@ case "$TARGETARCH" in
XX_MARCH="armv5l"
XX_DEBIAN_ARCH="armel"
XX_ALPINE_ARCH="armel" # alpine does not actually support v5
XX_RHEL_ARCH="armv5tel"
XX_TRIPLE="arm${vendor}-linux-${XX_LIBC}eabi"
if [ "$XX_VENDOR" = "alpine" ]; then
XX_TRIPLE="armv5${vendor}-linux-${XX_LIBC}eabi"
Expand All @@ -236,24 +244,28 @@ case "$TARGETARCH" in
XX_MARCH="riscv64"
XX_DEBIAN_ARCH="riscv64"
XX_ALPINE_ARCH="riscv64"
XX_RHEL_ARCH="riscv64"
XX_TRIPLE="riscv64${vendor}-linux-${XX_LIBC}"
;;
"ppc64le")
XX_MARCH="ppc64le"
XX_DEBIAN_ARCH="ppc64el"
XX_ALPINE_ARCH="ppc64le"
XX_RHEL_ARCH="ppc64le"
XX_TRIPLE="powerpc64le${vendor}-linux-${XX_LIBC}"
;;
"s390x")
XX_MARCH="s390x"
XX_DEBIAN_ARCH="s390x"
XX_ALPINE_ARCH="s390x"
XX_RHEL_ARCH="s390x"
XX_TRIPLE="s390x${vendor}-linux-${XX_LIBC}"
;;
"386")
XX_MARCH="i386"
XX_DEBIAN_ARCH="i386"
XX_ALPINE_ARCH="x86"
XX_RHEL_ARCH="i386"
XX_TRIPLE="i686${vendor}-linux-${XX_LIBC}"
if [ "$XX_VENDOR" = "alpine" ]; then
XX_TRIPLE="i586${vendor}-linux-${XX_LIBC}"
Expand All @@ -269,6 +281,8 @@ if [ "$XX_VENDOR" = "debian" ]; then
XX_PKG_ARCH=${XX_DEBIAN_ARCH}
elif [ "$XX_VENDOR" = "alpine" ]; then
XX_PKG_ARCH=${XX_ALPINE_ARCH}
elif [ "$XX_VENDOR" = "rhel" ] || [ "$XX_VENDOR" = "fedora" ] || [ "$XX_VENDOR" = "centos" ] || [ "$XX_VENDOR" = "rocky" ]; then
XX_PKG_ARCH=${XX_RHEL_ARCH}
fi

case "$1" in
Expand Down Expand Up @@ -297,6 +311,9 @@ case "$1" in
"alpine-arch")
echo $XX_ALPINE_ARCH
;;
"rhel-arch")
echo $XX_RHEL_ARCH
;;
"pkg-arch")
echo $XX_PKG_ARCH
;;
Expand Down
11 changes: 10 additions & 1 deletion docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ target "meta-helper" {
}

group "test" {
targets = ["test-alpine", "test-debian"]
targets = ["test-alpine", "test-debian", "test-rhel"]
}

target "test-base" {
Expand All @@ -28,6 +28,15 @@ target "test-debian" {
}
}

target "test-rhel" {
inherits = ["test-base"]
args = {
TEST_BASE_TYPE = "rhel"
TEST_BASE_IMAGE = "fedora:35"
TEST_CMDS = "info"
Copy link
Collaborator Author

@crazy-max crazy-max Nov 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line in a follow-up when windres is hanlded for rhel:

#24 [test  6/11] RUN --mount=type=cache,target=/pkg-cache     [ "${TEST_CMDS:-windres}" = "${TEST_CMDS#*windres}" ] && exit 0; ./test-windres.bats
#24 0.173 1..3
#24 0.254 not ok 1 invalid
#24 0.254 # (from function `xxrun' in file test_helper.bash, line 54,
#24 0.254 #  from function `add' in file test_helper.bash, line 7,
#24 0.254 #  in test file test-windres.bats, line 7)
#24 0.255 #   `add llvm' failed with status 127
#24 0.255 # /work/test_helper.bash: line 54: apt: command not found
#24 0.319 not ok 2 basic
#24 0.319 # (from function `assert_success' in file bats-assert/src/assert.bash, line 114,
#24 0.319 #  in test file test-windres.bats, line 20)
#24 0.319 #   `assert_success' failed
#24 0.319 #
#24 0.319 # -- command failed --
#24 0.319 # status : 1
#24 0.319 # output : llvm-rc not installed
#24 0.319 # --
#24 0.320 #
#24 0.359 ok 3 clean
#24 ERROR: process "/bin/sh -c [ \"${TEST_CMDS:-windres}\" = \"${TEST_CMDS#*windres}\" ] && exit 0; ./test-windres.bats" did not complete successfully: exit code: 1
------
 > [test  6/11] RUN --mount=type=cache,target=/pkg-cache     [ "${TEST_CMDS:-windres}" = "${TEST_CMDS#*windres}" ] && exit 0; ./test-windres.bats:
#24 0.319 # (from function `assert_success' in file bats-assert/src/assert.bash, line 114,
#24 0.319 #  in test file test-windres.bats, line 20)
#24 0.319 #   `assert_success' failed
#24 0.319 #
#24 0.319 # -- command failed --
#24 0.319 # status : 1
#24 0.319 # output : llvm-rc not installed
#24 0.319 # --
#24 0.320 #
#24 0.359 ok 3 clean

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a check for this in https://github.com/tonistiigi/xx/pull/49/files#diff-97b6828de99e6a75768dba426569ce1a89f0e32542b0ea9c7a3349f47a99263bR16 . Does centos really ship with very old llvm or why isn't this installed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does centos really ship with very old llvm or why isn't this installed?

I have not yet updated the test_helper.bash to include yum/dnf. I can add the add/del implementation so the test would pass but we might also need to add xx-yum or xx-dnf.

Copy link
Collaborator Author

@crazy-max crazy-max Nov 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also centos and rhel don't have the bats pkg available in their main repo so I might need to fix sources for the test-base-rhel target in the Dockerfile.

}
}

group "validate" {
targets = ["shfmt-validate", "shellcheck"]
}
Expand Down