Skip to content

Commit

Permalink
Add initial bb testing scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jeaye committed Jan 31, 2025
1 parent 1e552a1 commit f43fdf9
Show file tree
Hide file tree
Showing 17 changed files with 421 additions and 144 deletions.
89 changes: 18 additions & 71 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,79 +14,26 @@ outputs:
runs:
using: "composite"
steps:
- if: runner.os == 'Linux'
name: Install apt packages
- name: Test Clojure CLI workflow
shell: bash
run: sudo apt-get install -y curl git git-lfs zip build-essential entr libssl-dev libdouble-conversion-dev pkg-config ninja-build cmake zlib1g-dev libffi-dev clang libclang-dev llvm llvm-dev libzip-dev libbz2-dev doctest-dev libboost-all-dev gcc g++ libgc-dev
- if: runner.os == 'macOS'
name: Install brew packages
working-directory: ${{ github.workspace }}/clojure-cli
run: ${{ github.workspace }}/clojure-cli/bin/ci/test
- name: Test Leiningen plugin
shell: bash
run: HOMEBREW_NO_AUTO_UPDATE=1 brew install curl git git-lfs zip entr openssl double-conversion pkg-config ninja python cmake gnupg zlib doctest boost libzip lbzip2 llvm@19
- name: Restore cached Clang/LLVM
id: restore-clang-cache
uses: actions/cache/restore@v4
with:
path: |
${{ github.workspace }}/compiler+runtime/build
key: ${{ runner.os }}-${{ hashFiles('compiler+runtime/bin/build-clang') }}
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- name: Install clojure tools
uses: DeLaGuardo/setup-clojure@13.1
with:
cli: latest
lein: 2.9.1
- name: Compile and test
working-directory: ${{ github.workspace }}/lein-jank
run: ${{ github.workspace }}/lein-jank/bin/ci/test
- name: Test library workflows
shell: bash
working-directory: ${{ github.workspace }}/compiler+runtime
run: ${{ github.workspace }}/compiler+runtime/bin/ci/test -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
- name: Store cached Clang/LLVM
id: save-clang-cache
uses: actions/cache/save@v4
with:
path: |
${{ github.workspace }}/compiler+runtime/build
key: ${{ steps.restore-clang-cache.outputs.cache-primary-key }}
# We need to validate formatting after building, since we build Clang/LLVM as part of our
# build process and we need clang-format from that local Clang build in order to have
# consistent formatting results.
- name: Validate formatting
working-directory: ${{ github.workspace }}/lib-test
run: ${{ github.workspace }}/lib-test/bin/ci/test
- if: success() && ${{ inputs.build_ubuntu_tarball }}
name: Release
id: release
shell: bash
working-directory: ${{ github.workspace }}/compiler+runtime
run: ${{ github.workspace }}/compiler+runtime/bin/ci/validate-formatting
- if: success() && ${{ env.CODECOV == 'on' }}
name: Upload report to Codecov
uses: codecov/codecov-action@v3
#- name: Add jank to PATH
# shell: bash
# working-directory: ${{ github.workspace }}/compiler+runtime
# run: |
# export DESTDIR=${{ github.workspace }}/jank-install
# ${{ github.workspace }}/compiler+runtime/bin/install
# export PATH="${DESTDIR}/usr/local/bin:${PATH}"
# echo "PATH=${PATH}" >> "${GITHUB_ENV}"
#- name: Test Clojure CLI workflow
# shell: bash
# working-directory: ${{ github.workspace }}/clojure-cli
# run: ${{ github.workspace }}/clojure-cli/bin/ci/test
#- name: Test Leiningen plugin
# shell: bash
# working-directory: ${{ github.workspace }}/lein-jank
# run: ${{ github.workspace }}/lein-jank/bin/ci/test
#- if: success() && ${{ inputs.build_ubuntu_tarball }}
#- name: Test library workflows
# shell: bash
# working-directory: ${{ github.workspace }}/lib-test
# run: ${{ github.workspace }}/lib-test/bin/ci/test
# name: Release
# id: release
# shell: bash
# working-directory: ${{ github.workspace }}/compiler+runtime
# run: |
# export DESTDIR=jank-${{ matrix.os }}-$(date +'%Y-%m-%d').$(git rev-parse --short $GITHUB_SHA)
# bin/install
# tar czf $DESTDIR.tar.gz ${DESTDIR}/
# absolute_archive=${{ github.workspace }}/compiler+runtime/${DESTDIR}.tar.gz
# echo "archive=${absolute_archive}" >> ${GITHUB_OUTPUT}
run: |
export DESTDIR=jank-${{ matrix.os }}-$(date +'%Y-%m-%d').$(git rev-parse --short $GITHUB_SHA)
bin/install
tar czf $DESTDIR.tar.gz ${DESTDIR}/
absolute_archive=${{ github.workspace }}/compiler+runtime/${DESTDIR}.tar.gz
echo "archive=${absolute_archive}" >> ${GITHUB_OUTPUT}
34 changes: 18 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ jobs:
matrix:
include:
# Ubuntu
## Lint all sources
- os: ubuntu-24.04
lint: true
## Debug + clang-tidy + codecov
- os: ubuntu-24.04
build_type: Debug
sanitize: none
codecov: on
analysis: on
codecov: true
analyze: true
## Debug + sanitization
- os: ubuntu-24.04
build_type: Debug
Expand All @@ -35,27 +38,26 @@ jobs:
runs-on: ${{ matrix.os }}
env:
JANK_MATRIX_ID: ${{ matrix.os }}-${{ matrix.build_type }}-${{ matrix.sanitize }}
CODECOV: ${{ matrix.codecov }}
ANALYSIS: ${{ matrix.analysis }}
SANITIZE: ${{ matrix.sanitize }}
JANK_BUILD_TYPE: ${{ matrix.build_type }}
JANK_LINT: ${{ matrix.lint }}
JANK_CODECOV: ${{ matrix.codecov }}
JANK_ANALYZE: ${{ matrix.analyze }}
JANK_SANITIZE: ${{ matrix.sanitize }}
ASAN_OPTIONS: detect_leaks=0
TERM: xterm
timeout-minutes: 240 # 4h
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Build and test
uses: ./.github/actions/build
id: build
with:
build_ubuntu_tarball: ${{ matrix.build_ubuntu_tarball }}
- name: Archive test log
if: always()
uses: actions/upload-artifact@v4
with:
name: test-log-${{ env.JANK_MATRIX_ID }}
path: compiler+runtime/test.log
run: ./bin/jank/test_everything.clj
#- name: Archive test log
# if: always()
# uses: actions/upload-artifact@v4
# with:
# name: test-log-${{ env.JANK_MATRIX_ID }}
# path: compiler+runtime/test.log
#- name: Update Ubuntu tarball
# if: success() && ${{ matrix.build_ubuntu_tarball == 'true' }}
# uses: pyTooling/Actions/releaser@main
Expand Down
7 changes: 7 additions & 0 deletions .standard-clj.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{:include ["bin/jank/**/**.clj"
"bin/jank/bb.edn"

"compiler+runtime/bin/jank/**/*.clj"
"compiler+runtime/bin/jank/bb.edn"
"compiler+runtime/src/jank/**/*.jank"
"compiler+runtime/test/jank/**/*.jank"]}
2 changes: 2 additions & 0 deletions bin/jank/bb.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{:paths ["../"
"../../compiler+runtime/bin"]}
73 changes: 73 additions & 0 deletions bin/jank/test_everything.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env bb

