Skip to content

Commit c310959

Browse files
committed
Restructure source tree.
* Move all C++ sources for core library into core/ * Move source for Jsonnet command line too into cmd/ * Move sources for Python bindings into python/
1 parent 6d8f377 commit c310959

26 files changed

+123
-86
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ libjsonnet.so
99
/libjsonnet.js
1010
libjsonnet_test_file
1111
libjsonnet_test_snippet
12-
core
1312
core.*
1413
vgcore
1514
vgcore.*

BUILD

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package(default_visibility = ["//visibility:public"])
22

33
filegroup(
44
name = "std",
5-
srcs = ["std.jsonnet"],
5+
srcs = ["stdlib/std.jsonnet"],
66
)
77

88
genrule(
99
name = "gen-std-jsonnet-h",
10-
srcs = ["std.jsonnet"],
11-
outs = ["std.jsonnet.h"],
10+
srcs = ["stdlib/std.jsonnet"],
11+
outs = ["stdlib/std.jsonnet.h"],
1212
cmd = "((od -v -Anone -t u1 $< | tr \" \" \"\n\" | grep -v \"^$$\" " +
1313
"| tr \"\n\" \",\" ) && echo \"0\") > $@; " +
1414
"echo >> $@",
@@ -19,47 +19,47 @@ genrule(
1919
cc_library(
2020
name = "jsonnet-common",
2121
srcs = [
22-
"lexer.cpp",
23-
"parser.cpp",
24-
"static_analysis.cpp",
25-
"vm.cpp",
26-
"std.jsonnet.h",
22+
"core/lexer.cpp",
23+
"core/parser.cpp",
24+
"core/static_analysis.cpp",
25+
"core/vm.cpp",
26+
"stdlib/std.jsonnet.h",
2727
],
2828
hdrs = [
29-
"lexer.h",
30-
"parser.h",
31-
"static_analysis.h",
32-
"static_error.h",
33-
"vm.h",
29+
"core/lexer.h",
30+
"core/parser.h",
31+
"core/static_analysis.h",
32+
"core/static_error.h",
33+
"core/vm.h",
3434
],
3535
includes = ["."],
3636
)
3737

3838
cc_library(
3939
name = "libjsonnet",
40-
srcs = ["libjsonnet.cpp"],
41-
hdrs = ["libjsonnet.h"],
40+
srcs = ["core/libjsonnet.cpp"],
41+
hdrs = ["core/libjsonnet.h"],
4242
deps = [":jsonnet-common"],
4343
includes = ["."],
4444
)
4545

4646
cc_binary(
4747
name = "jsonnet",
48-
srcs = ["jsonnet.cpp"],
48+
srcs = ["cmd/jsonnet.cpp"],
4949
deps = [":libjsonnet"],
5050
includes = ["."],
5151
)
5252

5353
cc_binary(
5454
name = "libjsonnet_test_snippet",
55-
srcs = ["libjsonnet_test_snippet.c"],
55+
srcs = ["core/libjsonnet_test_snippet.c"],
5656
deps = [":libjsonnet"],
5757
includes = ["."],
5858
)
5959

6060
cc_binary(
6161
name = "libjsonnet_test_file",
62-
srcs = ["libjsonnet_test_file.c"],
62+
srcs = ["core/libjsonnet_test_file.c"],
6363
deps = [":libjsonnet"],
6464
includes = ["."],
6565
)
@@ -71,7 +71,7 @@ filegroup(
7171

7272
sh_test(
7373
name = "libjsonnet_test",
74-
srcs = ["libjsonnet_test.sh"],
74+
srcs = ["core/libjsonnet_test.sh"],
7575
data = [
7676
":jsonnet",
7777
":libjsonnet_test_snippet",

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
include LICENSE libjsonnet.h libjsonnet.cpp _jsonnet.c lexer.h lexer.cpp ast.h parser.h parser.cpp static_error.h static_analysis.h static_analysis.cpp state.h vm.h vm.cpp std.jsonnet Makefile
1+
include LICENSE core/*.cpp core/*.h python/*.c stdlib/std.jsonnet Makefile
22
#recursive-include test_suite examples gc_stress benchmarks editors

Makefile

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

15-
###################################################################################################
15+
################################################################################
1616
# User-servicable parts:
17-
###################################################################################################
17+
################################################################################
1818

1919
# C/C++ compiler -- clang also works
2020
CXX ?= g++
@@ -29,23 +29,44 @@ OD ?= od
2929

3030
OPT ?= -O3
3131

32-
CXXFLAGS ?= -g $(OPT) -Wall -Wextra -pedantic -std=c++0x -fPIC
33-
CFLAGS ?= -g $(OPT) -Wall -Wextra -pedantic -std=c99 -fPIC
32+
CXXFLAGS ?= -g $(OPT) -Wall -Wextra -pedantic -std=c++0x -fPIC -I.
33+
CFLAGS ?= -g $(OPT) -Wall -Wextra -pedantic -std=c99 -fPIC -I.
3434
EMCXXFLAGS = $(CXXFLAGS) --memory-init-file 0 -s DISABLE_EXCEPTION_CATCHING=0
3535
EMCFLAGS = $(CFLAGS) --memory-init-file 0 -s DISABLE_EXCEPTION_CATCHING=0
3636
LDFLAGS ?=
3737

3838
SHARED_LDFLAGS ?= -shared
3939

40-
###################################################################################################
40+
################################################################################
4141
# End of user-servicable parts
42-
###################################################################################################
43-
44-
LIB_SRC = lexer.cpp parser.cpp static_analysis.cpp vm.cpp libjsonnet.cpp
42+
################################################################################
43+
44+
LIB_SRC = \
45+
core/lexer.cpp \
46+
core/parser.cpp \
47+
core/static_analysis.cpp \
48+
core/vm.cpp \
49+
core/libjsonnet.cpp
4550
LIB_OBJ = $(LIB_SRC:.cpp=.o)
4651

47-
ALL = jsonnet libjsonnet.so libjsonnet_test_snippet libjsonnet_test_file libjsonnet.js doc/libjsonnet.js $(LIB_OBJ)
48-
ALL_HEADERS = libjsonnet.h vm.h static_analysis.h parser.h lexer.h ast.h static_error.h state.h std.jsonnet.h
52+
ALL = \
53+
jsonnet \
54+
libjsonnet.so \
55+
libjsonnet_test_snippet \
56+
libjsonnet_test_file \
57+
libjsonnet.js \
58+
doc/libjsonnet.js \
59+
$(LIB_OBJ)
60+
ALL_HEADERS = \
61+
core/libjsonnet.h \
62+
core/vm.h \
63+
core/static_analysis.h \
64+
core/parser.h \
65+
core/lexer.h \
66+
core/ast.h \
67+
core/static_error.h \
68+
core/state.h \
69+
stdlib/std.jsonnet.h
4970

5071
default: jsonnet
5172

@@ -60,47 +81,64 @@ test: jsonnet libjsonnet.so libjsonnet_test_snippet libjsonnet_test_file
6081
cd examples/terraform ; ./check.sh
6182
cd test_suite ; ./run_tests.sh
6283

84+
MAKEDEPEND_SRCS = \
85+
cmd/jsonnet.cpp \
86+
core/libjsonnet_test_snippet.c \
87+
core/libjsonnet_test_file.c
88+
6389
depend:
64-
makedepend -f- $(LIB_SRC) jsonnet.cpp libjsonnet_test_snippet.c libjsonnet_test_file.c > Makefile.depend
90+
makedepend -f- $(LIB_SRC) $(MAKEDEPEND_SRCS) > Makefile.depend
6591

66-
parser.cpp: std.jsonnet.h
92+
core/parser.cpp: stdlib/std.jsonnet.h
6793

6894
# Object files
6995
%.o: %.cpp
7096
$(CXX) -c $(CXXFLAGS) $< -o $@
7197

7298
# Commandline executable.
73-
jsonnet: jsonnet.cpp $(LIB_OBJ)
99+
jsonnet: cmd/jsonnet.cpp $(LIB_OBJ)
74100
$(CXX) $(CXXFLAGS) $(LDFLAGS) $< $(LIB_SRC:.cpp=.o) -o $@
75101

76102
# C binding.
77103
libjsonnet.so: $(LIB_OBJ)
78104
$(CXX) $(LDFLAGS) $(LIB_OBJ) $(SHARED_LDFLAGS) -o $@
79105

80106
# Javascript build of C binding
107+
JS_EXPORTED_FUNCTIONS = 'EXPORTED_FUNCTIONS=["_jsonnet_make", "_jsonnet_evaluate_snippet", "_jsonnet_realloc", "_jsonnet_destroy"]'
108+
81109
libjsonnet.js: $(LIB_SRC) $(ALL_HEADERS)
82-
$(EMCXX) -s 'EXPORTED_FUNCTIONS=["_jsonnet_make", "_jsonnet_evaluate_snippet", "_jsonnet_realloc", "_jsonnet_destroy"]' $(EMCXXFLAGS) $(LDFLAGS) $(LIB_SRC) -o $@
110+
$(EMCXX) -s $(JS_EXPORTED_FUNCTIONS) $(EMCXXFLAGS) $(LDFLAGS) $(LIB_SRC) -o $@
83111

84112
# Copy javascript build to doc directory
85113
doc/libjsonnet.js: libjsonnet.js
86114
$(CP) $^ $@
87115

88116
# Tests for C binding.
89-
libjsonnet_test_snippet: libjsonnet_test_snippet.c libjsonnet.so libjsonnet.h
117+
LIBJSONNET_TEST_SNIPPET_SRCS = \
118+
core/libjsonnet_test_snippet.c \
119+
libjsonnet.so \
120+
core/libjsonnet.h
121+
122+
libjsonnet_test_snippet: $(LIBJSONNET_TEST_SNIPPET_SRCS)
90123
$(CC) $(CFLAGS) $(LDFLAGS) $< -L. -ljsonnet -o $@
91124

92-
libjsonnet_test_file: libjsonnet_test_file.c libjsonnet.so libjsonnet.h
125+
LIBJSONNET_TEST_FILE_SRCS = \
126+
core/libjsonnet_test_file.c \
127+
libjsonnet.so \
128+
core/libjsonnet.h
129+
130+
libjsonnet_test_file: $(LIBJSONNET_TEST_FILE_SRCS)
93131
$(CC) $(CFLAGS) $(LDFLAGS) $< -L. -ljsonnet -o $@
94132

95133
# Encode standard library for embedding in C
96-
%.jsonnet.h: %.jsonnet
97-
(($(OD) -v -Anone -t u1 $< | tr " " "\n" | grep -v "^$$" | tr "\n" "," ) && echo "0") > $@
134+
stdlib/%.jsonnet.h: stdlib/%.jsonnet
135+
(($(OD) -v -Anone -t u1 $< \
136+
| tr " " "\n" \
137+
| grep -v "^$$" \
138+
| tr "\n" "," ) && echo "0") > $@
98139
echo >> $@
99140

100141
clean:
101-
rm -vf */*~ *~ .*~ */.*.swp .*.swp $(ALL) *.o *.jsonnet.h
142+
rm -vf */*~ *~ .*~ */.*.swp .*.swp $(ALL) *.o stdlib/*.jsonnet.h
102143

103144
-include Makefile.depend
104-
105-
106-

jsonnet.cpp renamed to cmd/jsonnet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ limitations under the License.
2626
#include <vector>
2727

2828
extern "C" {
29-
#include "libjsonnet.h"
29+
#include "core/libjsonnet.h"
3030
}
3131

3232
struct ImportCallbackContext {

ast.h renamed to core/ast.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ limitations under the License.
2424
#include <map>
2525
#include <vector>
2626

27-
#include "lexer.h"
27+
#include "core/lexer.h"
2828

2929
enum ASTType {
3030
AST_APPLY,
@@ -409,4 +409,4 @@ class Allocator {
409409
}
410410
};
411411

412-
#endif
412+
#endif // JSONNET_AST_H

lexer.cpp renamed to core/lexer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ limitations under the License.
1919
#include <string>
2020
#include <sstream>
2121

22-
#include "static_error.h"
23-
#include "lexer.h"
22+
#include "core/static_error.h"
23+
#include "core/lexer.h"
2424

2525
static bool is_upper(char c)
2626
{

lexer.h renamed to core/lexer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ limitations under the License.
2323
#include <list>
2424
#include <sstream>
2525

26-
#include "static_error.h"
26+
#include "core/static_error.h"
2727

2828
struct Token {
2929
enum Kind {
@@ -153,4 +153,4 @@ static inline std::ostream &operator<<(std::ostream &o, const Token &v)
153153

154154
std::list<Token> jsonnet_lex(const std::string &filename, const char *input);
155155

156-
#endif
156+
#endif // JSONNET_LEXER_H

libjsonnet.cpp renamed to core/libjsonnet.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ limitations under the License.
2424
#include <string>
2525

2626
extern "C" {
27-
#include "libjsonnet.h"
27+
#include "core/libjsonnet.h"
2828
}
2929

30-
#include "parser.h"
31-
#include "static_analysis.h"
32-
#include "vm.h"
30+
#include "core/parser.h"
31+
#include "core/static_analysis.h"
32+
#include "core/vm.h"
3333

3434
static void memory_panic(void)
3535
{

libjsonnet.h renamed to core/libjsonnet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,4 @@ char *jsonnet_evaluate_snippet_multi(struct JsonnetVm *vm,
154154
/** Complement of \see jsonnet_vm_make. */
155155
void jsonnet_destroy(struct JsonnetVm *vm);
156156

157-
#endif
157+
#endif // LIB_JSONNET_H
File renamed without changes.

libjsonnet_test_file.c renamed to core/libjsonnet_test_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
#include <stdlib.h>
1818
#include <stdio.h>
1919

20-
#include "libjsonnet.h"
20+
#include "core/libjsonnet.h"
2121

2222
int main(int argc, const char **argv)
2323
{

libjsonnet_test_snippet.c renamed to core/libjsonnet_test_snippet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
#include <stdlib.h>
1818
#include <stdio.h>
1919

20-
#include "libjsonnet.h"
20+
#include "core/libjsonnet.h"
2121

2222
int main(int argc, const char **argv)
2323
{

parser.cpp renamed to core/parser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ limitations under the License.
2525
#include <iomanip>
2626

2727

28-
#include "static_error.h"
29-
#include "ast.h"
30-
#include "parser.h"
31-
#include "lexer.h"
28+
#include "core/static_error.h"
29+
#include "core/ast.h"
30+
#include "core/parser.h"
31+
#include "core/lexer.h"
3232

3333

3434
// For generated ASTs, use a bogus location.
@@ -1078,7 +1078,7 @@ static AST *do_parse(Allocator *alloc, const std::string &file, const char *inpu
10781078
}
10791079

10801080
static constexpr char STD_CODE[] = {
1081-
#include "std.jsonnet.h"
1081+
#include "stdlib/std.jsonnet.h"
10821082
};
10831083

10841084
AST *jsonnet_parse(Allocator *alloc, const std::string &file, const char *input)

parser.h renamed to core/parser.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ limitations under the License.
1919

2020
#include <string>
2121

22-
#include "lexer.h"
23-
#include "ast.h"
22+
#include "core/lexer.h"
23+
#include "core/ast.h"
2424

2525
/** Parse a given JSON++ string.
2626
*
@@ -53,4 +53,4 @@ BuiltinDecl jsonnet_builtin_decl(unsigned long builtin);
5353
*/
5454
std::string jsonnet_unparse_jsonnet(const AST *ast);
5555

56-
#endif
56+
#endif // JSONNET_PARSER_H

state.h renamed to core/state.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,4 +445,4 @@ namespace {
445445

446446
}
447447

448-
#endif
448+
#endif // JSONNET_STATE_H

static_analysis.cpp renamed to core/static_analysis.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ limitations under the License.
1616

1717
#include <set>
1818

19-
#include "static_analysis.h"
20-
21-
#include "static_error.h"
22-
#include "ast.h"
19+
#include "core/static_analysis.h"
20+
#include "core/static_error.h"
21+
#include "core/ast.h"
2322

2423
typedef std::set<const Identifier *> IdSet;
2524

0 commit comments

Comments
 (0)