Skip to content

Commit

Permalink
Use the Go Jsonnet port instead of the C++ port (#113)
Browse files Browse the repository at this point in the history
* Use the Go Jsonnet port instead of the C++ port

* Allow use of the C++ port via command-line flag

By default, Bazel will use the Go port of Jsonnet. To use the C++ port
of Jsonnet instead, invoke Bazel with the "--define jsonnet_port=cpp"
command-line flag. To select the Go port explicitly, invoke Bazel with
the "--define jsonnet_port=go" command-line flag.

* Change default Jsonnet port back from Go to C++

Retain use of C++ as the default port for one more release, with the
intention to change the default to the Go port and eventually remove
support for the C++ port.

* Use the latest version of the Jsonnet Go port

The selected commit is the latest along the "master" branch as of 24
August 2019.
  • Loading branch information
Steven E. Harris authored and Globegitter committed Sep 4, 2019
1 parent a7983a4 commit b9c0208
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 5 deletions.
Empty file added BUILD
Empty file.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,37 @@ external repositories for Jsonnet:
```python
http_archive(
name = "io_bazel_rules_jsonnet",
# TODO: Update this to reflect a later release.
sha256 = "59bf1edb53bc6b5adb804fbfabd796a019200d4ef4dd5cc7bdee03acc7686806",
strip_prefix = "rules_jsonnet-0.1.0",
urls = ["https://github.com/bazelbuild/rules_jsonnet/archive/0.1.0.tar.gz"],
)
load("@io_bazel_rules_jsonnet//jsonnet:jsonnet.bzl", "jsonnet_repositories")

jsonnet_repositories()

load("@jsonnet_go//bazel:repositories.bzl", "jsonnet_go_repositories")

jsonnet_go_repositories()

load("@jsonnet_go//bazel:deps.bzl", "jsonnet_go_dependencies")

jsonnet_go_dependencies()
```

## Jsonnet Port Selection

By default, Bazel will use [the C++ port](https://github.com/google/jsonnet) of Jsonnet. To use [the Go port](https://github.com/google/go-jsonnet) of Jsonnet instead, invoke Bazel with the `--define jsonnet_port=go` command-line flag. To select the C++ port explicitly, invoke Bazel with the `--define jsonnet_port=cpp` command-line flag.

_bazel_ Flag | Jsonnet Port
------------ | ------------
(none) | C++
`--define jsonnet_port=cpp`| C++
`--define jsonnet_port=go` | Go

Note that the primary development focus of the Jsonnet project is now with the Go port. This repository's support for using the C++ port is deprecated, and may be removed in a future release. Before then, its default port will likely change from C++ to Go in the next release.


<a name="#jsonnet_library"></a>
## jsonnet_library

Expand Down
8 changes: 8 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ load("//jsonnet:jsonnet.bzl", "jsonnet_repositories")

jsonnet_repositories()

load("@jsonnet_go//bazel:repositories.bzl", "jsonnet_go_repositories")

jsonnet_go_repositories()

load("@jsonnet_go//bazel:deps.bzl", "jsonnet_go_dependencies")

jsonnet_go_dependencies()

# Used for documenting Jsonnet rules.
# TODO: Move this to docs/WORKSPACE when recursive repositories are enabled.
git_repository(
Expand Down
2 changes: 1 addition & 1 deletion examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_jsonnet//jsonnet:jsonnet.bzl",
"jsonnet_library",
"jsonnet_to_json",
"jsonnet_to_json_test",
)

Expand Down Expand Up @@ -51,6 +50,7 @@ jsonnet_to_json_test(
src = "invalid.jsonnet",
error = 1,
golden = "invalid.out",
regex = 1,
)

jsonnet_to_json_test(
Expand Down
5 changes: 3 additions & 2 deletions examples/invalid.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
RUNTIME ERROR: Foo.
../examples/invalid.jsonnet:15:1-13
^RUNTIME ERROR: Foo\.
../examples/invalid\.jsonnet:15:1-13 ($|\$
During evaluation )
22 changes: 22 additions & 0 deletions jsonnet/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,25 @@ py_binary(
main = "stamper.py",
visibility = ["//visibility:public"],
)

config_setting(
name = "port_cpp",
define_values = {
"jsonnet_port": "cpp",
},
)

config_setting(
name = "port_go",
define_values = {
"jsonnet_port": "go",
},
)

alias(
name = "jsonnet_tool",
actual = select({
"//jsonnet:port_go": "@jsonnet_go//cmd/jsonnet",
"//conditions:default": "@jsonnet//cmd:jsonnet",
}),
)
12 changes: 10 additions & 2 deletions jsonnet/jsonnet.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

"""Jsonnet Rules
Expand Down Expand Up @@ -288,7 +289,7 @@ _REGEX_DIFF_COMMAND = """
GOLDEN_REGEX=$(%s %s)
if [[ ! "$OUTPUT" =~ $GOLDEN_REGEX ]]; then
echo "FAIL (regex mismatch): %s"
if [ %s = true]; then
if [ %s = true ]; then
echo "Output: $OUTPUT"
fi
exit 1
Expand Down Expand Up @@ -412,7 +413,7 @@ _jsonnet_common_attrs = {
),
"imports": attr.string_list(),
"jsonnet": attr.label(
default = Label("@jsonnet//cmd:jsonnet"),
default = Label("//jsonnet:jsonnet_tool"),
cfg = "host",
executable = True,
allow_single_file = True,
Expand Down Expand Up @@ -806,3 +807,10 @@ def jsonnet_repositories():
"https://github.com/google/jsonnet/archive/v0.13.0.tar.gz",
],
)
git_repository(
name = "jsonnet_go",
remote = "https://github.com/google/go-jsonnet",
commit = "13437c69e1834da8ca99dc8471adc97d0eb776d5",
init_submodules = True,
shallow_since = "1566677218 +0200",
)

0 comments on commit b9c0208

Please sign in to comment.