(ns jank.test-everything
(:require
[jank.util :as util]
[jank.compiler+runtime.core]))

(defn show-env []
(util/log-info "JANK_BUILD_TYPE: " (System/getenv "JANK_BUILD_TYPE"))
(util/log-info "JANK_LINT: " (System/getenv "JANK_LINT"))
(util/log-info "JANK_CODECOV: " (System/getenv "JANK_CODECOV"))
(util/log-info "JANK_ANALYZE: " (System/getenv "JANK_ANALYZE"))
(util/log-info "JANK_SANITIZE: " (System/getenv "JANK_SANITIZE")))

(def os->deps-cmd {"Linux" "sudo apt-get install -y curl git git-lfs zip build-essential entr libssl-dev libdouble-conversion-dev pkg-config ninja-build cmake zlib1g-dev libffi-dev libzip-dev libbz2-dev doctest-dev libboost-all-dev gcc g++ libgc-dev"

"Mac OS X" "brew install curl git git-lfs zip entr openssl double-conversion pkg-config ninja python cmake gnupg zlib doctest boost libzip lbzip2 llvm@19"})

(defmulti install-deps
(fn []
(System/getProperty "os.name")))

(defmethod install-deps "Linux" []
(let [apt? (try
(util/quiet-shell {} "which apt-get")
true
(catch Exception _e
false))]
(if-not apt?
(util/log-warning "Skipping dependency install, since we don't have apt-get")
(do
; Install deps required for running our tests.
(util/quiet-shell {} "sudo apt-get install -y default-jdk software-properties-common lsb-release npm lcov leiningen")
(util/quiet-shell {} "sudo npm install --global @chrisoakman/standard-clojure-style")

; Install jank's build deps.
(util/quiet-shell {} (os->deps-cmd "Linux"))

; Install Clang/LLVM.
(util/quiet-shell {} "curl -L -O https://apt.llvm.org/llvm.sh")
(util/quiet-shell {} "chmod +x llvm.sh")
(util/quiet-shell {} (str "sudo ./llvm.sh " util/llvm-version " all"))
; The libc++abi headers conflict with the system headers:
; https://github.com/llvm/llvm-project/issues/121300
(util/quiet-shell {} (str "sudo apt-get remove -y libc++abi-" util/llvm-version "-dev"))

; Install the new Clojure CLI.
(util/quiet-shell {} "curl -L -O https://github.com/clojure/brew-install/releases/latest/download/linux-install.sh")
(util/quiet-shell {} "chmod +x linux-install.sh")
(util/quiet-shell {} "sudo ./linux-install.sh")))))

