Skip to content

Commit b9c0208

Browse files
Steven E. Harrismarkusdap
authored andcommitted
Use the Go Jsonnet port instead of the C++ port (#113)
* 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.
1 parent a7983a4 commit b9c0208

File tree

7 files changed

+66
-5
lines changed

7 files changed

+66
-5
lines changed

BUILD

Whitespace-only changes.

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,37 @@ external repositories for Jsonnet:
2525
```python
2626
http_archive(
2727
name = "io_bazel_rules_jsonnet",
28+
# TODO: Update this to reflect a later release.
2829
sha256 = "59bf1edb53bc6b5adb804fbfabd796a019200d4ef4dd5cc7bdee03acc7686806",
2930
strip_prefix = "rules_jsonnet-0.1.0",
3031
urls = ["https://github.com/bazelbuild/rules_jsonnet/archive/0.1.0.tar.gz"],
3132
)
3233
load("@io_bazel_rules_jsonnet//jsonnet:jsonnet.bzl", "jsonnet_repositories")
3334

3435
jsonnet_repositories()
36+
37+
load("@jsonnet_go//bazel:repositories.bzl", "jsonnet_go_repositories")
38+
39+
jsonnet_go_repositories()
40+
41+
load("@jsonnet_go//bazel:deps.bzl", "jsonnet_go_dependencies")
42+
43+
jsonnet_go_dependencies()
3544
```
3645

46+
## Jsonnet Port Selection
47+
48+
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.
49+
50+
_bazel_ Flag | Jsonnet Port
51+
------------ | ------------
52+
(none) | C++
53+
`--define jsonnet_port=cpp`| C++
54+
`--define jsonnet_port=go` | Go
55+
56+
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.
57+
58+
3759
<a name="#jsonnet_library"></a>
3860
## jsonnet_library
3961

WORKSPACE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ load("//jsonnet:jsonnet.bzl", "jsonnet_repositories")
1717

1818
jsonnet_repositories()
1919

20+
load("@jsonnet_go//bazel:repositories.bzl", "jsonnet_go_repositories")
21+
22+
jsonnet_go_repositories()
23+
24+
load("@jsonnet_go//bazel:deps.bzl", "jsonnet_go_dependencies")
25+
26+
jsonnet_go_dependencies()
27+
2028
# Used for documenting Jsonnet rules.
2129
# TODO: Move this to docs/WORKSPACE when recursive repositories are enabled.
2230
git_repository(

examples/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package(default_visibility = ["//visibility:public"])
77
load(
88
"@io_bazel_rules_jsonnet//jsonnet:jsonnet.bzl",
99
"jsonnet_library",
10-
"jsonnet_to_json",
1110
"jsonnet_to_json_test",
1211
)
1312

@@ -51,6 +50,7 @@ jsonnet_to_json_test(
5150
src = "invalid.jsonnet",
5251
error = 1,
5352
golden = "invalid.out",
53+
regex = 1,
5454
)
5555

5656
jsonnet_to_json_test(

examples/invalid.out

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
RUNTIME ERROR: Foo.
2-
../examples/invalid.jsonnet:15:1-13
1+
^RUNTIME ERROR: Foo\.
2+
../examples/invalid\.jsonnet:15:1-13 ($|\$
3+
During evaluation )

jsonnet/BUILD

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,25 @@ py_binary(
88
main = "stamper.py",
99
visibility = ["//visibility:public"],
1010
)
11+
12+
config_setting(
13+
name = "port_cpp",
14+
define_values = {
15+
"jsonnet_port": "cpp",
16+
},
17+
)
18+
19+
config_setting(
20+
name = "port_go",
21+
define_values = {
22+
"jsonnet_port": "go",
23+
},
24+
)
25+
26+
alias(
27+
name = "jsonnet_tool",
28+
actual = select({
29+
"//jsonnet:port_go": "@jsonnet_go//cmd/jsonnet",
30+
"//conditions:default": "@jsonnet//cmd:jsonnet",
31+
}),
32+
)

jsonnet/jsonnet.bzl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

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

1718
"""Jsonnet Rules
@@ -288,7 +289,7 @@ _REGEX_DIFF_COMMAND = """
288289
GOLDEN_REGEX=$(%s %s)
289290
if [[ ! "$OUTPUT" =~ $GOLDEN_REGEX ]]; then
290291
echo "FAIL (regex mismatch): %s"
291-
if [ %s = true]; then
292+
if [ %s = true ]; then
292293
echo "Output: $OUTPUT"
293294
fi
294295
exit 1
@@ -412,7 +413,7 @@ _jsonnet_common_attrs = {
412413
),
413414
"imports": attr.string_list(),
414415
"jsonnet": attr.label(
415-
default = Label("@jsonnet//cmd:jsonnet"),
416+
default = Label("//jsonnet:jsonnet_tool"),
416417
cfg = "host",
417418
executable = True,
418419
allow_single_file = True,
@@ -806,3 +807,10 @@ def jsonnet_repositories():
806807
"https://github.com/google/jsonnet/archive/v0.13.0.tar.gz",
807808
],
808809
)
810+
git_repository(
811+
name = "jsonnet_go",
812+
remote = "https://github.com/google/go-jsonnet",
813+
commit = "13437c69e1834da8ca99dc8471adc97d0eb776d5",
814+
init_submodules = True,
815+
shallow_since = "1566677218 +0200",
816+
)

0 commit comments

Comments
 (0)