From 1f46100938cea24697647cb56d555470a9e989ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Sun, 30 Sep 2018 14:43:11 +0200 Subject: [PATCH 01/15] Add TEST_SUITE=bazel to run Bazel on examples In an attempt to support all build systems in the examples, run bazel test on all examples. That's also the first step towards Bazel support #204 --- .travis.yml | 17 +++++++++++++++++ jflex/examples/WORKSPACE | 1 + scripts/bazel.sh | 21 +++++++++++++++++++++ scripts/run-tests.sh | 3 +++ 4 files changed, 42 insertions(+) create mode 100644 jflex/examples/WORKSPACE create mode 100755 scripts/bazel.sh diff --git a/.travis.yml b/.travis.yml index f28c1d1c5..b318abfa1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,23 @@ env: - TEST_SUITE=ant - TEST_SUITE=unit - TEST_SUITE=regression + - TEST_SUITE=bazel + +# Prerequisites for Bazel +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - curl + - pkg-config + - zip + - g++ + - zlib1g-dev + - unzip + - python + +sudo: $TEST_SUITE = bazel # Empty the previously built artifacts # They cannot be deleted in the before_cache phase, diff --git a/jflex/examples/WORKSPACE b/jflex/examples/WORKSPACE new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/jflex/examples/WORKSPACE @@ -0,0 +1 @@ + diff --git a/scripts/bazel.sh b/scripts/bazel.sh new file mode 100755 index 000000000..3aec8a460 --- /dev/null +++ b/scripts/bazel.sh @@ -0,0 +1,21 @@ +#!/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 + +logi "Install Bazel" +logi "=============" +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 +sudo apt-get install tools/bazel-0.16.1.deb + +logi "Run Bazel tests on examples" +logi "===========================" +cd jflex/examples +bazel test /.. + +cd "$CWD" diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index 8f012ac51..2c7536b87 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -33,6 +33,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" From 7d76a148050cee672d05999ff52fbf3f7ec252f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Sun, 30 Sep 2018 18:32:49 +0200 Subject: [PATCH 02/15] Attempt to fix apt-get --- scripts/bazel.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/bazel.sh b/scripts/bazel.sh index 3aec8a460..1364cd1e3 100755 --- a/scripts/bazel.sh +++ b/scripts/bazel.sh @@ -10,8 +10,9 @@ set -e logi "Install Bazel" logi "=============" +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 -sudo apt-get install tools/bazel-0.16.1.deb +sudo apt-get install ./tools/bazel-0.16.1.deb logi "Run Bazel tests on examples" logi "===========================" From 0789b46115b860711be963e80f9124fcd9b0e260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Sun, 30 Sep 2018 23:17:26 +0200 Subject: [PATCH 03/15] typo --- scripts/bazel.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bazel.sh b/scripts/bazel.sh index 1364cd1e3..acff9106c 100755 --- a/scripts/bazel.sh +++ b/scripts/bazel.sh @@ -17,6 +17,6 @@ sudo apt-get install ./tools/bazel-0.16.1.deb logi "Run Bazel tests on examples" logi "===========================" cd jflex/examples -bazel test /.. +bazel test //.. cd "$CWD" From 744e65f5e0e86ff5b3f4ac19f8ebc724068531b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Sun, 30 Sep 2018 23:27:07 +0200 Subject: [PATCH 04/15] Move the installation of bazel in the travis.yml --- .travis.yml | 9 ++++++++- scripts/bazel.sh | 17 +++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index c16b870c6..e20d41408 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,6 @@ matrix: - name: "Ant JDK9" script: scripts/run-ant.sh - name: "Bazel" - sudo: true script: scripts/bazel.sh # Prerequisites for Bazel addons: @@ -47,6 +46,14 @@ matrix: - 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, diff --git a/scripts/bazel.sh b/scripts/bazel.sh index acff9106c..3899623ab 100755 --- a/scripts/bazel.sh +++ b/scripts/bazel.sh @@ -8,15 +8,16 @@ source "$BASEDIR"/scripts/logger.sh # fail on error set -e -logi "Install Bazel" -logi "=============" -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 -sudo apt-get install ./tools/bazel-0.16.1.deb - -logi "Run Bazel tests on examples" -logi "===========================" +logi "Start Bazel" +logi "===========" cd jflex/examples +bazel start + +logi "Build everything" +bazel build //... + +logi "Test everything" +logi "===============" bazel test //.. cd "$CWD" From 24e9884588f19a34c43348bc43710945bd13892f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Sun, 30 Sep 2018 23:35:04 +0200 Subject: [PATCH 05/15] Use Travis .bazelrc --- jflex/examples/.travis.bazelrc | 17 +++++++++++++++++ scripts/bazel.sh | 12 +++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 jflex/examples/.travis.bazelrc diff --git a/jflex/examples/.travis.bazelrc b/jflex/examples/.travis.bazelrc new file mode 100644 index 000000000..2189a6936 --- /dev/null +++ b/jflex/examples/.travis.bazelrc @@ -0,0 +1,17 @@ +# Taken from https://github.com/korfuri/bazel-travis/blob/master/.bazelrc + +# 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 + +# This is so we don't use sandboxed execution. Sandboxed execution +# runs stuff in a container, and since Travis already runs its script +# in a container (unless you require sudo in your .travis.yml) this +# fails to run tests. +# build --spawn_strategy=standalone --genrule_strategy=standalone +# test --test_strategy=standalone diff --git a/scripts/bazel.sh b/scripts/bazel.sh index 3899623ab..b06697052 100755 --- a/scripts/bazel.sh +++ b/scripts/bazel.sh @@ -8,16 +8,22 @@ 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 start +$BAZEL start logi "Build everything" -bazel build //... +$BAZEL build //... logi "Test everything" logi "===============" -bazel test //.. +$BAZEL test //... cd "$CWD" From 008603bd6f557e0a4624eaeeb366066bf2d04e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Sun, 30 Sep 2018 23:39:07 +0200 Subject: [PATCH 06/15] Display bazel info --- scripts/bazel.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bazel.sh b/scripts/bazel.sh index b06697052..a195e2aba 100755 --- a/scripts/bazel.sh +++ b/scripts/bazel.sh @@ -17,7 +17,7 @@ fi logi "Start Bazel" logi "===========" cd jflex/examples -$BAZEL start +$BAZEL info logi "Build everything" $BAZEL build //... From 6d6b73c5f1ae474330807a06c59815ead0db935e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Sun, 30 Sep 2018 23:43:58 +0200 Subject: [PATCH 07/15] move bazelrc to travis root --- jflex/examples/.travis.bazelrc => .travis.bazelrc | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename jflex/examples/.travis.bazelrc => .travis.bazelrc (100%) diff --git a/jflex/examples/.travis.bazelrc b/.travis.bazelrc similarity index 100% rename from jflex/examples/.travis.bazelrc rename to .travis.bazelrc From 5b90b836ac251c274eca5527134ae034b9a74508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Sun, 30 Sep 2018 23:46:44 +0200 Subject: [PATCH 08/15] Cache bazel output dir --- .travis.bazelrc | 4 ++++ .travis.yml | 1 + 2 files changed, 5 insertions(+) diff --git a/.travis.bazelrc b/.travis.bazelrc index 2189a6936..3d9520c48 100644 --- a/.travis.bazelrc +++ b/.travis.bazelrc @@ -1,3 +1,6 @@ +# This allows to cache the build artefacts :-D +startup --output_user_root=$TRAVIS_BUILD_DIR/__bazel__ + # Taken from https://github.com/korfuri/bazel-travis/blob/master/.bazelrc # This is from Bazel's former travis setup, to avoid blowing up the RAM usage. @@ -15,3 +18,4 @@ test --test_output=errors # fails to run tests. # build --spawn_strategy=standalone --genrule_strategy=standalone # test --test_strategy=standalone + diff --git a/.travis.yml b/.travis.yml index e20d41408..cce4a5039 100644 --- a/.travis.yml +++ b/.travis.yml @@ -77,6 +77,7 @@ cache: - $HOME/.m2 - jflex/lib - tools + - __bazel__ deploy: # Deploy the maven site on Github pages From 0e21608fa7e30c6cd674a5b70e9226225614a5c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Sun, 30 Sep 2018 23:48:21 +0200 Subject: [PATCH 09/15] fix Error: Unable to read .bazelrc file '/home/travis/build/jflex-de/jflex/jflex/examples/$TRAVIS_BUILD_DIR/.travis.bazelrc'. --- scripts/bazel.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bazel.sh b/scripts/bazel.sh index a195e2aba..054f42634 100755 --- a/scripts/bazel.sh +++ b/scripts/bazel.sh @@ -9,7 +9,7 @@ source "$BASEDIR"/scripts/logger.sh set -e if [[ $TRAVIS ]]; then - BAZEL='bazel --bazelrc=$TRAVIS_BUILD_DIR/.travis.bazelrc' + BAZEL="bazel --bazelrc=$TRAVIS_BUILD_DIR/.travis.bazelrc" else BAZEL='bazel' fi From 7012dd88976b207752ec910a6dfa4461615efb2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Sun, 30 Sep 2018 23:55:07 +0200 Subject: [PATCH 10/15] Define bazel_root on cli only --- .travis.bazelrc | 4 ++-- scripts/bazel.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.bazelrc b/.travis.bazelrc index 3d9520c48..e8a294ca0 100644 --- a/.travis.bazelrc +++ b/.travis.bazelrc @@ -1,5 +1,5 @@ -# This allows to cache the build artefacts :-D -startup --output_user_root=$TRAVIS_BUILD_DIR/__bazel__ +# Env variables are not substituted in .bazelrc :( +#startup --output_user_root=$TRAVIS_BUILD_DIR/__bazel__ # Taken from https://github.com/korfuri/bazel-travis/blob/master/.bazelrc diff --git a/scripts/bazel.sh b/scripts/bazel.sh index 054f42634..0c0bd4490 100755 --- a/scripts/bazel.sh +++ b/scripts/bazel.sh @@ -9,7 +9,7 @@ source "$BASEDIR"/scripts/logger.sh set -e if [[ $TRAVIS ]]; then - BAZEL="bazel --bazelrc=$TRAVIS_BUILD_DIR/.travis.bazelrc" + BAZEL="bazel --bazelrc=$TRAVIS_BUILD_DIR/.travis.bazelrc --output_user_root=$TRAVIS_BUILD_DIR/__bazel__" else BAZEL='bazel' fi From 598b271a324af3c11626bdfe517c40ee5567f0a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Sun, 30 Sep 2018 23:56:42 +0200 Subject: [PATCH 11/15] Remove useless comments from bazelrc --- .travis.bazelrc | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.travis.bazelrc b/.travis.bazelrc index e8a294ca0..a34c9f070 100644 --- a/.travis.bazelrc +++ b/.travis.bazelrc @@ -1,8 +1,3 @@ -# Env variables are not substituted in .bazelrc :( -#startup --output_user_root=$TRAVIS_BUILD_DIR/__bazel__ - -# Taken from https://github.com/korfuri/bazel-travis/blob/master/.bazelrc - # 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 @@ -12,10 +7,3 @@ test --ram_utilization_factor=10 build --verbose_failures test --test_output=errors -# This is so we don't use sandboxed execution. Sandboxed execution -# runs stuff in a container, and since Travis already runs its script -# in a container (unless you require sudo in your .travis.yml) this -# fails to run tests. -# build --spawn_strategy=standalone --genrule_strategy=standalone -# test --test_strategy=standalone - From ec0efcb6407b248f5bf0c706cbad383d4d493267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Mon, 1 Oct 2018 00:17:23 +0200 Subject: [PATCH 12/15] Bazel needs at least one package. Add root package --- jflex/.gitignore | 3 --- jflex/examples/.gitignore | 2 +- jflex/examples/BUILD | 5 +++++ 3 files changed, 6 insertions(+), 4 deletions(-) delete mode 100644 jflex/.gitignore create mode 100644 jflex/examples/BUILD diff --git a/jflex/.gitignore b/jflex/.gitignore deleted file mode 100644 index c3ebe0a51..000000000 --- a/jflex/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Generated by ant -build - diff --git a/jflex/examples/.gitignore b/jflex/examples/.gitignore index 298e948b2..e8851ff06 100644 --- a/jflex/examples/.gitignore +++ b/jflex/examples/.gitignore @@ -1,3 +1,3 @@ -build +antbuild target out diff --git a/jflex/examples/BUILD b/jflex/examples/BUILD new file mode 100644 index 000000000..4322c868c --- /dev/null +++ b/jflex/examples/BUILD @@ -0,0 +1,5 @@ +# Root bazel package + +# This pacakge exists because +# `blaze build //...` needs at least one package + From e20555b3518742c8eae82822b0666e54a6b86338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Mon, 1 Oct 2018 00:19:11 +0200 Subject: [PATCH 13/15] cosmetic --- scripts/bazel.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/bazel.sh b/scripts/bazel.sh index 0c0bd4490..62610e7ad 100755 --- a/scripts/bazel.sh +++ b/scripts/bazel.sh @@ -20,6 +20,7 @@ cd jflex/examples $BAZEL info logi "Build everything" +logi "================" $BAZEL build //... logi "Test everything" From 854eedcb03133be40e4c9c9ac49a4ce5208465f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Mon, 1 Oct 2018 00:50:50 +0200 Subject: [PATCH 14/15] Add stupid sh_test to make bazel happy --- jflex/examples/BUILD | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/jflex/examples/BUILD b/jflex/examples/BUILD index 4322c868c..bddad4a25 100644 --- a/jflex/examples/BUILD +++ b/jflex/examples/BUILD @@ -1,5 +1,24 @@ # Root bazel package # This pacakge exists because -# `blaze build //...` needs at least one package +# `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\"' > $@", +) From a4434a56a9e5effd6bcb54f800fec99e52209172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20D=C3=A9camps?= Date: Mon, 1 Oct 2018 00:59:39 +0200 Subject: [PATCH 15/15] Remove bazel cache. Travis hangs when there is one. --- .travis.yml | 1 - scripts/bazel.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index cce4a5039..e20d41408 100644 --- a/.travis.yml +++ b/.travis.yml @@ -77,7 +77,6 @@ cache: - $HOME/.m2 - jflex/lib - tools - - __bazel__ deploy: # Deploy the maven site on Github pages diff --git a/scripts/bazel.sh b/scripts/bazel.sh index 62610e7ad..bd11ba2b5 100755 --- a/scripts/bazel.sh +++ b/scripts/bazel.sh @@ -9,7 +9,7 @@ source "$BASEDIR"/scripts/logger.sh set -e if [[ $TRAVIS ]]; then - BAZEL="bazel --bazelrc=$TRAVIS_BUILD_DIR/.travis.bazelrc --output_user_root=$TRAVIS_BUILD_DIR/__bazel__" + BAZEL="bazel --bazelrc=$TRAVIS_BUILD_DIR/.travis.bazelrc" else BAZEL='bazel' fi