(defmethod install-deps "Mac OS X" []
(util/quiet-shell {:extra-env {"HOMEBREW_NO_AUTO_UPDATE" "1"}}
(os->deps-cmd "Mac OS X")))

(defn -main [{:keys [install-deps? validate-formatting? compiler+runtime]}]
(util/log-boundary "Environment")
(show-env)

(util/log-boundary "Install dependencies")
(if-not install-deps?
(util/log-info "Not enabled")
(util/with-elapsed-time duration
(install-deps)
(util/log-info-with-time duration "Dependencies installed")))

(jank.compiler+runtime.core/-main {:validate-formatting? validate-formatting?
:build? (:build? compiler+runtime)}))

(when (= *file* (System/getProperty "babashka.file"))
(-main {:install-deps? (parse-boolean (or (System/getenv "JANK_INSTALL_DEPS") "true"))
:validate-formatting? (parse-boolean (or (System/getenv "JANK_LINT") "true"))
:compiler+runtime {:build? (some? (System/getenv "JANK_BUILD_TYPE"))}}))
74 changes: 74 additions & 0 deletions bin/jank/util.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
(ns jank.util
(:require
[clojure.string]
[babashka.fs :as b.f]
[babashka.process :as b.p]))

(def llvm-version 19)

(defn log [& args]
(println (apply str args)))

(defn log-boundary [title]
(log "\n──────────────── " title " ────────────────"))

(defn log-step [title]
(log "\n──── " title " ────"))

(defn log-info [& args]
(println "🛈 " (apply str args)))

(defn log-info-with-time [time-ms & args]
; TODO: Time formatting.
(println "🛈 " (apply str args) (str "(" time-ms " ms)")))

(defn log-warning [& args]
(println "" (apply str args)))

(defn log-error [& args]
(println "" (apply str args)))

(defn log-error-with-time [time-ms & args]
; TODO: Time formatting.
(println "" (apply str args) (str "(" time-ms " ms)")))

(defn quiet-shell [props cmd]
(let [proc @(b.p/process
(merge {:out :string
:err :out}
props)
cmd)]
(if-not (zero? (:exit proc))
(do
(log-error "Failed to run command " cmd)
(log (:out proc))
(System/exit 1))
proc)))

(defmacro with-elapsed-time
[time-sym expr-to-time expr-with-time-sym]
`(let [start# (. System (nanoTime))
ret# ~expr-to-time
~time-sym (long (/ (double (- (. System (nanoTime)) start#)) 1000000.0))]
~expr-with-time-sym))

(defn extract-llvm-tool-format-version [tool]
(let [res (b.p/shell {:out :string
:err :string}
(str tool " --version"))
major-version (->> (clojure.string/replace (clojure.string/trim (:out res)) #"\n" " ")
(re-matches #".*version (\d+).*")
second)]
major-version))

(defn find-llvm-tool [tool]
(loop [names [(str tool "-" llvm-version) tool]]
(if (empty? names)
(do
(log-error "Unable to find a suitable " tool " for LLVM " llvm-version)
(System/exit 1))
(let [found (b.f/which (first names))]
(if (and (some? found) (= (str llvm-version)
(extract-llvm-tool-format-version found)))
(clojure.string/trim (str found))
(recur (rest names)))))))
38 changes: 0 additions & 38 deletions compiler+runtime/bin/ci/test

This file was deleted.

18 changes: 0 additions & 18 deletions compiler+runtime/bin/ci/validate-formatting

This file was deleted.

Loading

0 comments on commit f43fdf9

Please sign in to comment.