Skip to content

Commit

Permalink
Add Bazel job in Travis (#395)
Browse files Browse the repository at this point in the history
* Add a new matrix cell for [Bazel](https://bazel.build)
* In the bazel job:
  - install deps with apt
  - download bazel.deb from official repo
  - install with `sudo apt-get install`. **N.B.** This job needs **sudo: true**
* Add a simple `bazel.sh` that only does (and it's not going to change much in the future)
  ```
  cd jflex/examples
  bazel build //...
  bazel test //...
  ```
* Add an (virtually) empty root `jflex/examples/BUILD`
  - This root BUILD defines one sh_test, so that `bazel test //...` doesn't complain with 
    > No test targets were found, yet testing was requested
* This is the first step for #204 (Bazel support)
* **N.B.** Do not use a cache for bazel.
  - I tried caching the bazel output directory (this is in theory perfectly fine)
    by setting  a non-default `--output_user_root=$TRAVIS_BUILD_DIR/__bazel__`
  - But the VM hangs at startup with
    > creating directory /home/travis/build/jflex-de/jflex/__bazel__
  • Loading branch information
regisd authored Sep 30, 2018
1 parent 3936f66 commit f110aa8
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .travis.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This is from Bazel's former travis setup, to avoid blowing up the RAM usage.
startup --host_jvm_args=-Xms2000m
startup --host_jvm_args=-Xmx3000m
test --ram_utilization_factor=10

# This is so we understand failures better
build --verbose_failures
test --test_output=errors

23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@ matrix:
sdk: oraclejdk8
- name: "Ant JDK9"
script: scripts/run-ant.sh
- name: "Bazel"
script: scripts/bazel.sh
# Prerequisites for Bazel
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- curl
- pkg-config
- zip
- g++
- zlib1g-dev
- unzip
- python
before_install:
- mkdir -p tools
- curl -L https://github.com/bazelbuild/bazel/releases/download/0.16.1/bazel_0.16.1-linux-x86_64.deb -o tools/bazel-0.16.1.deb
install:
- java -version
- sudo apt-get install ./tools/bazel-0.16.1.deb
sudo: true
after_success: blaze shutdown

# Empty the previously built artifacts
# They cannot be deleted in the before_cache phase,
Expand Down
3 changes: 0 additions & 3 deletions jflex/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion jflex/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build
antbuild
target
out
24 changes: 24 additions & 0 deletions jflex/examples/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Root bazel package

# This pacakge exists because
# `bazel build //...` needs at least one package

# But bazel test //... fails with
# No test targets were found, yet testing was requested
# So here is a test:

sh_test(
name = "hello_test",
size = "small",
srcs = [":hello_test_lib"],
)
sh_library(
name = "hello_test_lib",
srcs = [":gen_hello_test_sh"],
)
genrule(
name = "gen_hello_test_sh",
srcs = [],
outs = ["hello_test.sh"],
cmd = "echo 'echo \"Hello World\"' > $@",
)
1 change: 1 addition & 0 deletions jflex/examples/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

30 changes: 30 additions & 0 deletions scripts/bazel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
# Run bazel on examples

CWD="$PWD"
BASEDIR="$(cd "$(dirname "$0")" && pwd -P)"/..
# Provides the logi function
source "$BASEDIR"/scripts/logger.sh
# fail on error
set -e

if [[ $TRAVIS ]]; then
BAZEL="bazel --bazelrc=$TRAVIS_BUILD_DIR/.travis.bazelrc"
else
BAZEL='bazel'
fi

logi "Start Bazel"
logi "==========="
cd jflex/examples
$BAZEL info

logi "Build everything"
logi "================"
$BAZEL build //...

logi "Test everything"
logi "==============="
$BAZEL test //...

cd "$CWD"
3 changes: 3 additions & 0 deletions scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ if [[ -z "$TEST_SUITE" || "$TEST_SUITE" == "ant" ]]; then
"$BASEDIR"/scripts/ant-build.sh
"$BASEDIR"/scripts/test-examples.sh
fi
if [[ -z "$TEST_SUITE" || "$TEST_SUITE" == "bazel" ]]; then
"$BASEDIR"/scripts/bazel.sh
fi

logi "Success"
cd "$CWD"

0 comments on commit f110aa8

Please sign in to comment.