Skip to content

Commit

Permalink
xx-info: handle rhel arch
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Nov 14, 2021
1 parent 66016ca commit e83c048
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/bats-assert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ on:
paths:
- '.github/workflows/bats-assert.yml'
- 'util/bats-assert/**'
- '**/*.bats'
pull_request:
branches:
- 'master'
paths:
- '.github/workflows/bats-assert.yml'
- 'util/bats-assert/**'
- '**/*.bats'

jobs:
build:
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"
}
}

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

0 comments on commit e83c048

Please sign in to comment.