Skip to content

Commit

Permalink
Make Bazel work gain. Add minimalisitc test that verifies the binary …
Browse files Browse the repository at this point in the history
…can at least report its own version.
  • Loading branch information
helly25 committed Oct 15, 2024
1 parent 01fd8b0 commit 5080971
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
common --noenable_bzlmod
10 changes: 9 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ genrule(
"//bazel:re2c_config.h",
],
outs = ["config.h"],
visibility = ["//bazel:__pkg__"],
cmd = """
cat $(location //:CMakeLists.txt) |\\
sed -rne 's/project\\(re2c VERSION ([^ ]+).*/#define PACKAGE_VERSION "\\1-bootstrap"/p' >> "$@"
Expand All @@ -27,10 +28,17 @@ cc_library(
hdrs = glob([
"bootstrap/src/**/*.h",
"src/**/*.h",
]),
], exclude = [
"src/test/**",
]) + [
"src/test/range/test.h"
],
srcs = glob([
"bootstrap/src/**/*.cc",
"src/**/*.cc",
], exclude = [
"src/main.cc",
"src/test/**",
]),
deps = [
"re2c_config_cc", # Needed for 're2c_config_cc' data files
Expand Down
13 changes: 11 additions & 2 deletions bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package(default_visibility = ["//visibility:private"])

load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

package(default_visibility = ["//visibility:private"])

exports_files([
"re2c_config.h",
])
Expand All @@ -11,3 +11,12 @@ bzl_library(
srcs = ["re2c.bzl"],
visibility = ["//visibility:public"],
)

sh_test(
name = "re2c_bazel_test",
srcs = ["re2c_bazel_test.sh"],
data = [
"//:re2c_config",
"//:re2c",
],
)
2 changes: 1 addition & 1 deletion bazel/re2c.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# re2c generator rules - assuming that re2c is available as '@re2c//:re2c'.
"""re2c generator rules - assuming that re2c is available as '@re2c//:re2c'."""

load("@bazel_skylib//lib:paths.bzl", "paths")

Expand Down
16 changes: 16 additions & 0 deletions bazel/re2c_bazel_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Minimalistic test that verifies the binary can run and report its own version.

set -euo pipefail

RE2C_VERSION="$(cat "${TEST_SRCDIR}/re2c/config.h" | sed -rne 's,^#define PACKAGE_VERSION "(.*)"$,\1,p')"

RE2C_BAZEL_VERSION="re2c ${RE2C_VERSION}"

if [[ "$("${TEST_SRCDIR}/re2c/re2c" --version)" == "${RE2C_BAZEL_VERSION}" ]]; then
echo "PASS"
else
echo "FAIL"
exit 1
fi

0 comments on commit 5080971

Please sign in to comment.