Detect Arch Support (#40)
* Provide helper to detect the current architecture
* Use new 'detect-arch' helper when building JS
* build.sh: Ensure package directories are writable to user 'jenkins'
* Makefile: Trivial: Correct DIST name for ubuntu-bionic
diff --git a/Makefile b/Makefile
index d41f77d..958bcaa 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,15 @@
export DEBFULLNAME="CouchDB Developers"
export DEBEMAIL="dev@couchdb.apache.org"
+# Default package directory (over-written for RPM based builds)
+PKGDIR=$(COUCHDIR)
+
+ifeq ($(shell arch),aarch64)
+PKGARCH=arm64
+else
+PKGARCH=$(shell arch)
+endif
+
# Debian default
debian: find-couch-dist copy-debian update-changelog dpkg lintian copy-pkgs
@@ -68,11 +77,12 @@
# Ubuntu 18.04
ubuntu-bionic: PLATFORM=bionic
-ubuntu-bionic: DIST=ubuntu-bioniC
+ubuntu-bionic: DIST=ubuntu-bionic
ubuntu-bionic: bionic
bionic: debian
# RPM default
+centos: PKGDIR=../rpmbuild/RPMS/$(PKGARCH)
centos: find-couch-dist link-couch-dist build-rpm copy-pkgs
centos-6: DIST=centos-6
@@ -153,11 +163,11 @@
export HOME=$(HOME) && cd ../rpmbuild && rpmbuild --verbose -bb SPECS/couchdb.spec --define '_version $(VERSION)'
# ######################################
+
copy-pkgs:
- -chmod a+rwx ../rpmbuild/RPMS/x86_64/couchdb-* ../couchdb/couchdb_* 2>/dev/null
- -mkdir -p pkgs/couch/$(DIST) && chmod 777 pkgs/couch/$(DIST)
- -cp ../rpmbuild/RPMS/x86_64/couchdb-* pkgs/couch/$(DIST) 2>/dev/null
- -cp ../couchdb/couchdb_* pkgs/couch/$(DIST) 2>/dev/null
+ chmod a+rwx $(PKGDIR)/couchdb*
+ mkdir -p pkgs/couch/$(DIST) && chmod 777 pkgs/couch/$(DIST)
+ cp $(PKGDIR)/couchdb* pkgs/couch/$(DIST)
clean:
rm -rf parts prime stage js/build
diff --git a/bin/build-js.sh b/bin/build-js.sh
index 7968867..36d6e33 100755
--- a/bin/build-js.sh
+++ b/bin/build-js.sh
@@ -27,7 +27,6 @@
# This works if we're not called through a symlink
# otherwise, see https://stackoverflow.com/questions/59895/
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-ARCH=$(arch)
# Check if running as root
if [[ ${EUID} -ne 0 ]]; then
@@ -36,6 +35,7 @@
exit 1
fi
+. ${SCRIPTPATH}/detect-arch.sh
. ${SCRIPTPATH}/detect-os.sh
cd ${SCRIPTPATH}/..
diff --git a/bin/detect-arch.sh b/bin/detect-arch.sh
new file mode 100755
index 0000000..60cb779
--- /dev/null
+++ b/bin/detect-arch.sh
@@ -0,0 +1,73 @@
+#!/usr/bin/env bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# This shell script detects which architecture we're currently
+# operating on, and sets an environment variable the calling
+# script can use.
+
+# stop on error
+set -e
+
+case "${OSTYPE}" in
+ linux*)
+ if [ -x /usr/bin/arch -o -x /bin/arch ]; then
+ export ARCH=`arch`
+ fi
+
+ if [ -x /usr/bin/uname -o -x /bin/uname ]; then
+ export ARCH=`uname -m`
+ fi
+
+ if [ "$ARCH" == "" ]; then
+ echo "$0 uses 'arch' or 'uname' which appear to be missing"
+ exit 1
+ fi
+ ;;
+ *bsd*)
+ # TODO
+ echo "Currently unable to detect Arch on BSD"
+ exit 1
+ ;;
+ darwin*)
+ # TODO
+ echo "Currently unable to detect Arch on macOS (OSX)"
+ exit 1
+ ;;
+ solaris*)
+ # TODO
+ echo "Currently unable to detect Arch on Solaris-like OS"
+ exit 1
+ ;;
+ msys*)
+ # TODO
+ echo "Currently unable to detect Arch on Windows (msys)"
+ exit 1
+ ;;
+ cygwin*)
+ # TODO
+ echo "Currently unable to detect Arch on Windows (cygwin)"
+ exit 1
+ ;;
+ *)
+ echo "Unknown OS detected: ${OSTYPE}"
+ exit 1
+ ;;
+esac
+
+echo "Detected architecture: $ARCH"
diff --git a/build.sh b/build.sh
index 6cc59ac..82d843d 100755
--- a/build.sh
+++ b/build.sh
@@ -153,6 +153,8 @@
}
build-couch() {
+ # We will be changing user to 'jenkins' - ensure it has write permissions
+ chmod a+rwx pkgs pkgs/couch pkgs/js
# $1 is plat, $2 is the optional path to a dist tarball
docker run \
--mount type=bind,src=${SCRIPTPATH},dst=/home/jenkins/couchdb-pkg \