Skip to content

Commit 0887553

Browse files
committed
Separate jsonnet fmt into its own executable.
1 parent 1f76d49 commit 0887553

37 files changed

+903
-743
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*.dSYM
1212

1313
jsonnet
14+
jsonnetfmt
1415
_jsonnet.so
1516
libjsonnet.so
1617
libjsonnet++.so

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ include(GNUInstallDirs)
55

66
# User-configurable options.
77
option(BUILD_JSONNET "Build jsonnet command-line tool." ON)
8+
option(BUILD_JSONNETFMT "Build jsonnetfmt command-line tool." ON)
89
option(BUILD_TESTS "Build and run jsonnet tests." ON)
910
option(USE_SYSTEM_GTEST "Use system-provided gtest library" OFF)
1011
set(GLOBAL_OUTPUT_PATH_SUFFIX "" CACHE STRING

Makefile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ LIB_CPP_OBJ = $(LIB_OBJ) $(LIB_CPP_SRC:.cpp=.o)
6363

6464
ALL = \
6565
jsonnet \
66+
jsonnetfmt \
6667
libjsonnet.so \
6768
libjsonnet++.so \
6869
libjsonnet_test_snippet \
@@ -89,11 +90,11 @@ ALL_HEADERS = \
8990
third_party/md5/md5.h \
9091
third_party/json/json.hpp
9192

92-
default: jsonnet
93+
default: jsonnet jsonnetfmt
9394

9495
all: $(ALL)
9596

96-
test: jsonnet libjsonnet.so libjsonnet_test_snippet libjsonnet_test_file
97+
test: jsonnet jsonnetfmt libjsonnet.so libjsonnet_test_snippet libjsonnet_test_file
9798
./tests.sh
9899

99100
reformat:
@@ -104,6 +105,7 @@ test-formatting:
104105

105106
MAKEDEPEND_SRCS = \
106107
cmd/jsonnet.cpp \
108+
cmd/jsonnetfmt.cpp \
107109
core/libjsonnet_test_snippet.c \
108110
core/libjsonnet_test_file.c
109111

@@ -118,8 +120,12 @@ core/desugarer.cpp: core/std.jsonnet.h
118120
$(CXX) -c $(CXXFLAGS) $< -o $@
119121

120122
# Commandline executable.
121-
jsonnet: cmd/jsonnet.cpp $(LIB_OBJ)
122-
$(CXX) $(CXXFLAGS) $(LDFLAGS) $< $(LIB_SRC:.cpp=.o) -o $@
123+
jsonnet: cmd/jsonnet.cpp cmd/utils.cpp $(LIB_OBJ)
124+
$(CXX) $(CXXFLAGS) $(LDFLAGS) $< cmd/utils.cpp $(LIB_SRC:.cpp=.o) -o $@
125+
126+
# Commandline executable (reformatter).
127+
jsonnetfmt: cmd/jsonnetfmt.cpp cmd/utils.cpp $(LIB_OBJ)
128+
$(CXX) $(CXXFLAGS) $(LDFLAGS) $< cmd/utils.cpp $(LIB_SRC:.cpp=.o) -o $@
123129

124130
# C binding.
125131
libjsonnet.so: $(LIB_OBJ)

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,38 @@ To run the output binary, run:
3333
./jsonnet
3434
```
3535

36+
To run the reformatter, run:
37+
38+
```
39+
./jsonnetfmt
40+
```
41+
3642
### Bazel
3743

3844
Bazel builds are also supported.
3945
Install [Bazel](https://www.bazel.io/versions/master/docs/install.html) if it is
4046
not installed already. Then, run the following command to build with GCC:
4147

4248
```
43-
bazel build -c opt //cmd:jsonnet
49+
bazel build -c opt //cmd:all
4450
```
4551

4652
To build with Clang, use one of these two options:
4753

4854
```
49-
env CC=clang CXX=clang++ bazel build -c opt //cmd:jsonnet
55+
env CC=clang CXX=clang++ bazel build -c opt //cmd:all
5056
5157
# OR
5258
53-
bazel build -c opt --action_env=CC=clang --action_env=CXX=clang++ //cmd:jsonnet
59+
bazel build -c opt --action_env=CC=clang --action_env=CXX=clang++ //cmd:all
5460
```
5561

56-
This builds the `jsonnet` target defined in [`cmd/BUILD`](./cmd/BUILD). To
57-
launch the output binary, run:
62+
This builds the `jsonnet` and `jsonnetfmt` targets defined in [`cmd/BUILD`](./cmd/BUILD). To launch
63+
the output binaries, run:
5864

5965
```
6066
bazel-bin/cmd/jsonnet
67+
bazel-bin/cmd/jsonnetfmt
6168
```
6269

6370

cmd/BUILD

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
package(default_visibility = ["//visibility:public"])
22

3+
cc_library(
4+
name = "utils",
5+
srcs = ["utils.cpp"],
6+
hdrs = ["utils.h"],
7+
includes = ["."],
8+
)
9+
310
cc_binary(
411
name = "jsonnet",
512
srcs = ["jsonnet.cpp"],
6-
deps = ["//core:libjsonnet"],
13+
deps = [
14+
":utils",
15+
"//core:libjsonnet",
16+
],
17+
)
18+
19+
cc_binary(
20+
name = "jsonnetfmt",
21+
srcs = ["jsonnetfmt.cpp"],
22+
deps = [
23+
":utils",
24+
"//core:libjsonnet",
25+
],
726
)

cmd/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
# Jsonnet command-line tool.
22

33
if (BUILD_JSONNET OR BUILD_TESTS)
4-
add_executable(jsonnet ${LIBJSONNET_SOURCE} jsonnet.cpp)
4+
add_executable(jsonnet ${LIBJSONNET_SOURCE} jsonnet.cpp utils.cpp)
55
add_dependencies(jsonnet libjsonnet_static)
66
target_link_libraries(jsonnet libjsonnet_static)
77

88
install(TARGETS jsonnet DESTINATION "${CMAKE_INSTALL_BINDIR}")
99
endif()
10+
11+
if (BUILD_JSONNETFMT OR BUILD_TESTS)
12+
add_executable(jsonnetfmt ${LIBJSONNET_SOURCE} jsonnetfmt.cpp utils.cpp)
13+
add_dependencies(jsonnet libjsonnet_static)
14+
target_link_libraries(jsonnet libjsonnet_static)
15+
16+
install(TARGETS jsonnetfmt DESTINATION "${CMAKE_INSTALL_BINDIR}")
17+
endif()

0 commit comments

Comments
 (0)