|
|
@@ -0,0 +1,163 @@
|
|
|
+#!/bin/sh
|
|
|
+set -eu
|
|
|
+
|
|
|
+repository_root=${RIGFORGE_ROOT:-/workspace}
|
|
|
+state_file="$repository_root/config/desired-state.yaml"
|
|
|
+artifact_directory="$repository_root/artifacts/sooperlooper/arm64"
|
|
|
+work_directory=
|
|
|
+temporary_directory=
|
|
|
+previous_directory="$artifact_directory/previous"
|
|
|
+
|
|
|
+cleanup() {
|
|
|
+ if [ -n "$work_directory" ]; then
|
|
|
+ rm -rf "$work_directory"
|
|
|
+ fi
|
|
|
+ if [ -n "$temporary_directory" ]; then
|
|
|
+ rm -rf "$temporary_directory"
|
|
|
+ fi
|
|
|
+ if [ ! -e "$artifact_directory/current" ] && [ -e "$previous_directory" ]; then
|
|
|
+ mv "$previous_directory" "$artifact_directory/current"
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+trap cleanup EXIT
|
|
|
+trap 'exit 129' HUP
|
|
|
+trap 'exit 130' INT
|
|
|
+trap 'exit 143' TERM
|
|
|
+
|
|
|
+case "$(dpkg --print-architecture)" in
|
|
|
+ arm64) ;;
|
|
|
+ *) printf '%s\n' "This build task requires an ARM64 container." >&2; exit 1 ;;
|
|
|
+esac
|
|
|
+
|
|
|
+python3 - "$repository_root" "$state_file" <<'PY'
|
|
|
+import sys
|
|
|
+from pathlib import Path
|
|
|
+
|
|
|
+import yaml
|
|
|
+
|
|
|
+repository_root = Path(sys.argv[1])
|
|
|
+sys.path.insert(0, str(repository_root / "scripts"))
|
|
|
+from validate_desired_state import validate_state
|
|
|
+
|
|
|
+state_path = Path(sys.argv[2])
|
|
|
+with state_path.open(encoding="utf-8") as stream:
|
|
|
+ state = yaml.safe_load(stream)
|
|
|
+errors = validate_state(state)
|
|
|
+if errors:
|
|
|
+ raise SystemExit("Invalid desired state: " + "; ".join(errors))
|
|
|
+PY
|
|
|
+
|
|
|
+set -- $(python3 - "$state_file" <<'PY'
|
|
|
+import sys
|
|
|
+import yaml
|
|
|
+
|
|
|
+with open(sys.argv[1], encoding="utf-8") as stream:
|
|
|
+ source = yaml.safe_load(stream)["deployment"]["sooperlooper"]
|
|
|
+print(source["source_url"])
|
|
|
+print(source["tag"])
|
|
|
+PY
|
|
|
+)
|
|
|
+source_url=$1
|
|
|
+tag=$2
|
|
|
+
|
|
|
+mkdir -p "$artifact_directory"
|
|
|
+work_directory=$(mktemp -d /tmp/sooperlooper-build.XXXXXX)
|
|
|
+temporary_directory=$(mktemp -d "$artifact_directory/.build.XXXXXX")
|
|
|
+git clone --no-checkout "$source_url" "$work_directory/source"
|
|
|
+git -C "$work_directory/source" checkout --detach "refs/tags/$tag"
|
|
|
+source_commit=$(git -C "$work_directory/source" rev-parse HEAD)
|
|
|
+
|
|
|
+cd "$work_directory/source"
|
|
|
+./autogen.sh
|
|
|
+./configure --without-gui --prefix=/usr
|
|
|
+
|
|
|
+python3 - "$work_directory/source/libs/pbd/pbd/atomic.h" "$work_directory/source/src/atomic.h" <<'PY'
|
|
|
+import sys
|
|
|
+from pathlib import Path
|
|
|
+
|
|
|
+replacement = '''#if defined(__aarch64__)
|
|
|
+
|
|
|
+typedef struct { volatile int counter; } atomic_t;
|
|
|
+#define ATOMIC_INIT(i) { (i) }
|
|
|
+#define atomic_read(v) __atomic_load_n(&(v)->counter, __ATOMIC_SEQ_CST)
|
|
|
+#define atomic_set(v, i) __atomic_store_n(&(v)->counter, (i), __ATOMIC_SEQ_CST)
|
|
|
+static __inline__ void atomic_add(int i, atomic_t *v) { __atomic_add_fetch(&v->counter, i, __ATOMIC_SEQ_CST); }
|
|
|
+static __inline__ int atomic_add_return(int i, atomic_t *v) { return __atomic_add_fetch(&v->counter, i, __ATOMIC_SEQ_CST); }
|
|
|
+static __inline__ int atomic_add_negative(int i, atomic_t *v) { return __atomic_add_fetch(&v->counter, i, __ATOMIC_SEQ_CST) < 0; }
|
|
|
+static __inline__ void atomic_sub(int i, atomic_t *v) { __atomic_sub_fetch(&v->counter, i, __ATOMIC_SEQ_CST); }
|
|
|
+static __inline__ int atomic_sub_return(int i, atomic_t *v) { return __atomic_sub_fetch(&v->counter, i, __ATOMIC_SEQ_CST); }
|
|
|
+static __inline__ void atomic_inc(atomic_t *v) { __atomic_add_fetch(&v->counter, 1, __ATOMIC_SEQ_CST); }
|
|
|
+static __inline__ int atomic_inc_return(atomic_t *v) { return __atomic_add_fetch(&v->counter, 1, __ATOMIC_SEQ_CST); }
|
|
|
+static __inline__ int atomic_inc_and_test(atomic_t *v) { return __atomic_add_fetch(&v->counter, 1, __ATOMIC_SEQ_CST) == 0; }
|
|
|
+static __inline__ void atomic_dec(atomic_t *v) { __atomic_sub_fetch(&v->counter, 1, __ATOMIC_SEQ_CST); }
|
|
|
+static __inline__ int atomic_dec_return(atomic_t *v) { return __atomic_sub_fetch(&v->counter, 1, __ATOMIC_SEQ_CST); }
|
|
|
+static __inline__ int atomic_dec_and_test(atomic_t *v) { return __atomic_sub_fetch(&v->counter, 1, __ATOMIC_SEQ_CST) == 0; }
|
|
|
+static __inline__ int atomic_dec_if_positive(atomic_t *v) {
|
|
|
+ int current = atomic_read(v);
|
|
|
+ for (;;) {
|
|
|
+ int decremented = current - 1;
|
|
|
+ if (decremented < 0) return decremented;
|
|
|
+ if (__atomic_compare_exchange_n(&v->counter, ¤t, decremented, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) return decremented;
|
|
|
+ }
|
|
|
+}
|
|
|
+static __inline__ int atomic_sub_and_test(int i, atomic_t *v) { return __atomic_sub_fetch(&v->counter, i, __ATOMIC_SEQ_CST) == 0; }
|
|
|
+static __inline__ void atomic_clear_mask(unsigned long mask, unsigned long *addr) { __atomic_fetch_and(addr, ~mask, __ATOMIC_SEQ_CST); }
|
|
|
+static __inline__ void atomic_set_mask(unsigned long mask, unsigned long *addr) { __atomic_fetch_or(addr, mask, __ATOMIC_SEQ_CST); }
|
|
|
+#define smp_mb__before_atomic_dec() __atomic_thread_fence(__ATOMIC_SEQ_CST)
|
|
|
+#define smp_mb__after_atomic_dec() __atomic_thread_fence(__ATOMIC_SEQ_CST)
|
|
|
+#define smp_mb__before_atomic_inc() __atomic_thread_fence(__ATOMIC_SEQ_CST)
|
|
|
+#define smp_mb__after_atomic_inc() __atomic_thread_fence(__ATOMIC_SEQ_CST)
|
|
|
+
|
|
|
+#elif defined(__powerpc__) || defined(__ppc__)
|
|
|
+'''
|
|
|
+
|
|
|
+for filename in sys.argv[1:]:
|
|
|
+ path = Path(filename)
|
|
|
+ text = path.read_text(encoding="utf-8")
|
|
|
+ needle = "#if defined(__powerpc__) || defined(__ppc__)\n"
|
|
|
+ if text.count(needle) != 1:
|
|
|
+ raise SystemExit(f"Expected one PowerPC atomic implementation guard in {path}")
|
|
|
+ path.write_text(text.replace(needle, replacement, 1), encoding="utf-8")
|
|
|
+PY
|
|
|
+
|
|
|
+make -C libs -j"$(nproc)"
|
|
|
+make -C src -j"$(nproc)" sooperlooper
|
|
|
+
|
|
|
+install -m 0755 src/sooperlooper "$temporary_directory/sooperlooper"
|
|
|
+ldd "$temporary_directory/sooperlooper" > "$temporary_directory/runtime-dependencies.txt"
|
|
|
+if grep -F 'not found' "$temporary_directory/runtime-dependencies.txt"; then
|
|
|
+ printf '%s\n' "Unresolved runtime dependencies in the compiled executable." >&2
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+
|
|
|
+binary_sha256=$(sha256sum "$temporary_directory/sooperlooper" | cut -d ' ' -f 1)
|
|
|
+cat > "$temporary_directory/provenance.json" <<EOF
|
|
|
+{
|
|
|
+ "source_url": "$source_url",
|
|
|
+ "tag": "$tag",
|
|
|
+ "commit": "$source_commit",
|
|
|
+ "platform": "linux/arm64",
|
|
|
+ "artifact": "sooperlooper",
|
|
|
+ "sha256": "$binary_sha256",
|
|
|
+ "local_patches": ["GCC AArch64 atomic operations in libs/pbd/pbd/atomic.h and src/atomic.h"]
|
|
|
+}
|
|
|
+EOF
|
|
|
+
|
|
|
+chmod 0755 "$temporary_directory"
|
|
|
+chmod 0644 "$temporary_directory/provenance.json" "$temporary_directory/runtime-dependencies.txt"
|
|
|
+if [ ! -e "$artifact_directory/current" ] && [ -e "$previous_directory" ]; then
|
|
|
+ mv "$previous_directory" "$artifact_directory/current"
|
|
|
+fi
|
|
|
+if [ -e "$previous_directory" ]; then
|
|
|
+ rm -rf "$previous_directory"
|
|
|
+fi
|
|
|
+if [ -e "$artifact_directory/current" ]; then
|
|
|
+ mv "$artifact_directory/current" "$previous_directory"
|
|
|
+fi
|
|
|
+mv "$temporary_directory" "$artifact_directory/current"
|
|
|
+temporary_directory=
|
|
|
+rm -rf "$previous_directory"
|
|
|
+printf 'Built %s at %s\n' "$tag" "$source_commit"
|
|
|
+printf 'Artifact: %s/current/sooperlooper\n' "$artifact_directory"
|
|
|
+printf 'SHA-256: %s\n' "$binary_sha256"
|