Skip to content

Commit

Permalink
Restructure source tree.
Browse files Browse the repository at this point in the history
* 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/
  • Loading branch information
davidzchen committed Sep 30, 2015
1 parent 6d8f377 commit c310959
Show file tree
Hide file tree
Showing 26 changed files with 123 additions and 86 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ libjsonnet.so
/libjsonnet.js
libjsonnet_test_file
libjsonnet_test_snippet
core
core.*
vgcore
vgcore.*
Expand Down
38 changes: 19 additions & 19 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package(default_visibility = ["//visibility:public"])

filegroup(
name = "std",
srcs = ["std.jsonnet"],
srcs = ["stdlib/std.jsonnet"],
)

genrule(
name = "gen-std-jsonnet-h",
srcs = ["std.jsonnet"],
outs = ["std.jsonnet.h"],
srcs = ["stdlib/std.jsonnet"],
outs = ["stdlib/std.jsonnet.h"],
cmd = "((od -v -Anone -t u1 $< | tr \" \" \"\n\" | grep -v \"^$$\" " +
"| tr \"\n\" \",\" ) && echo \"0\") > $@; " +
"echo >> $@",
Expand All @@ -19,47 +19,47 @@ genrule(
cc_library(
name = "jsonnet-common",
srcs = [
"lexer.cpp",
"parser.cpp",
"static_analysis.cpp",
"vm.cpp",
"std.jsonnet.h",
"core/lexer.cpp",
"core/parser.cpp",
"core/static_analysis.cpp",
"core/vm.cpp",
"stdlib/std.jsonnet.h",
],
hdrs = [
"lexer.h",
"parser.h",
"static_analysis.h",
"static_error.h",
"vm.h",
"core/lexer.h",
"core/parser.h",
"core/static_analysis.h",
"core/static_error.h",
"core/vm.h",
],
includes = ["."],
)

cc_library(
name = "libjsonnet",
srcs = ["libjsonnet.cpp"],
hdrs = ["libjsonnet.h"],
srcs = ["core/libjsonnet.cpp"],
hdrs = ["core/libjsonnet.h"],
deps = [":jsonnet-common"],
includes = ["."],
)

cc_binary(
name = "jsonnet",
srcs = ["jsonnet.cpp"],
srcs = ["cmd/jsonnet.cpp"],
deps = [":libjsonnet"],
includes = ["."],
)

cc_binary(
name = "libjsonnet_test_snippet",
srcs = ["libjsonnet_test_snippet.c"],
srcs = ["core/libjsonnet_test_snippet.c"],
deps = [":libjsonnet"],
includes = ["."],
)

cc_binary(
name = "libjsonnet_test_file",
srcs = ["libjsonnet_test_file.c"],
srcs = ["core/libjsonnet_test_file.c"],
deps = [":libjsonnet"],
includes = ["."],
)
Expand All @@ -71,7 +71,7 @@ filegroup(

sh_test(
name = "libjsonnet_test",
srcs = ["libjsonnet_test.sh"],
srcs = ["core/libjsonnet_test.sh"],
data = [
":jsonnet",
":libjsonnet_test_snippet",
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
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
include LICENSE core/*.cpp core/*.h python/*.c stdlib/std.jsonnet Makefile
#recursive-include test_suite examples gc_stress benchmarks editors
82 changes: 60 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

###################################################################################################
################################################################################
# User-servicable parts:
###################################################################################################
################################################################################

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

OPT ?= -O3

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

SHARED_LDFLAGS ?= -shared

###################################################################################################
################################################################################
# End of user-servicable parts
###################################################################################################

LIB_SRC = lexer.cpp parser.cpp static_analysis.cpp vm.cpp libjsonnet.cpp
################################################################################

LIB_SRC = \
core/lexer.cpp \
core/parser.cpp \
core/static_analysis.cpp \
core/vm.cpp \
core/libjsonnet.cpp
LIB_OBJ = $(LIB_SRC:.cpp=.o)

ALL = jsonnet libjsonnet.so libjsonnet_test_snippet libjsonnet_test_file libjsonnet.js doc/libjsonnet.js $(LIB_OBJ)
ALL_HEADERS = libjsonnet.h vm.h static_analysis.h parser.h lexer.h ast.h static_error.h state.h std.jsonnet.h
ALL = \
jsonnet \
libjsonnet.so \
libjsonnet_test_snippet \
libjsonnet_test_file \
libjsonnet.js \
doc/libjsonnet.js \
$(LIB_OBJ)
ALL_HEADERS = \
core/libjsonnet.h \
core/vm.h \
core/static_analysis.h \
core/parser.h \
core/lexer.h \
core/ast.h \
core/static_error.h \
core/state.h \
stdlib/std.jsonnet.h

default: jsonnet

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

MAKEDEPEND_SRCS = \
cmd/jsonnet.cpp \
core/libjsonnet_test_snippet.c \
core/libjsonnet_test_file.c

depend:
makedepend -f- $(LIB_SRC) jsonnet.cpp libjsonnet_test_snippet.c libjsonnet_test_file.c > Makefile.depend
makedepend -f- $(LIB_SRC) $(MAKEDEPEND_SRCS) > Makefile.depend

parser.cpp: std.jsonnet.h
core/parser.cpp: stdlib/std.jsonnet.h

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

# Commandline executable.
jsonnet: jsonnet.cpp $(LIB_OBJ)
jsonnet: cmd/jsonnet.cpp $(LIB_OBJ)
$(CXX) $(CXXFLAGS) $(LDFLAGS) $< $(LIB_SRC:.cpp=.o) -o $@

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

# Javascript build of C binding
JS_EXPORTED_FUNCTIONS = 'EXPORTED_FUNCTIONS=["_jsonnet_make", "_jsonnet_evaluate_snippet", "_jsonnet_realloc", "_jsonnet_destroy"]'

libjsonnet.js: $(LIB_SRC) $(ALL_HEADERS)
$(EMCXX) -s 'EXPORTED_FUNCTIONS=["_jsonnet_make", "_jsonnet_evaluate_snippet", "_jsonnet_realloc", "_jsonnet_destroy"]' $(EMCXXFLAGS) $(LDFLAGS) $(LIB_SRC) -o $@
$(EMCXX) -s $(JS_EXPORTED_FUNCTIONS) $(EMCXXFLAGS) $(LDFLAGS) $(LIB_SRC) -o $@

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

# Tests for C binding.
libjsonnet_test_snippet: libjsonnet_test_snippet.c libjsonnet.so libjsonnet.h
LIBJSONNET_TEST_SNIPPET_SRCS = \
core/libjsonnet_test_snippet.c \
libjsonnet.so \
core/libjsonnet.h

libjsonnet_test_snippet: $(LIBJSONNET_TEST_SNIPPET_SRCS)
$(CC) $(CFLAGS) $(LDFLAGS) $< -L. -ljsonnet -o $@

libjsonnet_test_file: libjsonnet_test_file.c libjsonnet.so libjsonnet.h
LIBJSONNET_TEST_FILE_SRCS = \
core/libjsonnet_test_file.c \
libjsonnet.so \
core/libjsonnet.h

libjsonnet_test_file: $(LIBJSONNET_TEST_FILE_SRCS)
$(CC) $(CFLAGS) $(LDFLAGS) $< -L. -ljsonnet -o $@

# Encode standard library for embedding in C
%.jsonnet.h: %.jsonnet
(($(OD) -v -Anone -t u1 $< | tr " " "\n" | grep -v "^$$" | tr "\n" "," ) && echo "0") > $@
stdlib/%.jsonnet.h: stdlib/%.jsonnet
(($(OD) -v -Anone -t u1 $< \
| tr " " "\n" \
| grep -v "^$$" \
| tr "\n" "," ) && echo "0") > $@
echo >> $@

clean:
rm -vf */*~ *~ .*~ */.*.swp .*.swp $(ALL) *.o *.jsonnet.h
rm -vf */*~ *~ .*~ */.*.swp .*.swp $(ALL) *.o stdlib/*.jsonnet.h

-include Makefile.depend



2 changes: 1 addition & 1 deletion jsonnet.cpp → cmd/jsonnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ limitations under the License.
#include <vector>

extern "C" {
#include "libjsonnet.h"
#include "core/libjsonnet.h"
}

struct ImportCallbackContext {
Expand Down
4 changes: 2 additions & 2 deletions ast.h → core/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ limitations under the License.
#include <map>
#include <vector>

#include "lexer.h"
#include "core/lexer.h"

enum ASTType {
AST_APPLY,
Expand Down Expand Up @@ -409,4 +409,4 @@ class Allocator {
}
};

#endif
#endif // JSONNET_AST_H
4 changes: 2 additions & 2 deletions lexer.cpp → core/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ limitations under the License.
#include <string>
#include <sstream>

#include "static_error.h"
#include "lexer.h"
#include "core/static_error.h"
#include "core/lexer.h"

static bool is_upper(char c)
{
Expand Down
4 changes: 2 additions & 2 deletions lexer.h → core/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ limitations under the License.
#include <list>
#include <sstream>

#include "static_error.h"
#include "core/static_error.h"

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

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

#endif
#endif // JSONNET_LEXER_H
8 changes: 4 additions & 4 deletions libjsonnet.cpp → core/libjsonnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ limitations under the License.
#include <string>

extern "C" {
#include "libjsonnet.h"
#include "core/libjsonnet.h"
}

#include "parser.h"
#include "static_analysis.h"
#include "vm.h"
#include "core/parser.h"
#include "core/static_analysis.h"
#include "core/vm.h"

static void memory_panic(void)
{
Expand Down
2 changes: 1 addition & 1 deletion libjsonnet.h → core/libjsonnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ char *jsonnet_evaluate_snippet_multi(struct JsonnetVm *vm,
/** Complement of \see jsonnet_vm_make. */
void jsonnet_destroy(struct JsonnetVm *vm);

#endif
#endif // LIB_JSONNET_H
File renamed without changes.
2 changes: 1 addition & 1 deletion libjsonnet_test_file.c → core/libjsonnet_test_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
#include <stdlib.h>
#include <stdio.h>

#include "libjsonnet.h"
#include "core/libjsonnet.h"

int main(int argc, const char **argv)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
#include <stdlib.h>
#include <stdio.h>

#include "libjsonnet.h"
#include "core/libjsonnet.h"

int main(int argc, const char **argv)
{
Expand Down
10 changes: 5 additions & 5 deletions parser.cpp → core/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ limitations under the License.
#include <iomanip>


#include "static_error.h"
#include "ast.h"
#include "parser.h"
#include "lexer.h"
#include "core/static_error.h"
#include "core/ast.h"
#include "core/parser.h"
#include "core/lexer.h"


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

static constexpr char STD_CODE[] = {
#include "std.jsonnet.h"
#include "stdlib/std.jsonnet.h"
};

AST *jsonnet_parse(Allocator *alloc, const std::string &file, const char *input)
Expand Down
6 changes: 3 additions & 3 deletions parser.h → core/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ limitations under the License.

#include <string>

#include "lexer.h"
#include "ast.h"
#include "core/lexer.h"
#include "core/ast.h"

/** Parse a given JSON++ string.
*
Expand Down Expand Up @@ -53,4 +53,4 @@ BuiltinDecl jsonnet_builtin_decl(unsigned long builtin);
*/
std::string jsonnet_unparse_jsonnet(const AST *ast);

#endif
#endif // JSONNET_PARSER_H
2 changes: 1 addition & 1 deletion state.h → core/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,4 @@ namespace {

}

#endif
#endif // JSONNET_STATE_H
7 changes: 3 additions & 4 deletions static_analysis.cpp → core/static_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ limitations under the License.

#include <set>

#include "static_analysis.h"

#include "static_error.h"
#include "ast.h"
#include "core/static_analysis.h"
#include "core/static_error.h"
#include "core/ast.h"

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

Expand Down
Loading

0 comments on commit c310959

Please sign in to comment.