• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

ast/H09-Feb-2020-

astgen/H09-Feb-2020-

bazel/H09-Feb-2020-

builtin-benchmarks/H09-Feb-2020-

c-bindings/H09-Feb-2020-

c-bindings-tests/H09-Feb-2020-

cmd/H09-Feb-2020-

cpp-jsonnet/H09-Feb-2020-

internal/H09-Feb-2020-

linter/H09-Feb-2020-

python/H09-Feb-2020-

testdata/H09-Feb-2020-

toolutils/H09-Feb-2020-

.gitignoreH A D09-Feb-2020375

.gitmodulesH A D09-Feb-202091

.tool-versionsH A D09-Feb-202012

.travis.ymlH A D09-Feb-20201.4 KiB

BUILD.bazelH A D09-Feb-20201.1 KiB

CONTRIBUTINGH A D09-Feb-2020266

LICENSEH A D09-Feb-202011.1 KiB

MakefileH A D09-Feb-20201.8 KiB

README.mdH A D09-Feb-20205.1 KiB

WORKSPACEH A D09-Feb-2020410

benchmark.shH A D09-Feb-2020618

builtins.goH A D09-Feb-202043.7 KiB

builtins_benchmark_test.goH A D09-Feb-20201.1 KiB

doc.goH A D09-Feb-2020979

error_formatter.goH A D09-Feb-20204.2 KiB

go.modH A D09-Feb-2020332

go.sumH A D09-Feb-20201.7 KiB

imports.goH A D09-Feb-20207.8 KiB

interpreter.goH A D09-Feb-202032 KiB

interpreter_test.goH A D09-Feb-2020593

jsonnet_test.goH A D09-Feb-20203.6 KiB

main_test.goH A D09-Feb-202014.1 KiB

runtime_error.goH A D09-Feb-20201.7 KiB

setup.pyH A D09-Feb-20202.1 KiB

tests.shH A D09-Feb-2020463

thunks.goH A D09-Feb-20208.1 KiB

travisBazel.shH A D09-Feb-2020407

travisBuild.shH A D09-Feb-2020606

value.goH A D09-Feb-202020.9 KiB

vm.goH A D09-Feb-20208.5 KiB

README.md

1# go-jsonnet
2
3[![GoDoc Widget]][GoDoc] [![Travis Widget]][Travis] [![Coverage Status Widget]][Coverage Status]
4
5[GoDoc]: https://godoc.org/github.com/google/go-jsonnet
6[GoDoc Widget]: https://godoc.org/github.com/google/go-jsonnet?status.png
7[Travis]: https://travis-ci.org/google/go-jsonnet
8[Travis Widget]: https://travis-ci.org/google/go-jsonnet.svg?branch=master
9[Coverage Status Widget]: https://coveralls.io/repos/github/google/go-jsonnet/badge.svg?branch=master
10[Coverage Status]: https://coveralls.io/github/google/go-jsonnet?branch=master
11
12This an implementation of [Jsonnet](http://jsonnet.org/) in pure Go. It is feature complete but is not as heavily exercised as the [Jsonnet C++ implementation](https://github.com/google/jsonnet).  Please try it out and give feedback.
13
14This code is known to work on Go 1.8 and above. We recommend always using the newest stable release of Go.
15
16## Installation instructions
17
18```
19go get github.com/google/go-jsonnet/cmd/jsonnet
20```
21
22## Build instructions (go 1.11+)
23
24```bash
25git clone git@github.com:google/go-jsonnet.git
26cd go-jsonnet
27go build ./cmd/jsonnet
28```
29To build with [Bazel](https://bazel.build/) instead:
30```bash
31git clone git@github.com:google/go-jsonnet.git
32cd go-jsonnet
33git submodule init
34git submodule update
35bazel build //cmd/jsonnet
36```
37The resulting _jsonnet_ program will then be available at a platform-specific path, such as _bazel-bin/cmd/jsonnet/darwin_amd64_stripped/jsonnet_ for macOS.
38
39Bazel also accommodates cross-compiling the program. To build the _jsonnet_ program for various popular platforms, run the following commands:
40
41Target platform | Build command
42--------------- | -------------------------------------------------------------------------------------
43Current host    | _bazel build //cmd/jsonnet_
44Linux           | _bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //cmd/jsonnet_
45macOS           | _bazel build --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 //cmd/jsonnet_
46Windows         | _bazel build --platforms=@io_bazel_rules_go//go/toolchain:windows_amd64 //cmd/jsonnet_
47
48For additional target platform names, see the per-Go release definitions [here](https://github.com/bazelbuild/rules_go/blob/master/go/private/sdk_list.bzl#L21-L31) in the _rules_go_ Bazel package.
49
50Additionally if any files were moved around, see the section [Keeping the Bazel files up to date](#keeping-the-bazel-files-up-to-date).
51
52## Running tests
53
54```bash
55./tests.sh  # Also runs `go test ./...`
56```
57
58## Running Benchmarks
59
60Setup
61
62```bash
63go get golang.org/x/tools/cmd/benchcmp
64```
65
661. Make sure you build a jsonnet binary _prior_ to making changes.
67
68```bash
69go build ./cmd/jsonnet -o jsonnet-old
70```
71
722. Make changes (iterate as needed), and rebuild new binary
73
74```bash
75go build ./cmd/jsonnet
76```
77
783. Run benchmark:
79
80```bash
81# e.g. ./benchmark.sh Builtin
82./benchmark.sh <TestNameFilter>
83```
84
85## Implementation Notes
86
87We are generating some helper classes on types by using http://clipperhouse.github.io/gen/.  Do the following to regenerate these if necessary:
88
89```bash
90go get github.com/clipperhouse/gen
91go get github.com/clipperhouse/set
92export PATH=$PATH:$GOPATH/bin  # If you haven't already
93go generate
94```
95
96## Updating and modifying the standard library
97
98Standard library source code is kept in `cpp-jsonnet` submodule, because it is shared with [Jsonnet C++
99implementation](https://github.com/google/jsonnet).
100
101For performance reasons we perform preprocessing on the standard library, so for the changes to be visible, regeneration is necessary:
102
103```bash
104git submodule init
105git submodule update
106go run cmd/dumpstdlibast/dumpstdlibast.go cpp-jsonnet/stdlib/std.jsonnet > astgen/stdast.go
107```
108
109The above command creates the _astgen/stdast.go_ file which puts the desugared standard library into the right data structures, which lets us avoid the parsing overhead during execution. Note that this step is not necessary to perform manually when building with Bazel; the Bazel target regenerates the _astgen/stdast.go_ (writing it into Bazel's build sandbox directory tree) file when necessary.
110
111## Keeping the Bazel files up to date
112Note that we maintain the Go-related Bazel targets with [the Gazelle tool](https://github.com/bazelbuild/bazel-gazelle). The Go module (_go.mod_ in the root directory) remains the primary source of truth. Gazelle analyzes both that file and the rest of the Go files in the repository to create and adjust appropriate Bazel targets for building Go packages and executable programs.
113
114After changing any dependencies within the files covered by this Go module, it is helpful to run _go mod tidy_ to ensure that the module declarations match the state of the Go source code. In order to synchronize the Bazel rules with material changes to the Go module, run the following command to invoke [Gazelle's `update-repos` command](https://github.com/bazelbuild/bazel-gazelle#update-repos):
115```bash
116bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=bazel/deps.bzl%jsonnet_go_dependencies
117```
118
119Similarly, after adding or removing Go source files, it may be necessary to synchronize the Bazel rules by running the following command:
120```bash
121bazel run //:gazelle
122```
123